$(document).ready(function(){

 
 //trovo dimensione massima per container
 var maxHeight = 0;
 var leftC = $('#leftContainer');
 var rightC = $('#rigthContainer');
 var centerC = $('#centerContainer');
 if(centerC.length <= 0)
 	centerC = $('#unsizeContainer');
 
 var target;
 var size = 0;
 if(leftC.length) {
 	target = leftC;
    size = 0;
 	size = target.height() + parseInt(target.css('margin-top').replace("px","")) + parseInt(target.css('margin-bottom').replace("px"),"");
 	maxHeight = size;
 }
 
 if(rightC.length) {
 	var target = rightC;
 	size = 0;
 	size = target.height() + parseInt(target.css('margin-top').replace("px","")) + parseInt(target.css('margin-bottom').replace("px"),"");
 	
 	if(maxHeight < size)  
 		maxHeight = size;
 }
 if(centerC.length){ 
 	var target = centerC;
 	size = 0;
 	size = target.height() + parseInt(target.css('margin-top').replace("px","")) + parseInt(target.css('margin-bottom').replace("px"),"");
 	
 	if(maxHeight < size)  
 		maxHeight = size;
 }
 $('#mainContainer').css('height',maxHeight+'px');
 //____________FOOTER
	setFooterPosition();
 $(window).resize(function(){
 	setFooterPosition();
 });
 
 //___________POPUP
 if(getCookie('popupChiuso')!='true')
 {
	 var larg = $(window).width();
 	$("#mies1").overlay({load:true,top: 260,
 	closeOnClick:false,
 	onClose:function(){
 		setCookie('popupChiuso','true','12-12-2078');
 
 	},
 	top:80, 
 	left:larg - 280});
}
 
 //_____________PROGRAMMI
 $('#listProgrammiLink').mouseenter(function(){
 	window.clearTimeout(timer);
 	var left = $("#listProgrammiLink").width() + $("#listProgrammiLink").position().left + 10;
 	$("#listProgrammi").css('left', left+"px");
 	$("#listProgrammi").css('top', $("#listProgrammiLink").position().top+"px");
  		$("#listProgrammi").show('slow', function() {
    	// Animation complete.
  		});
 }).mouseleave(function(){
  timer = window.setTimeout(function(){ $("#listProgrammi").hide('slow'); }, 1000);
 });
 
 $('#listProgrammi').mouseenter(function(){
 	window.clearTimeout(timer);
 }).mouseleave(function(){
  timer = window.setTimeout(function(){ $("#listProgrammi").hide('slow'); }, 1000);
 });
 
});

var timer;
 function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
var setFooterPosition = function(){
	 var al = $(window).height();
	 var mainCont = $("#mainContainer").height();

 	if((al - (mainCont + 40 + 150)) > 0)
 		$('#footer').height(al - mainCont - 40);
	 else
	 	$('#footer').height(150);
 };
