/**
* nav.js
*
* This file is used to display the active nav bar
*
* Author: Andrew Chan
*/

    var timeout,timeout2;
    window.whiteout=0;

    $(document).ready(function(){
        $("#menu a").focus(function(){$(this).blur();});
        $(".secondMenu,.thirdMenu").css("display","none");
        $(".firstMenu a").each(function(){
            $(this).mouseover(function(){
                    var ts = this;
            	    timeout = setTimeout(function(){overFirstMenu(ts);},250);
            }).mouseout(function(){
		        clearTimeout(timeout);
	        });
        });
        $(".secondMenu a").each(function(){
            $(this).mouseover(function(){
                    var ts = this;
                    timeout2 = setTimeout(function(){overSecondMenu(ts);},300);
	        }).mouseout(function(){
		        clearTimeout(timeout2);
            });
        });
        
/*
           $("#navigation").mouseover(function(event){
           	//alert(event.target.id);
        	if (event.target.tagName.toUpperCase()=="A" && window.whiteout==0){ 
        		setTimeout(beginWhiteout,"50");
        		window.whiteout=1;
        		}
        	else if(event.target.tagName.toUpperCase()!="A"){
        		setTimeout(unWhiteout,"50");
        		window.whiteout=0;
        		}	
        	});
        
          $("#navigation").mouseout(function(event){
        	if (event.target.id=="menu"){
        		setTimeout(unWhiteout,"50");
        		window.whiteout=0;
        		}
        	});
*/
        
    });

function overFirstMenu(ts){
		var tar=$(ts).parent().attr("lang");
                var secondTar="";
                if($(".secondA").length>0){
                    secondTar=$(".secondA").parent().attr("lang");
                }
                $(".secondMenu,.thirdMenu").hide("normal");
                
                if($(ts).attr("class")!="firstA"){
                    $(".firstMenu a").css("color","").removeClass("firstA");
                    $("#menu").children("li[lang='"+tar+"']").show("normal");
                    $(ts).css("color","#3A79B7").addClass("firstA");
                    $(".introMenu").fadeOut();
                    if(secondTar!=""&&secondTar.substring(0,tar.length)==tar){
                        if(secondTar!="1.1.1") $("#menu").children("li[lang='"+secondTar+"']").show("normal");
                        else{ 
                            $(".thirdMenu[lang='1.1.1']").show("normal");
                            $(".thirdMenu[lang='1.1.1'] *").show("normal").fadeIn();
                        }
                    }
                }
                else{
                	 $(".firstMenu a").css("color","").removeClass("firstA");
                	 $(".introMenu").fadeIn();
                		}
};
function overSecondMenu(ts){
                if($(ts).attr("class")!="secondA"){
		    $(".thirdMenu").hide("normal");
                    $(".secondMenu a").css("color","").removeClass("secondA");
                    $(ts).css("color","#3A79B7").addClass("secondA");
                    var tar=$(ts).parent().attr("lang");
                    if(tar!="1.1.1") $("#menu").children("li[lang='"+tar+"']").show("normal");
                    else{ 
                        $(".thirdMenu[lang='1.1.1']").show("normal");
                        $(".thirdMenu[lang='1.1.1'] *").show("normal").fadeIn();
                    }
                }
}


// code here added to make nav/grid interaction behave as GT wanted it
YAHOO.util.Event.addListener('navigation','mouseover',handleNavOver);

// var to hold timeout ref for unWhiteOut();
nav_unwhiteout_timeout = null;
function handleNavOver(e){
	beginWhiteout();
	clearTimeout( nav_unwhiteout_timeout );
	nav_unwhiteout_timeout = setTimeout( unWhiteout, 3000 );
	//alert( 'over nav' );
}

