// this is a fix for the jQuery slide effects
function slideToggle(el, bShow){
  var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
  
  // if the bShow isn't present, get the current visibility and reverse it
  if( arguments.length == 1 ) bShow = !visible;
  
  // if the current visiblilty is the same as the requested state, cancel
  if( bShow == visible ) return false;
  
  // get the original height
  if( !height ){
    // get original height
    height = $el.show().height();
    // update the height
    $el.data("originalHeight", height);
    // if the element was hidden, hide it again
    if( !visible ) $el.hide().css({height: 0});
  }

  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
  if( bShow ){
    $el.show().animate({height: height}, {duration: 250});
  } else {
    $el.animate({height: 0}, {duration: 250, complete:function (){
        $el.hide();
      }
    });
  }
}


$(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
	var config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 200, // number = milliseconds for onMouseOver polling interval    
     over: function(){//on mouse over
			$(this).addClass("hover");
				if($(this).find("ul.subnav")){//checks to see if li has a sub menu
					$(this).find("span").addClass("subhover");
					var element = $(this).find("ul.subnav");
					slideToggle(element,true);
				}
	 		}, // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: function(){//on mouse leave
			$(this).removeClass("hover");
			var element = $(this).find("ul.subnav");
				slideToggle(element,false);
			$(this).find("span").removeClass("subhover");
			} // function = onMouseOut callback (REQUIRED)    
	};

	$("ul.topnav li").hoverIntent(config);
});
