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

function OfferteHoverHandle(){
	$('.offerte LI').hover(function(){
		clearTimeout(OfferteTimerId);
		index = $('.offerte LI').index(this);
	}, function(){
		OfferteRun(index);
	});
}

function OfferteShow(i){
	$('.offerte LI').hide();
	$('.offerte LI:eq('+ i +')').show();
}

function OfferteRun(i){
	num = $('.offerte LI').size();
	if (num > 1) {
		OfferteShow(i)
		i++;
		if (i == num) i = 0;
		OfferteTimerId = window.setTimeout('OfferteRun('+ i +')', 5000);
	}
}

/******************************************************************************************************************/
// NEWS FUNCTIONS
/******************************************************************************************************************/

function TickerHoverHandle(){
	$('.ticker LI').hover(function(){
		clearTimeout(TickerTimerId);
		index = $('.ticker LI').index(this);
	}, function(){
		TickerRun(index);
	});
}

function TickerShow(i){
	$('.ticker LI').hide();
	$('.ticker LI:eq('+ i +')').show('slow');
}

function TickerRun(i){
	num = $('.ticker LI').size();
	if (num > 1) {
		TickerShow(i)
		i++;
		if (i == num) i = 0;
		TickerTimerId = window.setTimeout('TickerRun('+ i +')', 5000);
	}
}

/******************************************************************************************************************/
// SIDEBAR CATEGORIES FUNCTIONS
/******************************************************************************************************************/

function submenuHandle(){
	$('#menu .disable').click(function(){ return false; });
	
	$('#menu LI').hover(function(){
		$(this).find('.submenu').show(200).fadeTo(1,0.95);
	}, function(){
		$(this).find('.submenu').hide(200);
	});
}

/******************************************************************************************************************/
// SIDEBAR CATEGORIES FUNCTIONS
/******************************************************************************************************************/

function sidecategoriesHandle(){
	$('#sidebar #categories LI UL').hide();
	
	$('#sidebar #categories .current-cat UL').show();
	$('#sidebar #categories .current-cat').parent().show();
	
	$('#sidebar #categories LI').hover(function(){
		if ($(this).find('UL')) $(this).find('UL').show();
	}, function(){
		if ($(this).hasClass('current-cat') || $(this).find('LI').hasClass('current-cat')) { } 
		else if ($(this).find('UL')) $(this).find('UL').hide(400);
	});
}

/******************************************************************************************************************/
// ON DOCUMENT LOAD...
/******************************************************************************************************************/

$(function(){
	// Primo Piano
	/*max = $('.offerte LI').eq(0).height();
	$('.offerte LI').each(function(i){
		if ($(this).height() > max) max = $(this).height();
	});
	$('.offerte').height(max);
	$('.offerte LI').height(max);*/
	
	OfferteRun(0);
	OfferteHoverHandle();
	
	//Submenu
	submenuHandle();
	
	// News
	TickerRun(0);
	TickerHoverHandle();
	
	// Sidebar Categories
	sidecategoriesHandle();
});