/*=========================== MegaMenu ===============================*/	

jQuery.fn.megamenu = function (options) {

	var mmActive = 0;

	options = jQuery.extend({ hoverClass: 'mmsel', align: 'left', submenuClass: 'submenuClass' }, options || {});

	jQuery(this).hoverIntent (
		function () {


			if (jQuery(this).parent().hasClass(options.submenuClass)) {
				return;
			}  


			var pos = jQuery(this).children("a:first").offset();	// Get the trigger link position
			var h = jQuery(this).children("a:first").height();	// Get the trigger link's height 
			var w = jQuery(this).width();	// Get the trigger link's width
			var divw = jQuery(this).children("div:first").width();	// Get the trigger link's width

			// Get the x position of the menu div
			var left;
			if (options.align == 'right') {
				left = pos.left + w - divw - 27; 
			} else if (options.align == 'center') {
				left = pos.left + (w-divw)/2;
			} else {
				left = pos.left;
			} 
			left = left - 0;	

			var top = h + (pos.top);		// Calculate the y position

			jQuery(this).children("div:first").css( { 	// Set the div postion through CSS
				position: 'absolute',
				left: left + 'px',
                		top: top + 'px'
			});

			// The following is necessary only for curved border styling
			// jQuery(this).children("div:first").children("div.filler").css('width', jQuery(this).next("div").width()-jQuery(this).width());
			
			jQuery(this).children("div:first").fadeIn("fast"); 		// Use any effect to show the div
			jQuery(this).children("a:first").addClass(options.hoverClass);		// Change style to show tab
		 	

			},	

		function () { 

			if (jQuery(this).parent().hasClass('mmsubmenu')) {
				return;
			}  

			jQuery(this).children("div:first").fadeOut("fast"); 		// Make the div disappear
			jQuery(this).children("a:first").removeClass(options.hoverClass);  // Restore original styling (remove tab)
		}   

        );

}

