
var playPreload=new Image();
playPreload.src='fotos/play.gif';
var pB=document.images['PLAY'];
var REWIND=1;
var PAUSE=2;
var FORWARD=3;
var PLAY=4;
function changeButton(){
	if (pB.src.indexOf('play')!=-1){
		pB.src='fotos/pause.gif';
		moveArticle(PLAY);
	}
	else {
		pB.src='fotos/play.gif';
		moveArticle(PAUSE);
	}
}

var lastPicture=0;
var photosLength=8;
var photoInterval=7;	//seconds
function moveArticle(aAction){
	if (aAction==REWIND) {
		lastPicture--;
		clearInterval(playArticle);
		playArticle=false;
	}
	else if (aAction==FORWARD) {
		lastPicture++;
		clearInterval(playArticle);
		playArticle=false;
	}
	else if (aAction==PLAY) {
		if (!playArticle) playArticle=setInterval('moveArticle(PLAY)',photoInterval*1000);
		lastPicture++;
	}
	else if (aAction==PAUSE) {
		clearInterval(playArticle);
		playArticle=false;
	}
	var preLoadImage=new Image();
	preLoadImage.onload=function(){
		document.images['mainPhoto'].src=this.src;
				
	}
	preLoadImage.onerror=function(){
		document.images['mainPhoto'].src='fotos/mainphoto_01.jpg';
	}

	if (lastPicture>=photosLength) lastPicture=0;
	else if (lastPicture<0) lastPicture=photosLength-1;
	preLoadImage.src='fotos/mainphoto_0' + lastPicture + '.jpg';
}

var playArticle=setInterval('moveArticle(PLAY)',photoInterval*1000);

