/*
	Autore: Danilo Cicognani
	Script: common.js
	Applicazione: www.fieraesagradeigusti.it
	Versione: 1.01
	Data: 16/02/2010
	Scopo: Animazioni JavaScript
	Copyright (c) 2009-2010 Danilo Cicognani
*/
var headPath = 'http://www.fieraesagradeigusti.it/imgs/';
var headNum = 1;
var headTot = 12;
var headTime1 = 2000;
var headTime2 = 3000;
var headLoaded = false;
var headTime = false;
$('document').ready(function() {
	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_rounded', hideflash: true, showTitle: false, allowresize: false});
	$('.tabgialla, .tabrossa').hover(function() {
		$(this).addClass('over');
	}, function() {
		$(this).removeClass('over');
	});
	headLoad();
	tmrHeadAnim = setTimeout('headTimer()', headTime1);
});
function headTimer() {
	headTime = true;
	if (headLoaded)
		headAnim();
}
function headLoad() {
	var headImage = new Image();
	if (++headNum > headTot) headNum = 1;
	headImage.onload = function() {
		headLoaded = true;
		if (headTime)
			headAnim();
		headImage.onload = function(){};
	};
	headImage.src = headPath + 'foto' + headNum + '.jpg';
}
function headAnim() {
	headLoaded = false;
	headTime = false;
	$('#foto img').fadeOut('slow', function() {
		$('#foto img').attr('src', headPath + 'foto' + headNum + '.jpg');
		$('#foto img').fadeIn('slow', function() {
			headLoad();
			tmrHeadAnim = setTimeout('headTimer()', headTime2);
		});
	});
}