function DadosSlideShow(nm, cred, img, lnk) {
	this.titulo  = nm;
	this.credito = cred;
	this.imagem  = img;
	this.destino = lnk;
}


function SlideShow(slideList, image, speed, name){
	this.list = slideList;
	this.image = image;
	this.speed = speed;
	this.name = name;
	this.current = -1;
	this.timer = 0;
}
SlideShow.prototype.play = SlideShow_play;
SlideShow.prototype.next = SlideShow_next; 
SlideShow.prototype.stop = SlideShow_stop;
SlideShow.prototype.goTo = SlideShow_goto;
SlideShow.prototype.carregaLink = SlideShow_link;

function switchImage(imgName, imgSrc){
	if (document.getElementById('slide')){
		if (imgSrc != "none"){
			var image = "url("+homeImagens+imgSrc+")";
			document.getElementById('slideoff').style.backgroundImage = image; //document.getElementById('slide').style.backgroundImage;
			fadeOut('slide', 0.05);
			fadeTimerOff = setTimeout("setSlideFromOff()", 1000); 
			//fadeIn('slide', 0.1);
		}
	}
} 


function SlideShow_link() {
	with(this) {
		window.location = list[current].destino;
	}	
}
function setSlideFromOff() {
	clearInterval(fadeTimer);
	document.getElementById('slide').style.backgroundImage = document.getElementById('slideoff').style.backgroundImage; 
	setAlpha(document.getElementById('slide'), 100); 
	clearTimeout(fadeTimerOff);
}

var fadeTimer, fadeTimerOff;
function fadeOut(id, time) {
	target = document.getElementById(id);
	alpha = 100;
	timer = (time*1000)/50;
	fadeTimer = setInterval(
			function() {
				if (alpha <= 0)
					clearInterval(fadeTimer);
				setAlpha(target, alpha);
				alpha -= 2;
			}, timer);
}

function fadeIn(id, time) {
	target = document.getElementById(id);
	alpha = 0;
	timer = (time*1000)/50;
	fadeTimer = setInterval(
			function() {
				if (alpha >= 100)
					clearInterval(fadeTimer);
				setAlpha(target, alpha);
				alpha += 2;
			}, timer);
}

function setAlpha(target, alpha) {
	target.style.filter = "alpha(opacity="+ alpha +")";
	target.style.opacity = alpha/100;
}

function posFolhaRosto (objSlide) {
	with (objSlide) {
		next();
		timer = setTimeout(name+'.play();', speed);
	}
}
function SlideShow_play(){
	var folha;
	with(this){
		next(); //mySlideShow1.next();
		clearTimeout(timer);
		timer = setTimeout(name+'.play()', speed);
		idx_onOff(current);
	}
}

function SlideShow_stop(){
	with(this){
		pause = false;
		setSlideFromOff();
		clearTimeout(timer);
		clearInterval(fadeTimer);
		clearTimeout(fadeTimerOff);
	}
} 

function SlideShow_next(){
	if (!finishLoading) {
		alert("Aguarde o carregamento das imagens!");
		return;
	}
	with(this){
		clearTimeout(timer);
		clearInterval(fadeTimer); 
		clearTimeout(fadeTimerOff);
		
		if(current++ == list.length-1)
			current = 0;

		goTo(current);
//		switchImage(image, list[current].imagem);

//		idx_onOff(current);
	}
}

function SlideShow_goto(n){
	if (!finishLoading) {
		alert("Aguarde o carregamento das imagens!");
		return;
	}
	with(this){
/*		clearTimeout(timer); */
		clearInterval(fadeTimer); 
		clearTimeout(fadeTimerOff);
		current = n;
		switchImage(image, list[current].imagem);
		idx_onOff(current);
		document.getElementById('slide').title = list[current].credito;
		document.getElementById('atual').innerHTML = list[current].titulo;
	}
}


function idx_onOff(id){
	for (i=0;i<dadosSlider.length;i++)
		document.getElementById('botaoSlider'+i).className=((i==id)?"ativo":"");
}


