/******************************************************************************************************************/
// SLIDE PRIMO PIANO FUNCTIONS
/******************************************************************************************************************/

function itemSlide(i){
	num = $('#primopiano .item').size();
	
	offset = i * 350;
	offset = '-' + offset;
	
	$('#primopiano UL').animate({top: offset}, 500);
	
	i++;
	if (i >= num) i = 0;
	
	SliderTimerId = window.setTimeout('itemSlide('+ i +')', 3500);
}

function slideHandle(){
	num = $('#primopiano .item').size();
	
	if (num > 1) {
		itemSlide(0);
		
		$('#primopiano .item').hover(function(){
			clearTimeout(SliderTimerId);
			index = $('#primopiano .item').index(this);
		}, function(){
			SliderTimerId = window.setTimeout('itemSlide('+ index +')', 0);
		});
	}
}

/******************************************************************************************************************/
// BLOCKS FUNCTION
/******************************************************************************************************************/

function adjustBlocks(){
	max = 0;
	$('#blocks .cont').each(function(){
		tmp = $(this).height();
		if (max < tmp) max = tmp;
	});
	
	$('#blocks .cont').height(max);
}

/******************************************************************************************************************/
// IMAGES CENTERING FUNCTION
/******************************************************************************************************************/

function adjustImages(){
	$('.photo').each(function(i){
		h1 = $(this).height();
		h2 = $(this).find('IMG').height();
		
		if (h2 > h1) {
			ofs = -((h2 - h1) / 2);
			$(this).find('IMG').css('margin-top', ofs);
		}
	});
}

/******************************************************************************************************************/
// On document load...
/******************************************************************************************************************/

$(function(){
	slideHandle();
	adjustBlocks();
	adjustImages();
	
	$("a#teleassistenza").fancybox({
		frameWidth			:	750,
		frameHeight			:	500,
		hideOnContentClick	:	false,
	}
	);
});
