// desktop version sliding menus

//enable menu animation if the screen is set to desktop
function enableMenus() {
	//create shortcut for nav element
	var menu = $('#nav');
	//check to see if we are on desktop .vs tablet or mobile
	if ($(document).width() > 768) {
	//strip out no-js class if jQuery is running the animation
	if($('body').hasClass('no-js')){
	$('body').removeClass('no-js');
	};
	//attach a listener to each li that has a child ul, and then slide submenus down or up depending upon mouse position
	
	menu.find('li').each(function() {
		if($(this).find('ul').length > 0) {
			//unbind any existing events to prevent multiple handlers if document is resized
			$(this).unbind();
			//create handlers to control the menu animations
			$(this).mouseenter(function(e) {
                $(this).find('ul').stop(true,true).slideDown('fast');  //fast or slow
            });
			$(this).mouseleave(function(e) {
                $(this).find('ul').stop(true,true).slideUp('slow');
            });
		};
	});
	//if screen is smaller, strip out an events and ensure proper class assignment
	} else {
		menu.find('li').each(function() {
         if ($(this).find('ul').length > 0 ) {
         // strip any existing events
         $(this).unbind();
               };
                   });
		//add no-js class to disable menus if has been previously removed
		if($('body').hasClass('no-js')==
		false){
	$('body').addClass('no-js');
	};
	};
};
//since menus are turned off at smaller screen sizes, check for resize in order to disable or enable based on window size
$(window).resize(function() {
 	enableMenus();
});
