var current_image = 1;
var next_image = 2;
var bool=true;
var width=448;
var current_trailer=0;
var delay_i=0;

//show trailer
function trailer(val){
	if(delay_i==0){
		ad();
		setTimeout(
		test=function(){
			$('pub').style.display="none";
			// if(current_trailer!=0){
				// $("trailer"+current_trailer).style.display="none";
			// }
			$("trailer"+val).style.display="block";
			current_trailer=val;
		},5000);
	}

}

//display time remaining 
function disp_delay(){
	if(delay_i==5){$("time").innerHTML="";delay_i=0;return;}
	else if(delay_i<5){
		$("time").innerHTML="Patientez encore "+(5000-1000*delay_i)/1000+"s...";
		delay_i=delay_i+1;
		setTimeout("disp_delay()",1000);
	}
	
} 
//show advertising
function ad(){
	if(current_trailer!=0){
		$("trailer"+current_trailer).style.display="none";
	}
	disp_delay();
	$('pub').style.display="block";
}

//move in the right
function move(value){
if(bool){
	bool=false;
	new Effect.Parallel([
		 new Effect.Move('img1', { x: value, y: 0, mode: 'relative' }),
		 new Effect.Move('img2', { x: value, y: 0, mode: 'relative' }),
		 new Effect.Move('img3', { x: value, y: 0, mode: 'relative' }),
		 new Effect.Move('img4', { x: value, y: 0, mode: 'relative' }),
		 new Effect.Move('img5', { x: value, y: 0, mode: 'relative' })
	], { 
  duration: 0.4, afterFinish:function(){bool=true;}
});
return true;
}
else{return false;}

}
//shows previous image
function previous(){
	clearTimeout(t);
	if(current_image==1){
		var fin=-4*width;
		if(move(fin)){current_image=5;}
	}
	else{
		if(move(width)){current_image=current_image-1;}
	}
	galerie();
}

//shows next images
function next(){
	ClearTime();
	//move all the images
	if(current_image==5){
		var fin=4*width;
		if(move(fin)){current_image=1;}
	}
	else{
		if(move(-width)){current_image=current_image+1;}
	}
	//end move
	galerie();
}

//go to the last img
function last(){
	ClearTime();
	var move_last=-(5-current_image)*width;
	if(move(move_last)){current_image=5;}
	galerie();
}

//go to the first img
function first(){
	ClearTime();
	var move_first=(current_image-1)*width;
	if(move(move_first)){current_image=1;}
	galerie();
}

//Set a Time Transition between two effects
function galerie() {
	t=setTimeout("next()",5000);
}
//ClearTime
function ClearTime(){
	clearTimeout(t);
}

//initialisation
function init(){
	var x=width*4;
	$('img1').style.top='0px';
	$('img5').style.left=x+'px';	
	$('img2').style.top='-297px';
	$('img4').style.left=x-1*width+'px';
	$('img3').style.top='-594px';
	$('img3').style.left=x-width*2+'px';
	$('img4').style.top='-891px';
	$('img2').style.left=x-width*3+'px';
	$('img5').style.top='-1188px';
	$('img1').style.left=x -width*4+ 'px';
	$('time').style.color='white';
	galerie();
}