/* RIDIMENSIONAMENTO DIV */

var GLOBALS = {};

var ridimensionamento_div;
ridimensionamento_div = function(){

	if(NOSCRIPT)
		return;
	var larghezza = 0;
	var largh_ultima_foto = 0;
	var larghezza_finestra = 0;
	var larghezza_gap = 0;
	var largh_altre_foto = 0;
	GLOBALS.limiti_foto = new Array();
	var limiti_foto = GLOBALS.limiti_foto;
	limiti_foto.push(0);
	$('#scroll_content img').each(
		function(i,el){
			larghezza += el.offsetWidth+2;
			limiti_foto.push(larghezza);
			largh_ultima_foto = el.offsetWidth;
			GLOBALS.max_foto = i;
		}
	);
	limiti_foto.pop();
	
	if($.browser.msie)
	{
		larghezza_finestra = document.documentElement.clientWidth;
	}
	else
	{
		larghezza_finestra = window.innerWidth;
	}
		
	larghezza_gap = larghezza_finestra-parseInt($('#left_col_bg').css('width'))-largh_ultima_foto;
		
	if($.browser.msie)
	{
		$('#end').css('float','left');
		//$('#end').css('margin-right','');
		if(($('#end a').length > 1)&&($.browser.version != '8.0'))
		{
			$('#end').css('position','relative');
			$('#end a')[0].style.display = 'block';
			$('#end a')[0].style.position = 'absolute';
			$('#end a')[0].style.top = '214px';
			$('#end a')[0].style.left='50px';
			$('#end a')[1].display = 'block';
			$('#end a')[1].style.position = 'absolute';
			$('#end a')[1].style.top = '214px';
			$('#end a')[1].style.left='200px';
			/*
			$('#end a:last').css('margin-left',100); /* era margin-left e non riuscivo a cliccare il pulsante older coperto dal newer*/
			/*$('#end a:last').css('margin-top',214);
			*/
		}
	}

	
	$('body').css('width',larghezza+larghezza_gap);
	$('#mirror').css('width',parseInt($('#left_col_bg').css('width'))+larghezza+30);
	$('#scroll_content').css('width',larghezza+larghezza_gap);
	$('#posts').css('width',larghezza+larghezza_gap);

	/*
		gestione fixed su IE6
	*/
	if($.browser.msie && ($.browser.version == '6.0'))
	{
		$('#fixed_content').css('position','absolute');
		$('#fixed_content').css('top',0);
		$('#fixed_content').css('height',document.documentElement.clientHeight);
		window.attachEvent(
			'onscroll',
			function(){
				$('#fixed_content').css('left',document.documentElement.scrollLeft);
			}
		);/*
		setInterval(function(){
				$('#fixed_content').css('left',document.documentElement.scrollLeft);
			},1000);*/
		
	}
};

/* BOTTONI */

var animazioni_bottoni;

animazioni_bottoni = function(){
	if(NOSCRIPT)
		return;
		
	var bottone_sinistra = document.getElementById('bottone_sinistra');
	var bottone_destra   = document.getElementById('bottone_destra');
	
	var fotoPrecedente;
	var vaiAFoto;
	var prossimaFoto;
	var fotoAttuale;
	
	fotoAttuale = function(){
		var i = 0;
		var foto_attuale;
		
		foto_attuale = i
		posizione = HtinyScrolling.getScrollLeft();
		while(GLOBALS.limiti_foto[i]<=posizione)
		{
			foto_attuale = i;
			i++;
		}
		//foto_attuale = (foto_attuale==0)?foto_attuale+1:foto_attuale;
		
		return foto_attuale;
	};
		
	prossimaFoto = function(){
	
		var prossima_foto;
		var foto_attuale;
		
		foto_attuale = fotoAttuale();

		prossima_foto = (foto_attuale==(GLOBALS.max_foto))?foto_attuale:foto_attuale+1;
		//alert('foto attuale:'+foto_attuale+'\nprossima foto:'+prossima_foto);
		vaiAFoto(prossima_foto);
	};
	fotoPrecedente = function(){
		var foto_attuale;
		var foto_precedente;
		var posizione;
		
		foto_attuale = fotoAttuale();
		foto_precedente = foto_attuale;
		//alert('foto attuale:'+foto_attuale+'\nfoto precedente:'+foto_precedente);
		posizione = HtinyScrolling.getScrollLeft();
		if(posizione==GLOBALS.limiti_foto[foto_precedente]&&foto_precedente!=0)
			foto_precedente--;
		vaiAFoto(foto_precedente);
	};
	
	vaiAFoto = function(n){
		var indice = parseInt(n);
		var foto = GLOBALS.limiti_foto[indice];
		//alert(indice+':'+foto);
		jQuery('html, body').animate(
				{ scrollLeft: foto }, 
				500
			);
	};
	
	if(window.addEventListener)
	{
		bottone_sinistra.addEventListener('click', fotoPrecedente, false);
		bottone_destra.addEventListener('click', prossimaFoto, false);
	}
	else if(window.attachEvent)
	{
		bottone_sinistra.attachEvent('onclick',fotoPrecedente);
		bottone_destra.attachEvent('onclick',prossimaFoto);
	}
	

	
};

if(window.addEventListener)
{
	window.addEventListener('load', ridimensionamento_div, false);
	window.addEventListener('load', animazioni_bottoni, false);
}
else if(window.attachEvent)
{
	window.attachEvent('onload',ridimensionamento_div);
	window.attachEvent('onload',animazioni_bottoni);
}


