// JavaScript Document


var div_name = "page_box_contenuto";
var div_hide = 1;
var div_active = 2;
var div_num;
var div_width = 720;
var timer_value="10000";
var play = true;

interval = setInterval(SlideShowLayer,timer_value);

function SlideShowLayer(){
	
	div_num = document.getElementById("slideshow_div_num" ).innerHTML;
	div_num = parseInt(div_num) + parseInt(div_hide);
	document.getElementById(div_name).style.width = (div_width*parseInt(div_num));
	//alert (div_num);
	if(play){next();}


}
function next(){
	if(div_active==div_num ){
		first();
		clearTimeout(interval);
	}else{ 
		var newMargin = (div_active*parseInt(div_width));
		//alert (newMargin);
		div_active = div_active + 1;
		$("#"+div_name).animate({ marginLeft: "-"+newMargin+"px" }, 900 );
		//event.preventDefault();
	}
}
function previus(){
	if(div_active==parseInt(div_hide)+1 ){
		return;
	}else{ 
		div_active = div_active - 1;
		var newMargin = ((div_active-1)*parseInt(div_width));
		$("#"+div_name).animate({ marginLeft: "-"+newMargin+"px" }, 900 );
		//event.preventDefault();
	}
}
function first(){
		//alert (newMargin);
		div_active = 1+parseInt(div_hide);
		var newMargin = div_width*parseInt(div_hide);
		//alert(newMargin);
		$("#"+div_name).animate({ marginLeft: "-"+newMargin+"px" }, 900 );
		interval = setInterval(SlideShowLayer,timer_value);

}
function pause(){
 	play=false;
	document.getElementById("btn_play" ).style.display='inline';
	document.getElementById("btn_pause" ).style.display='none';

}
function btn_play(){
	document.getElementById("btn_play" ).style.display='none';
	document.getElementById("btn_pause" ).style.display='inline';
	play=true;
	next();

}
function btn_forward(){
	document.getElementById("btn_play" ).style.display='inline';
	document.getElementById("btn_pause" ).style.display='none';
	play=false;
	next();

}
function btn_rewind(){
	document.getElementById("btn_play" ).style.display='inline';
	document.getElementById("btn_pause" ).style.display='none';
	play=false;
	previus();

}
