/*

Sardine Academy

Actions
Version 2

*/


// menu animations

$(document).ready(function() {
  
  // Background resizer
  if($.browser.safari) {
    var img = $('#background img');
    img.load(function() {
      var o = {
        width: img.width(),
        height: img.height(),
        p: img.width()/img.height()
      };

      $(window).resize(function() {
        var self = $(this);
        var width = self.width();
        var height = self.height();
        img.css({
          width: (y = (width > (x = Math.round(height * o.p)))) ? width : x,
          height: (y ? Math.round(width / o.p) : height)
        });
      });
      $(window).trigger('resize');
    });
  }
	
	// t is for main menu timer				   
	var t;
	
	// expands main menu
	explode_menu = function() {
		$("#navigation_main").animate({
			width: "283px",
			height: "324px"
			}, 200);
		setTimeout("$('#navigation_main h2').fadeIn('slow');$('#navigation_main ul').fadeIn('slow');", 200);
	}
	
	// collapse main menu
	collapse_menu = function() {
		$("#navigation_main h2").fadeOut("fast");
		$("#navigation_main ul").fadeOut("fast");
		$("#navigation_main").animate({ width: "122px", height: "42px" }, 200);
	}
	
	// menu hover actions		   
	$("#navigation_main.content").hover(function() {
		clearTimeout(t);
		explode_menu();
	},
	function() {
		t = setTimeout("collapse_menu();", 800);
	});
	
	// sets menu to "hide" on "content" pages
	$("#navigation_main.content h2, #navigation_main.content ul").hide();
	$("#navigation_main.content").css({ width: "122px", height: "42px" });
	

});
