/*$(document).ready(function(){

    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

    $("ul.topnav li a").hover(function() { //When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).next("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
        
        $(this).parent().hover(function() {
            $('ul.topnav').data('third', true);                            
        }, function(){
            if(!($('ul.topnav').data('third'))){
                $(this).parent().find('ul.subnav').slideUp('fast');
            } else { 
                $('ul li#m-pri-6 ul.subnav').slideUp('fast');    
                
            }
        });

        //Following events are applied to the trigger (Hover events for the trigger)
        }).hover(function() {
            $(this).addClass("subhover"); //On hover over, add class "subhover"
        }, function(){    //On Hover Out
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });

});
*/
$(document).ready(function(){


				
				
	$('div#wrapper-out').data('third', 0);
	
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li a#menu-1, ul.topnav li a#menu-14, ul.topnav li a#menu-18, ul.topnav li a#menu-21").hover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		if($('div#wrapper-out').data('third') == 1){
			$('ul.topnav li#m-pri-4').find('ul.subnav').slideUp('fast');
			$('div#wrapper-out').data('third', 0);
		}
		
		$(this).next("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		
		$(this).parent().hover(function() {									
		}, function(){
			 $(this).parent().find('ul.subnav').slideUp('fast');
		});	


	});


	byebye = function (){
		$('ul.topnav li#m-pri-4').find('ul.subnav').slideUp('fast');
		$('div#wrapper-out').data('third', 0);
	}
	
	$("ul.topnav li a#menu-4").hover(function(){
		
	
		$(this).next("ul.subnav").slideDown('fast').show();

		
		$(this).parent().hover(function() {	
			
		}, function(){
			if($('div#wrapper-out').data('third') == 0){
				$(this).parent().find('ul.subnav').slideUp('fast');
			} else { 
				menuInterval = window.setTimeout("byebye()", 6000);

			}
		})		
	
	});
	

	$("a#menu-6").hover(
		function(){ 
				$('div#wrapper-out').data('third', 1);
				
				$(this).next("ul.subnav").slideDown('fast').show();
				
				$(this).parent().hover(
				
					function(){}, function(){ 
					
					
					$('div#wrapper-out').data('third', 1);
					} 
					
					
					
				);
		}
		);
		
	/*
	$("ul.topnav li ul.subnav a").hover(function(){
		if($(this).parent().attr('id') == 'm-pri-6'){
			$(this).parent().hover(function(){ $(this).parent().find('ul.subnav').stop();}, function(){ $(this).parent().find('ul.subnav').stop(); });
			
			
		}
		
	});	*/
		

});
/*
$(document).ready(function(){

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li a").hover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).next("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		
		$(this).parent().hover(function() {
									
		}, function(){
			 $(this).parent().find('ul.subnav').slideUp('fast');
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});
*/

