/**
**************************************************************************
 * Slide Show with Fade-in and Fade-out
**************************************************************************
 * VERSION:       1.1 
 * COMPATIBILITY: Firefox 2.0, MSIE 6, MSIE 7, Safari 3.0
 --------------------------------------------------------------------------
 * AUTHOR:			Douglas Fabiano Gaizer Barbosa (dbarbosa@cit.com.br)
 * DATE:			2008/05/12
 * LASTS UPDATES:
  		2008/05/12: Douglas Fabiano Gaizer Barbosa (dbarbosa@cit.com.br) --------------------------------------------------------------------------
**/
 
///==================================== START
var divs = new Array();
divs[0] = "#slide-top-01";
divs[1] = "#slide-top-02";
divs[2] = "#slide-top-03";

sTotal = divs.length-1;
scontinue = true;
outSlide = sTotal;
speedSlide = 3000;
firstSlide = 1000;

///==================================== FADEIN
function startShowIn() {		
	$(divs[outSlide]).fadeIn(1000);
	window.setTimeout(
		function() {
			for(i=0; i<=sTotal; i++) {
				$(divs[i]).fadeIn(1);
			}
			window.clearInterval(ie);
			startShow(0);
		}
	, speedSlide);
}

///==================================== FADEOUT
function startShowOut() {
	if(scontinue == true) {
		$(divs[outSlide]).fadeOut(1000);
		outSlide--;
		if(outSlide==-1){
			outSlide=sTotal;
			startShowIn();
			window.clearInterval(ie);
		}
	}
}

///==================================== STARTSHOW FUNCTION
function startShow(t) {	
	if(t==0) {
		startShowOut();
		ie = setInterval('startShowOut()',speedSlide);
	}
	else {		
		startShowIn();
		ie = setInterval('startShowIn()',speedSlide);
	}
}

///==================================== START STOP FUNCTION

function stopShow() {
	document.getElementById('play').style.display = "block";
	document.getElementById('stop').style.display = "none";
	scontinue = false;
	window.clearInterval(ie);
	ie = null;
}

///==================================== START PLAY FUNCTION
function playShow() {
	document.getElementById('stop').style.display = "block";
	document.getElementById('play').style.display = "none";
	if(scontinue == false){
		window.clearInterval(ie);
		ie = null;
		scontinue = true;		
		startShow(0);
	}
}

///==================================== START NEXT FUNCTION

function nextShow() {
	document.getElementById('play').style.display = "block";
	document.getElementById('stop').style.display = "none";
	scontinue = true;
	window.clearInterval(ie);
	ie = null;
	nextShowSlide();	
}

function nextShowSlide() {
	ShowOut();
	ie = setInterval('ShowOut()',50);
}

///==================================== FADEOUT FUNCTION
function ShowOut() {
	if(scontinue == true) {
		$(divs[outSlide]).fadeOut(50);
		window.clearInterval(ie);
		ie = null;
		outSlide--;
		scontinue = false;		
		if(outSlide==-1){
			outSlide=sTotal;
			ShowIn();		
		}
	}
}

///==================================== SHOWIN FUNCTION
function ShowIn() {
	$(divs[outSlide]).fadeIn(50);
	window.setTimeout(
		function() {
			for(i=0; i<=sTotal; i++) {
				$(divs[i]).fadeIn(1);
			}			
			window.clearInterval(ie);
			ie = null;			
		}
	, 50);	
}

///==================================== START PREV FUNCTION

function prevShow() {
	document.getElementById('play').style.display = "block";
	document.getElementById('stop').style.display = "none";
	scontinue = true;
	window.clearInterval(ie);
	ie = null;
	prevShowSlide();
}

function prevShowSlide() {	
	prevShowIn();
	ie = setInterval('prevShowIn()',50);
}

///==================================== PREV SHOW OUT FUNCTION
function prevShowOut() {	
	window.clearInterval(ie);
	ie = null;
	$(divs[outSlide]).fadeOut(50);
	for(i=outSlide-1; i>0; i--) {
		$(divs[i]).fadeOut(1);
	}
	outSlide = 0;
	prevShowIn();
}

///==================================== PREV SHOW IN FUNCTION
function prevShowIn() {
	if(scontinue == true) {	
		if(outSlide >= sTotal) {
			scontinue = false;
			outSlide = sTotal;
			window.clearInterval(ie);
			ie = null;
			prevShowOut();
		}
		else {
			outSlide = outSlide+1;
			$(divs[outSlide]).fadeIn(50);
			scontinue = false;
			window.clearInterval(ie);
			ie = null;			
		}
	}	
}

///==================================== START LOAD FUNCTION

function loadslide() {	
	window.setTimeout(
		function() {			
			document.getElementById('buttons-slide').style.display = "block";
			document.getElementById('play').style.display = "none";
			document.getElementById('stop').style.display = "block";
			startShow(0);
		}
	, firstSlide);
}
