﻿// Imagens
var myPix = new Array(3)
myPix[0] = "01";
myPix[1] = "02";
myPix[2] = "03";

// Tarjas
var myText = new Array(3)
myText[0] = "<a href=http://www.humormaior.com/imagens.php>Imagens de Humor</a>";
myText[1] = "<a href=http://www.humormaior.com/diversos/oculos3d.php>Aprenda a fazer oculos 3D.</a>";
myText[2] = "<a href=http://www.humormaior.com/videos.php>Videos inacreditaveis</a>";

// Variáveis
var format = ".jpg"; // formato das imagens
var timer = "3500"; 
var i = 1; 
var intervalo; 

function start() {
	intervalo = window.setInterval("change()",timer); 
	document.getElementById(0).className = "imgatual";
}

// Função quando clica na imagem pequena exibe ela grande.
function abrir() {
	var main = document.getElementById("exibicao");
	var iten = main.getElementsByTagName("img");
	if (iten) {
		for (var i=0;i<iten.length;i++) {
			if (iten[i].className  == "imgmenu") {
				iten[i].onclick = function() { // quando clicar na imagem executar os comandos
					limpa(); 
					this.className = "imgclick"; // coloca borda do click
					document.getElementById("image").src = 'http://i125.photobucket.com/albums/p56/humormaior/outros/' + myPix[this.id] + format; 
					document.getElementById("tarja").innerHTML = myText[this.id]; // coloca a tarja
				}
			}
		}
	}
}

function limpa() {
	var main = document.getElementById("exibicao");
	var iten = main.getElementsByTagName("img");
	if (iten) {
		for (var i=0;i<iten.length;i++) {
			if (iten[i].className  == "imgclick") { 
				iten[i].className = "imgmenu"; 
			}
		}
	}
}

function borda() {
	var img = arguments[0]; // recebe o por parametro a ID da imagem
	var main = document.getElementById("exibicao");
	var iten = main.getElementsByTagName("img");
	if (iten) {
		for (var i=0;i<iten.length;i++) { 
			if ((iten[i].className  == "imgatual") || (iten[i].className == "imgclick")) {
				iten[i].className = "imgmenu";
			}
		}
		document.getElementById(img).className = "imgatual"; // aqui coloca a borda na imagem atual
	}
}

// Função que exibe a imagem grande!
function change() {
	var tam = myPix.length;
	if (i < tam) {
		document.getElementById("image").src = 'http://i125.photobucket.com/albums/p56/humormaior/outros/' + myPix[i % tam] + format; // exibe a imagem grande
		borda(i); // modifica a borda nas imagens pequenas
		document.getElementById('tarja').innerHTML=myText[i]; // coloca a tarja na imagem
		if (i == tam) i = -1;
		i++;
	}else { i = 0; }
}

window.onload = function() {
			abrir();
			start();
		}

