/*
var jGalleryTimer = 0;
var jGalleryFirstStart = true;
var jGallery_action = false;
*/
/*
for(i=1;i<=9;i++)
	$("#incipit-"+i).css("display","none");
var currentframe = 1;

function incipit()
{
	for(i=1;i<=9;i++)
	{
		if(i!=currentframe)
			$("#incipit-"+i).css("display","none");
		else
			$("#incipit-"+i).css("display","block");
		curheight=$("#testo").height();
		$("#draggable").css("height",curheight);
	}
}
*/
/*
function jGallery(id, visible, timeInterval, transitionInterval)
{

	var visible = (visible) ? visible : 1;
	var timeInterval = (timeInterval) ? timeInterval : 5000;
	var transitionInterval = (transitionInterval) ? transitionInterval : 200;

	var w = (w) ? w : $("."+id+"-gallery-div :first").width();
	//var w = $("."+id+"-gallery-div:first").width();
	
	var cnt = $("#gallery-"+id+"-holder > div").size();
	if(jGalleryTimer)
	{
		clearInterval(jGalleryTimer);
		jGalleryTimer = 0;
	}
	if(!jGalleryFirstStart)
	{
		if(!jGallery_move(id, cnt, -1, w, visible, transitionInterval))
			jGallery_restart(id, cnt, transitionInterval);
	}
	
	jGalleryFirstStart = false;
	
	jGalleryTimer = setInterval(function(){ jGallery(id, visible, timeInterval, transitionInterval); }, timeInterval);
	incipit();
}
*/
/*
function jGallery_move(id, cnt, dir, w, visible, transitionInterval)
{
	if(jGallery_action)
		return false;
		
	var curr = document.getElementById("gallery-"+id+"-holder").style.left;
	curr = parseFloat(curr);
	if(isNaN(curr))
		curr = 0;
	if(dir > 0)
	{
		if(curr >= 0)
			return false;
	}
	else
	{
		if(curr + cnt * w - visible * w <= 0)
			return false;
	}

	jGallery_action = true;
	var offset = w;

	if(dir < 0)
		dir = "-";
	else
		dir = "+";
		
	$("#gallery-"+id+"-holder").animate(
		{left : dir+"="+offset+"px"},
		{queue:true
			, duration:transitionInterval
			, complete: function() 
			{
				jGallery_action = false;
				currentframe=((currentframe)%9)+1;
				incipit();
			}
		}
	);
	
	return true;
}
*/
/*
function jGallery_restart(id, cnt, transitionInterval)
{
	if(jGallery_action)
		return false;
		
	var curr = document.getElementById("gallery-"+id+"-holder").style.left;
	curr = parseFloat(curr);

	if(isNaN(curr))
		curr = 0;
	if(curr >= 0)
		return false;

	jGallery_action = true;
	var offset = curr * (-1);

	$("#gallery-"+id+"-holder").animate(
		{left : "+="+offset+"px"},
		{queue:true, duration:transitionInterval*cnt, complete: function() {currentframe=((currentframe)%9)+1;jGallery_action = false;incipit();}}
	);
	
	return true;
}
*/
function restartgallery()
{
	
	$("#gallery-pitch-holder").css("left","0px");
	//console.log("restart "+$('#gallery-pitch-holder').css("left"));
	
	
	$('#gallery-pitch-holder').animate({
	    left: '-='+ gallerywidth
	  }, 150000, 'linear', function(){ restartgallery();});
}

function adatta()
{	
	if($.browser.msie)
	{
		var w = document.body.offsetWidth/2+10;
		var h = document.documentElement.clientHeight;
	}
	else
	{
		var w = window.innerWidth/2;
		var h = window.innerHeight;
	}
	
	var containeraspect=w/h;
	
	//ridimensiono il contenitore dell'elemento draggable
	$('#content_main').css('height',h);
	//Contenitore immagini di sfondo
	$('#content_img').css('height',h);
	$('#content_img img').each( function(i){
		var aspect = $(this).width()/$(this).height();
		
		if(containeraspect>aspect)
		{
			//$(this).animate({'height':w/aspect,'width':w},100);
			$(this).css('height',w/aspect);
			$(this).css('width',w);
		}
		else
		{
			//$(this).animate({'height':h,'width':h*aspect },100);
			$(this).css('height',h);
			$(this).css('width',h*aspect);				
		}
		
	});
	$('#gallery-pitch-holder').css("width",11*$('#pitch11').width());
	gallerywidth = $('#gallery-pitch-holder').width()-$('#pitch11').width();
	$('#gallery-pitch-holder').stop(true);	
	
	//da 506 a 442 = 64
	//immagine al minimo = 22px
	//immagine al massimo = 84px
	if(h<506)
	{
		variation = (h-442)/64; 
		//alert( variation *62 +22 );
		$('img.footerimage').css("height",((variation *62 +22)+"px"));
		
		
		$('img.footerimage').css("margin-right",(variation*14+10)+"px");
		$('img.footerimage').css("margin-top",(variation*5+5)+"px");
		$('img.footerimage').css("margin-bottom",(variation*5+5)+"px");
		
		//alert(h+" "+$('img.footerimage').css("height"));
	}
	else
	{
		$('img.footerimage').css("height","84px");
		$('img.footerimage').css("margin-right","24px");
		$('img.footerimage').css("margin-top","5px");
		$('img.footerimage').css("margin-bottom","5px");
	}
	

	restartgallery();
	//currentframe=1;
	$('#content_img').css('visibility','visible');
}

