﻿// JavaScript Document
// This script configures the dropdown nav menus. Set the megaConfig variables to 
// configure menu open and close timing (ms), as well as mouse sensitivity behaviour.

$(document).ready(function() {

	function addMega(){
		$(this).addClass("hovering");
		keepMenuLeft();
	}
	
	function removeMega(){
		$(this).removeClass("hovering");
		removeKeepMenuLeft();
	}
	
	// sensitivity is how much mouse movement required before considered an actual mouse move
	// by the menus system. 
	var megaConfig = {
		interval: 200,
		sensitivity: 4,
		over: addMega,
		timeout: 400,
		out: removeMega
	};
	
	$("li.SNH_Header").hoverIntent(megaConfig)

    // These two functions keep the divs from going off the right side of the screen
    function removeKeepMenuLeft(){
        //clear inline styles for next hover new position
        $('.SNH_Header').each(function(idx,el){
            el.style.left='';
          });
        $('.SNH_Header').each(function(idx,el){
            el.style.position='';
          });
    }
    function keepMenuLeft(){
        var div_width = $("li.hovering div.SNH_Menu").width();
	   var screen_width = $(window).width();
        var offset = $("li.hovering div.SNH_Menu").offset();
        var left = 0;
		if ( (offset) && (div_width) ) // check that offset and div_width is not null
			if (offset.left + div_width > screen_width) {
				left = (offset.left + div_width) - screen_width;
				left = 0 -left - 30; //extra 30 (px) account for padding and margins
				left = left + "px";        
				$("li.hovering div.SNH_Menu").css('left',left);
			   //  $("li.hovering div.SNH_Header").css('position','relative');
			}     
    }
   /* $("li.mega").hoverIntent(megaConfig)*/
    
    });

