﻿jQuery(document).ready(function ($) {
  function megaHoverOver() {
    $(this).addClass('mmItemHover').find(".megaborder").stop().show(); //Find sub and fade it in
    (function ($) {
        jQuery.fn.calcMaxDimensions = function () {maxWidth = 0;maxHeight = 0;numColumns = 0;maxColumns = 3; 
       $(this).find("li.category").each(function () {numColumns++;maxWidth = ($(this).width() > maxWidth) ? $(this).width() : maxWidth;});
		maxWidth = (numColumns > maxColumns) ? (maxWidth * maxColumns) : (maxWidth * numColumns);
		$(this).find("li.category").each(function () { maxHeight = ($(this).height() > maxHeight) ? $(this).height() : maxHeight;});
      };
    })(jQuery);

	$(this).calcMaxDimensions(); 
	$(this).find(".megaborder").css({ 'width': maxWidth + 20 }); 
	$(this).find("li.category").each(function() {var thisPosition = $(this).index() + 1;if (thisPosition % 3 == 0) {$(this).addClass("mmRightColumn");}}).css({ 'height': maxHeight });}
  function megaHoverOut() {$(this).removeClass('mmItemHover').find(".megaborder").stop().fadeOut('fast', function () {$(this).hide();});}

  //Set custom configurations
  var config = {
    sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
    interval: 100, // number = milliseconds for onMouseOver polling interval
    over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
    timeout: 500, // number = milliseconds delay before onMouseOut
    out: megaHoverOut // function = onMouseOut callback (REQUIRED)
  };

  //$("ul.itramega li .megaborder").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
$("ul.itramega li.mmHasChild").hoverIntent(config); //Trigger Hover intent with custom configurations
  //Code goes here
});
