//Fotos Rotativas - Inicios
var pos = -1;
var timeout = "";
var fadeimages = new Array();
var titulos = new Array();
var textos = new Array();
var links = new Array();
var chapeu = new Array();
var loaded = false;

function $(obj) {return document.getElementById(obj);}
			
function underline(n) {

	obj = $("linkchamada");
	obj.style.textDecoration = (n == 0) ? "none":"underline";
	
}



window.onload = function() {

	loaded = true;

	for(var i=0;i<5;i++) {
	
		fadeimages[i] = new Image();
		
		fadeimages[i].src ="http://www.piauihoje.com/fotos/"+$("imgs"+(i+1)).value;
		titulos[i] = $("titulo"+(i+1)).value;
		links[i] = $("link"+(i+1)).value;
		chapeu[i] = $("chapeu"+(i+1)).value;
			
	}
	

	playslide();
		
}

function playslide() {

	//alert(pos);
	pos = pos+1;
	
	pos = (pos>4) ? 0:pos;
	
	
	tohtml();	
	
	
	repeat();
	
}

function tohtml() {
	$("imgs").src = fadeimages[pos].src;
	$("linkchamada").innerHTML = titulos[pos];
	$("linkimg").href = links[pos];
	$("linkchapeu").innerHTML = chapeu[pos];
	$("linkbaixo").href = links[pos];
}

function repeat() {
	
	clearTimeout(timeout);
	
	timeout = setTimeout("playslide()",6000);
	
}

function nextImage() {
	if (loaded) {

		clearTimeout(timeout);
	
		pos = pos + 1;
			
		if (pos>4) {
		
			pos = 0;
		
		}
		
		tohtml();
		
				
		repeat();
	}

}

function previousImage() {
	if (loaded) {
		clearTimeout(timeout);	
		
		pos = pos - 1;
		
		if (pos<0) {
		
			pos = 4;
		
		}
		
		tohtml();
			
				
		repeat();
	}
}
//Fotos Rotativas - Fim
