
$(document).ready(function(){
    $("#navcontainer a").click(function (){
        var lnkTitle = $(this).attr("title");
        pageTracker._trackPageview("/NavigationLinks/" + lnkTitle);
    });
    
    $("#navcontainer div.rootnav").mouseenter(function(){//over

        var catData = $(this).children("a:first").attr("rel").split(",");
        
        $(this).children("a:first").css("color", "#FC6E02");
        $(this).children("a:first").children("img:first").attr("src", catData[1]);
        
        $(this).children("ul:first").css("left", "-22px");  
        $(this).css("z-index", 1000);                       

        $(this).children("ul:first").show();              
        
    });
        
        
        
    $("#navcontainer div.rootnav").mouseleave(function(){ //out

        var catData = $(this).children("a:first").attr("rel").split(",");
                
        $(this).children("a:first").css("color", "#4C90D1");
        $(this).children("a:first").children("img:first").attr("src", catData[0]);      
        $(this).css("z-index", 0); 
        $(this).children("ul").hide();//("normal", function(){return false;});
            
    });
        
    $("#navcontainer .rootnav ul li.l").mouseenter(function(){ //out

        $(this).children("a:first").css("color", "#FC6E02");

        var catData = $(this).children("a:first").attr("rel").split(",");
        
        if(catData[1].length>0)
        {
            $(this).children("a:first").css("background", "url('" + catData[1] + "') no-repeat");
        }
             
                
        if($(this).parent().offset().left-136 < 0)
        {
           $(this).children("ul:first").css("left", "+136px"); 
        }
        else
        {
            $(this).children("ul:first").css("left", "-136px");
        }
        
        var menuBottomOffset = $(this).offset().top + $(this).children("ul:first").height();
        if(menuBottomOffset > $(window).height())
        {        
            $(this).children("ul:first").css("top",  ($(window).height()-menuBottomOffset) + "px");
        }
        else
        {
            $(this).children("ul:first").css("top", "0px");
        }
        
        $(this).children("ul:first").show();
            
    }); 
    
    $("#navcontainer .rootnav ul li.l").mouseleave(function(){ //out
    
        $(this).children("a:first").css("color", "#4C90D1");

        var catData = $(this).children("a:first").attr("rel").split(",");
        
        if(catData[0].length>0)
        {
            $(this).children("a:first").css("background", "url('" + catData[0] + "') no-repeat");
        }            
        
        $(this).children("ul:first").hide();
            
    });              
                      
});

