﻿// Master Page Functions

$(document).ready( SetupMasterEffects );

var mainMenuState = 0;

function SetupMasterEffects(){

    $("#explorecontainer")
    .hover
    (
        function() { ExploreRollover(); }
        ,function() { return false; }
    )
    
    $("#mainmenu")
    .hover
    (
         function() { mainMenuState = 1; }
        ,function() { HideMenu(); }
    )
    
//    $("#mapcontainer")
//    .mouseover
//    (
//        function() { PlayFindAUnitSound(); }
//    );
            
    $("#flyingsubmenucontrol")
    .hover
    (
         function() { ShowSubMenu(); }
        ,function() { return false; }
    )
    
    $("#flyingsubmenu")
    .hover
    (
         function() { return false; }
        ,function() { HideSubMenu(); }
    )
   
   $("#mapcontainer img")
   .hover
   (
        function(){
            var img = webRoot + "/images/_assets/unitSelectorMap.gif";
            $(this).attr("src", img);
            PlayFindAUnitSound();
        }
        ,
        function(){ 
            var img = webRoot + "/images/_assets/unitSelectorMapStill.gif";
            $(this).attr("src", img);
        }
   )
    
}//SetupEffects


function ExploreRollover(){
    
    mainMenuState = 1; 
    ShowMenu();
    $.sound.play(menuSound, { timeout:2000 } );
}


function PlayFindAUnitSound(){
    $.sound.play(findAUnitSound, {timeout:2000});	
}


function ShowMenu(){
    $("#mainmenu").fadeIn("slow");
}


function HideMenu(){
    
    var subMenuDisplay = $("#flyingsubmenu").css("display");
    if( subMenuDisplay == "none" ){
        $("#mainmenu").fadeOut("slow");
    }
}


function ShowSubMenu() {
    mainMenuState = 2;
    $("#flyingsubmenu").fadeIn( "slow" );
}


function HideSubMenu() {
    $("#flyingsubmenu").fadeOut( "slow" );    
    SetCheckIfMenuShouldCloseTimeOut();
}


function SetCheckIfMenuShouldCloseTimeOut(){
    setTimeout( "CheckIfMenuShouldClose()", 50 );

}


function CheckIfMenuShouldClose(){
    
    if( mainMenuState != 1 ){
        $("#mainmenu").fadeOut( "slow" );
    }
}


function CheckForVisibleRollover(menuObject, obj){

    var containerScrollTop = $(obj).parent().parent().parent().scrollTop();
    var top = menuObject.get(0).offsetTop;
    var diff = top - containerScrollTop;
	//console.log( top + " and " + containerScrollTop + " diff:" + diff);
	if( diff > 150 ){
	   top = top - 60;	    
	   menuObject.css("top", top + "px" );
	}//if							
}//CheckForVisibleRollover

