/**
 * @author stefano
 */
$(document).ready(function() {
	

	//var utente
	var msgPausa = "in pausa...";	//messaggio che appare portando il cursore sopra all'immagine
	var divContent = $('#flash');	//div dove è contenuta l'immagine

	//var
	var msgNormale = $("#flash img").attr('alt');
	var dirLeft;
	var imgSize;
	var scrollLeft;
	var time;
	var actualMargin = 0;
	
	var imgContent = $('> img:first', divContent);
	
	//$(imgContent).hide().fadeIn(2000);

	$(imgContent).each(function() {

		imgSize = parseInt($(this).attr('width'));

		scrollLeft = 500 - imgSize;	
		
		left = function() { 
			time = -(scrollLeft - actualMargin) * 15;
			dirLeft=true;
			$(this).animate({marginLeft: scrollLeft},time, right);
			actualMargin = scrollLeft;
		};
		right = function() {
			time = -(actualMargin) * 14;
			dirLeft=false;
			$(this).animate({marginLeft: "0"},time, left);
			actualMargin = 0;
		};

		$(this).each(left);	
	});
	
	$(divContent).mouseover(function () {
		$(imgContent).attr('alt',msgPausa).attr('title',msgPausa);
		$(imgContent).stop();
		actualMargin= parseInt($(imgContent).css('margin-left')); 
	}).mouseout(function () {	
		$(imgContent).attr('alt',msgNormale).attr('title',msgNormale);
		if (dirLeft)
			$(imgContent).each(left);
		else
			$(imgContent).each(right);
	});
	
	$('#imbottiti #content .left a, #imbottiti #content .right a').mouseover(function () {
		$('> span', this).hide().fadeIn(1200);
	});

	
});
