/*
* Fishsaucesoup.com
* John Wilson
* 2011
*
* menu.js
*/

var parent_offset,child_offset,width;
var url;
var subMenuClicked=false;


// On Document Load
$(document).ready(function() 
{   
  $.ajaxSetup({cache:false});
	
	$(".mainMenuItem").click(function(){

       // Remove mainMenuSelected class from all menu items
       $(this).siblings("td").removeClass("mainMenuItemSelected");
			 
			 // Add mainMenuSelected class to selected menu item
			 $(this).addClass("mainMenuItemSelected");
			 
			 if(subMenuClicked)
			 {
				 subMenuClicked=false;
			 }
			 else
			 {																					
			   url=$(this).attr("title");				 				 				 
				 GetContent(url);				 				
			 }
			 
     });
 
 
  $(".mainMenuItem").mouseenter(function(){	
			var width;
			
			// Show submenu
			$(this).children(".subMenu").css("display","block");
			 
			// Align submenu display
			parent_offset=$(this).offset();
			child_offset=$(this).children(".subMenu").offset();
			 
			child_offset.left=parent_offset.left;
			$(this).children(".subMenu").offset(child_offset);
				 
     });

  $(".subMenuItem").click(function(){
			subMenuClicked=true;

      url=$(this).attr("title");
			GetContent(url);
     });

  $(".mainMenuItem").mouseleave(function(){			       
			// Hide submenu
      $(this).children(".subMenu").css("display","none");
     });


  $(".subMenuItem").mouseenter(function(){

      // Get background and text color parent menu
      bc=$(this).parent(".subMenu").css("background-color");
			c=$(this).parent(".subMenu").css("color");			
      
			// Set background and text color of submenu item
			$(this).css("color",bc);
			$(this).css("background-color",c);

      // Get width of current submenu
			width=$(this).parents(".subMenu").width();	

      // Display any submenus of the current submenu item
      $(this).children(".subMenu").css("display","block");
			 
			// Figure out correct offset for submenu items of this submenu item.
			parent_offset=$(this).offset();
			width=$(this).width();
	    child_offset=$(this).children(".subMenu").offset();
				 
      child_offset.left=parent_offset.left+width;
			child_offset.top=parent_offset.top-5;
	    $(this).children(".subMenu").offset(child_offset);
			 
     });

  $(".subMenuItem").mouseleave(function(){			 
			 bc=$(this).parent(".subMenu").css("background-color");
			 c=$(this).parent(".subMenu").css("color");			
       $(this).css("color",c);
			 $(this).css("background-color",bc);			 
			 $(this).children(".subMenu").css("display","none");
     });

   // Load Current Tab
   url=$(".mainMenuItemSelected").attr("title");	 	 
	 GetContent(url);

});



