function FloatMenu(div, margin){
    margin = margin || {top: 0, bottom: null, fade: false};
    margin.top = margin.top || 0;
    margin.fade = margin.fade || false;
    if (margin.bottom != null)
    	var scrollAmount=$(document).scrollTop()+$(window).height()-$("#footer").height();
    else
	    var scrollAmount=$(document).scrollTop()+margin.top;
	    
	if ($(window).height() < div.height()) {
	    if (margin.bottom != null)
		    div.css("top", margin.top );
	} else {
	    if (margin.fade == true) {
	        div.stop().animate({opacity: 0}, 1, function(){
	            $(this).css({'top' : scrollAmount , 'position':'absolute'}).animate({opacity: 1}, 250);	            
	        });
	    } else { 
		    div.stop().animate({top: scrollAmount}, 1000, 'easeOutQuint');
		}    
	}
}

function correct_height(){
    var altezza = $(window).height()-$("#header").height()-$("#footer").height();
    altezza = altezza > 565 ? altezza+'px' : '565px';
    $("#tooltip_home").css("height", altezza );
    
    var larghezza = $(window).width();
    larghezza = larghezza < 930 ? '830px' : '';
    $('#logo').css('left', larghezza );
}

function mappaSfondo( lat, long, zoom ) {
  var latlng = new google.maps.LatLng( lat, long );
  var myOptions = {
    zoom: zoom,
    disableDefaultUI: true,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.SATELLITE
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"),
      myOptions);
}


$(document).ready(function(){
        
        correct_height();
        var header = $('#header');
        var sideMenu = $('#contfiltraprogetti');
        var footer = $('#footer');
  
    	$('#header li').hover(
    		function () {
    			//show its submenu
    			$('ul', this).slideDown(100);
    
    		}, 
    		function () {
    			//hide its submenu
    			$('ul', this).slideUp(100);			
    		}
    	);
    	
        	
    	var altezzaspallasx = $("#spallasx").height();
    	if	(altezzaspallasx>400) {
    		$("#map_canvas").css("height", altezzaspallasx + 100 );
    	}	
		
		
		$('#closefiltro a').toggle(
		    function () {
		        var $this = $(this).parent().parent();
		        $this.stop().animate({'width':'0px'},500);
   		        $('#closefiltro').stop().animate({'right':'0px'},500);
		        $('#closefiltro a').addClass("apri");
		       
		    },
		    function () {
		        var $this = $(this).parent().parent();
		        $this.stop().animate({'width':'126px'},500);
		        $('#closefiltro').stop().animate({'right':'126px'},500);
		        $('#closefiltro a').removeClass("apri");
		       
		    }
		);
		
		menuSetActive('#header li', 'attivo', true, true);
		
		/*USATO COME EFFETTO NELLE SEZIONI DI CHI SIAMO E CONTATTI*/
		$('#openContent').hide('fade', 10 );
		
		$('#closeDiv').click(function(){
		    $('.closeContent').hide('fade', 500 );
		    $('#openContent').show('fade', 500 );
		});
		    
		$('#openContent').mouseover(function(){
		    $('.closeContent').show('fade', 500 );
		    $('#openContent').hide('fade', 500 );
		});
		
		$(window).resize(function() {
		    correct_height();
		    FloatMenu(sideMenu, {top: 95});
		    if ($.browser.webkit){
    		    FloatMenu(header, {top : 0, fade: true});
    		    FloatMenu(footer, {bottom : 0, fade: true});
		    }
		});
		
		$(window).scroll(function() {   
		     FloatMenu(sideMenu, {top: 95});
		     if ($.browser.webkit){
		         FloatMenu(header, {top : 0, fade: true});
		         FloatMenu(footer, {bottom : 0, fade: true});
		     }
		});
});






