
// set the starting image.
var i = 0;			

// The array of div names which will hold the images.
var image_slide = new Array('image-1', 'image-2', 'image-3', 'image-4');

var leg_slide = new Array('leg-1', 'leg-2', 'leg-3', 'leg-4');


var aux_slide = new Array('aux-1', 'aux-2', 'aux-3', 'aux-4');

// The number of images in the array.
var NumOfImages = image_slide.length;

// The time to wait before moving to the next image. Set to 3 seconds by default.
var wait = 3000;

// The Fade Function
function SwapImage(x,y) {		
	$(image_slide[x]).appear({ duration: 1.5 });
	//$(leg_slide[x]).show();

/*
var myTypewriter = new Typewriter("myTypewriter");
myTypewriter.addText('Texto adicionado.');
myTypewriter.write();
*/
    $('leg').innerHTML = '<p class="fonte_leg">'+$(leg_slide[x]).innerHTML+'</p>';
	$(image_slide[y]).fade({duration: 0});
//$(leg_slide[x]).innerHTML=$(aux_slide[x]).innerHTML;

	/*$(leg_slide[y]).hide(); */
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	play = setInterval('Play()',wait);
	$('PlayButton').hide();
	$('PauseButton').appear({ duration: 0});
								
}

function Play() {
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function Stop () {
	clearInterval(play);				
	$('PlayButton').appear({ duration: 0});
	$('PauseButton').hide();
}

function GoNext() {
	clearInterval(play);
	$('PlayButton').appear({ duration: 0});
	$('PauseButton').hide();
	
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function GoPrevious() {
	clearInterval(play);
	$('PlayButton').appear({ duration: 0});
	$('PauseButton').hide();

	var imageShow, imageHide;
				
	imageShow = i-1;
	imageHide = i;
	
	if (i == 0) {
		SwapImage(NumOfImages-1,imageHide);	
		i = NumOfImages-1;		
		
		//alert(NumOfImages-1 + ' and ' + imageHide + ' i=' + i)
					
	} else {
		SwapImage(imageShow,imageHide);			
		i--;
		
		//alert(imageShow + ' and ' + imageHide)
	}
}

function Typewriter(sName)
{	// PROPERTIES
	this.counter = 0;
	this.name = sName;
	this.text = "";
	this.speed = 50; // in milliseconds
	
	// METHODS
	this.addText = AddText;
	this.next = Next;
	this.setSpeed = SetSpeed;
	this.write = Write;
	
	// FUNCTIONS
	function AddText(s)
	{	this.text = s
	}
	function Next()
	{	document.getElementById('leg').innerHTML = this.text.substr(0, this.counter++);
	}

	function SetSpeed(iSpeed)
	{	this.speed = iSpeed;
	}
	function Write()
	{	setInterval(this.name+".next()",this.speed);
	}
}
