﻿     
       var imagepath="";
       var random;
           
       $(document).ready(function() {
                RandomVar();
                BrowserVariables();
                CreateMenu(); 
                $(this).click(function(){ExitPopup();});             
                $(window).resize(function(){ExitPopup();});             
                $('#PopupMsg').hover(function(){menuStopSlideUp();},function(){menuSlideUp();});
       });  
       
       function BrowserVariables()
       {            
            if($.browser.mozilla)
            {
                imagepath="../../CMSTemplates/EC/Images/MenuImage/firefox/";
            }
            else
            {
                imagepath="../../CMSTemplates/EC/Images/MenuImage/default/";
            }
       }     
       
       function menuSlideUp()
       {
            $('#PopupMsg').queue( [ ] ).stop(); 
            $('#PopupMsg').slideUp(500);
       }
       
       function menuStopSlideUp()
       {
            $('#PopupMsg').queue( [ ] ).stop(); 
       }
       
        function CreateMenu()
        {
            var htm="";
            htm +="<ul>";        
            $.ajax({            
            type: "GET",
            url: "../../XML/MainNav.aspx?r="+random,
            dataType: "xml",
            error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); },
            success: function (xml) {            
             $(xml).find('item').each(                    
                function(){                 
                    var bn=$(this).attr('name');
                    var id=$(this).attr('id');
                    var lnk=$(this).attr('link');
                    var childCount=$(this).children().size();                    
                    
                    
                    htm +="<li id='"+ id +"'><a class='aNormal' onmouseover='javascript:InvokePopup("+ id +","+ childCount +")' onmouseout='javascript:DisposePopup("+id+")' href='" + lnk +"'>";                     
                    //htm += "<div style='padding-left:15px;padding-right:0;line-height:20px;'>";                    
                   htm += bn ;
                   htm +="&nbsp;&nbsp;<img id='img"+ id +"' src='"+ imagepath +"arrow.jpg' style='vertical-align:middle' border='0' />";                                       
                   htm +="&nbsp;&nbsp;<img src='"+ imagepath +"nav_top_divider.gif' style='vertical-align: middle' border='0' />";                   
                   // htm += "</div>"; 
                    htm +="</a></li>";
                    
                    }); 
                    htm +="</ul>";
                   $('#myjquerymenu').html(htm);    
                    
            }
            });          
            
        }
        
        
          function InvokePopup(id,childnodes)
          {     
                MenuRollOver(id);
                var menuheight=childnodes * 25;
               
                $('#PopupMsg').queue( [ ] ).stop(); 
                $('#PopupMsg').css({"display": 'none',"height": '0'});

                var x=$('#PopupMsg').height();
                var t=$('#'+ id).offset().top + 25;
                var l=$('#'+ id).offset().left;          
                if(x>1){ 
                    $('#PopupMsg').css({"visibility": 'hidden',"height": '0'});
                 } 
                 
                 $('#PopupMsg').css({ "visibility": 'visible',display: 'block', "top": t, "left": l,"position":'absolute' });
                 $('#PopupMsg').animate({ height: menuheight }, {queue:false, duration:"normal"} );
                 CreateSubMenu(id);
                 
         }
         
        function DisposePopup(id)
        {              
           MenuRollBack(id); 
                   
        }
        
        function MenuRollBack(id)
        {
           var imgID="#img"+id;
           $(imgID).attr("src",""+ imagepath +"arrow.jpg");
           $('#'+id + ' a').removeClass("aHover");           
           $('#'+id + ' a').addClass("aNormal");
          
           menuSlideUp(); //slides submenu
        }
        
        function MenuRollOver(id)
        {
            var imgID="#img"+id;
            $(imgID).attr("src",""+ imagepath +"arrow_over.gif"); 
            $('#'+id + ' a').removeClass("aNormal");         
            $('#'+id + ' a').addClass("aHover");
            
        }

        function CreateSubMenu(nodeid)
        {
            submenuHeight=0;
            
            var htm="<table id='tbl' border='0' cellspacing='0' cellpadding='0'>";                   
            $.ajax({            
            type: "GET",
            url: "../../XML/MainNav.aspx?r="+random,
            dataType: "xml",
            error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); },
            success: function (xml) {            
             $(xml).find('item').each(                    
                function(){                 
                    var id=$(this).attr('id');                    
                    if(nodeid==id)
                    {                    
                        $(this).find('subitem').each(function(){
                            var title=$(this).attr('name');
                            var lnk =$(this).attr('link');
                            htm +="<tr>";
                            htm +="<td style='background-color:#FFFF99'><a href='"+ lnk +"'  >"+ title +"</a></td>";
                            htm +="</tr>"; 
                            
                            submenuHeight=submenuHeight + 25;                       
                        });                        
                        htm +="</table>";
                        $('#PopupMsg').html(htm);  
                       
                       }                 
                    });  
            }
            });   
        }
        
        function ExitPopup()
        {
            $('#PopupMsg').css({"display": 'none',"height": '0'});
        }
        
        function RandomVar()
        {
            var d = new Date();
            random=d.getTime() ;
        }
       
    
        function LeftNavChangeImage(id,ev,act)
        {
            var imgID="#"+id;  
            
            if(ev=="over")
            {                              
                $(imgID).attr("src","../../../CMSTemplates/EC/Images/MenuImage/default/login_icon_over.gif");          

            }
            else
            {                
                $(imgID).attr("src","../../../CMSTemplates/EC/Images/MenuImage/default/login_icon.gif");  
            }
            
            if(act=="t")
            {
                $(imgID).attr("src","../../../CMSTemplates/EC/Images/MenuImage/default/login_icon_over.gif"); 
            }
        }

