﻿$(document).ready(function()
{        
       //Set variables       
       var menu;         // ID of menu open
       var timer = 100;	// ID of timeout set

       $("div[id=ddmenu] > a").hover(                    
            function()
            {   
                // Clear any opened menu(s)
                closemenu();
                
                //reset the timer; otherwise hovering off the parent
                //link 2nd time won't call the closemenu() as desired.  Becuase,
                //during the 1st trip the timer got set a big value                  
                timer = 100;
                
                //show the corresponding dropdowns                
                $(this).siblings('div').show().bgiframe();
                                
                
                $(this).siblings('div').hover(
                    function() //intercept, and clear the timer to stop hiding the dropdown links
                    {   clearTimeout(timer);
                    },
                    function() //hide the dropdown links
                    {  menu = $("div[id=ddmenu] > a");
                       closemenu();                                               
                    }
                 );
            },
            function()
            {   
                menu = this;   
                
                //variable timer will be set to a big value than default 100             
                timer = setTimeout(function(){closemenu()}, timer);  
            }
         );
         
        var closemenu = function(){
		    if (menu && timer)		    
		    {  
			   	$(menu).siblings('div').hide();
			    clearTimeout(timer);
			    menu = '';
		    }
	    }  
});


// Before showing sibling div's first child div
//$(document).ready(function()
//{        
//       //Set variables       
//       var menu;         // ID of menu open
//       var timer = 100;	// ID of timeout set

//       $("div[id=ddmenu] > a").hover(                    
//            function()
//            {   
//                // Clear any opened menu(s)
//                closemenu();
//                
//                //reset the timer; otherwise hovering off the parent
//                //link 2nd time won't call the closemenu() as desired.  Becuase,
//                //during the 1st trip the timer got set a big value                  
//                timer = 100;
//                
//                //show the corresponding dropdowns                
//                $(this).siblings('div').show().bgiframe();
//                                
//                
//                $(this).siblings('div').hover(
//                    function() //intercept, and clear the timer to stop hiding the dropdown links
//                    {   clearTimeout(timer);
//                    },
//                    function() //hide the dropdown links
//                    {  menu = $("div[id=ddmenu] > a");
//                       closemenu();                                               
//                    }
//                 );
//            },
//            function()
//            {   
//                menu = this;   
//                
//                //variable timer will be set to a big value than default 100             
//                timer = setTimeout(function(){closemenu()}, timer);  
//            }
//         );
//         
//        var closemenu = function(){
//		    if (menu && timer)		    
//		    {  
//			   	$(menu).siblings('div').hide();
//			    clearTimeout(timer);
//			    menu = '';
//		    }
//	    }  
//});