/* show the content */
$('#content').show();


//Resize the white content window on pages with Jquery. Couldn't get it to work with CSS only!!

    $(window).resize(function() {
	    resizepage(120);
	});
	
    function resizepage (dif) {
        var heightToFill = $("#content").height() - $("#infobar").height() - $("#header").height() - dif;
         var pageheight = $("#pages").height();
         
        if (heightToFill < pageheight){
	       heightToFill = pageheight;
        }
        
        if (heightToFill > pageheight){
	     $("#pages").height(heightToFill);
        }
        
        
        
        
        //$("#pages").text("( heightofill , pageheight) - " + heightToFill + pageheight);

}

$('#contact-form_es_').change(function() {
  alert('Handler for .change() called.');
});


$('#comment-form').click(function() {
	     resizepage();
});


//cookies

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;
}

function deleteCookie(name) {
    setCookie(name,"",-1);
}



//called once all the images are loaded.
$(window).load(
    function() {
       resizepage(120);
    }
).delay(1000, "myQueue").queue("myQueue", function(){ 
       resizepage(120);
}).dequeue("myQueue");


//Menu

     $(document).ready(function() {     
	     //mute the sound if the sound_muted cookie is set
	     if ((getCookie('sound_muted') == 'true') && ($("#mute") != 0)){
		     $("#mute > p").toggle();
	  $("audio") //loop for each item
  .each(function(i) {
	   this.muted = true;
  });
} 

	     
	
	        
	//remove sound on iOS (no rollover state) and IE 8 since it don't work.     
    if ($.browser.msie ) {
	  if ($.browser.version < 9){
		      $('#mute').remove(); 
	  }
	} else if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
		$('#mute').remove(); 
		
	}
  

	
	        /* this is the height of the menu for use later */
	        var menuheight = $('#menu').css('height');
	            
	// Expand menu
	/* Disabled
	$("#header").mouseenter(function(){
		if ($('#panel').css('height') == '0px'){
			$("div#menu").slideDown("slow");
	     }	
	});	
	*/
	
	//Open and close menu
	$("#header").click(function(){
		if ($("div#menu").is(":visible") == true){
		$("div#menu").slideUp("slow");
	    } else if ($("div#menu").is(":visible") != true){
			$("div#menu").slideDown("slow");
	    }
	});	
	
	$("#buffer").mouseenter(function(){
  	if ($("div#menu").is(":visible") == true){
		$("div#menu").slideUp("slow");
     }	
   }); 

		
});
