$(document).ready(function(){
	
	$('#content').css('height','272');
	
	$('#carousel .tab h2').hide();
	$('#carousel .tab:not(:first)').hide();
	
	$('ul#carousel-nav li a').click(function(e){
		e.preventDefault();
		var tab_to_show = $(this).attr('href');
		var new_class = tab_to_show.split('-')[1];

		var actual_class = $('ul#carousel-nav').attr('class');
		$('ul#carousel-nav').removeClass(actual_class).addClass(new_class);
		$(tab_to_show).show().siblings('.tab').hide();		
	});
	
	
	//gestione linkbox
	$("#news ul li").hover(function(){
			$(this).css({'cursor':'pointer'}).addClass("hovering");
		},function(){
		$(this).removeClass("hovering");
	}).click(function(){
		document.location = $(this).find("a:first").attr("href");
	});
	
});

function getCookie(name, defaultValue) {
    var value = $.cookie(name);
    return (value == null) ? defaultValue : value;
}

function setCookie(name, value, cookieSettings) {
    if (cookieSettings == null) {
        cookieSettings = getDefaultCookieSettings();
    }
    $.cookie(name, value, cookieSettings);
}

function getDefaultCookieSettings() {
    return {
        expires: 365,
        path: '/'
    };
}
function showHomePageAdIfRequired(){
	// NB: month is zero-based, ex: 0 - january
	var startDate = new Date(2011, 4, 12, 11, 0, 0, 0);
	var endDate = new Date(2011, 4, 20, 18, 0, 0, 0);
	//var startDate = new Date(2010, 10, 18, 16, 0, 0, 0);
	//var endDate = new Date(2010, 11, 2, 8, 0, 0, 0);
	var nowDate = new Date();
	
	var timeBeforeStartInMs = startDate.getTime() - nowDate.getTime();
	var timeLeftInMs = endDate.getTime() - nowDate.getTime();
	if (timeBeforeStartInMs >= 0 || timeLeftInMs <= 0) {
		return;
	}
	
	//$('#homepage-ad-launcher-link').click();
	
	if (parseInt(getCookie('hpas', 0)) == 0) {
		setCookie('hpas', 1, {
			expires: 0,
			path: '/'
		});
		$('#homepage-ad-launcher-link').click();
		
		setTimeout(function(){
		
			tb_remove();
			
		}, 12000);
	}
}


