$(function(){
	
	/* GESTIONE LOADING DELLA BF */
	$('#bf .bf-content').css('display','block');
	$('#bf').removeClass('loading');
	
	
	// FANCYBOX	
	jQuery(".photogallery a").fancybox();
	jQuery("#footer a.cat_16").attr('href', 'http://www.fastbooking.net');
	jQuery("#footer a.cat_16").attr('target', '_blank');
	
	
	/* HEIGHT SLIDESHOW */
	var height_slideshow = $('#slideshow').height(); 
	if (height_slideshow<420) {
		//alert("bassa");
		var image_background = "/themes/piandercole/images/bg_body_small.png";
		$('body').css('background-image','url("'+image_background+'")');
		$('#page_box').css('background-image','url("/themes/piandercole/images/bg_shadow_category.png")');
		$('#stemma').css("left","870px");
	}
	
	/***************************************************/
	/****************	 UNIFORM	********************/
	/***************************************************/
	$("#idForm .small select, #Posizione, #Language").uniform();	
		
	var i = 1;
	t = setTimeout('rotateCallouts('+i+')',6000);
	animationControls();
	
	// 
	$('#numbers a').mouseover(function(){
		$('#numbers span').each(function() {	
			$(this).removeClass('current');
		});
		
		clearTimeout(t);
		
		var thisId = $(this).attr('id');
		i = thisId.replace('number','');
		newId = 'div#rotating' + i;
		
		$('div.rotatingDiv:visible').css({display:"none"});
		
		$(newId).css({display:"block"});
		
		$(this).parent('span').addClass('current');
	});
	
});	/* end $(function) */
		
		
		

/*****************************************************/
/**************** 		FUNCTIONS 		**************/
/*****************************************************/
// FUNCTION animationControls
function animationControls(){
	$('div.rotatingDiv').mouseover(function(){
		clearTimeout(t);
	});

	$('div.rotatingDiv').mouseout(function(){
		visibleId = $('div.rotatingDiv:visible').attr('id');
		i = visibleId.replace('rotating','');
		t = setTimeout('rotateCallouts('+i+')',6000);
	});
	
	$('#numbers a').mouseover(function(){
		var thisId = $(this).attr('id');
		i = thisId.replace('number','');
		newId = 'div#rotating' + i;
		
		$('div.rotatingDiv:visible').css({display:"none"});
		
		$(newId).css({display:"block"});
	});	
}


// FUNCTION rotateCallouts		
function rotateCallouts(i){			
	if(i<5){
		thisId = 'div#rotating' + i;
		newId = i;
		newId++;
		newId = 'div#rotating' + newId;
		

		$('#numbers .element' + i).removeClass('current');

		
		$(thisId).fadeOut(1000,function(){
			$(newId).fadeIn(100); // SCRITTA
			$('#numbers .element' + i).addClass('current');
			i++;
		});
		
		i = newId.replace('div#rotating','');
		parseFloat(i);
		t = setTimeout('rotateCallouts('+i+')',6000);

	}
	else if(i===5){
		//Uncomment the code below to repeat
		
		$('#numbers .element' + i).removeClass('current');
		
		
		$('div#rotating5').fadeOut(1000,function(){
			$('div#rotating1').fadeIn(1000);
			i++;
		});
		i = 1;
		
		setTimeout('rotateCallouts('+i+')',6000);
		$('#numbers .element' + i).addClass('current');
	}
}





