﻿//# jQuery - DNNGo Mega Menu
//# Version 01.00.00
//#
//# http://www.dnngo.net
//#
//# Joshua
//#
//# Copyright 2008-2011

(function($) {	
	$.fn.DNNGoMegaMenu=function(options){
	
		var settings=$.extend({
			divWidth:500,
			animation: "fade",
			fadeInSpeed:200,
			fadeOutSpeed:200,
			slideDownSpeed:300		
		},options||{});
		
		var animation=settings.animation;		
		var isworking=false;
		$(">li.menu-item",this).each(function(i){
			//Add Hover Event
		    $(this).hover(function(){	
		        if($(">div.dropdown",$(this)).html()!=null)
		        {
		            switch(animation)
		            {
		                case "none":
		                {
		                    $(".dropdown",$(this)).css("display","block");
		                    break;
		                }
		                case "fade":
		                {
		                    if(!isworking)
		                    {
		                        isworking=true;
		                        $(">div.dropdown",$(this)).fadeIn(settings.fadeInSpeed,function(){
		                            isworking=false;		                    
		                        });
		                    }
		                    break;
		                }
		                case "slide":
		                {
		                    if(!isworking)
		                    {
		                        isworking=true;
		                        $(">div.dropdown",$(this)).slideDown(settings.slideDownSpeed,function(){
		                            isworking=false;		                    
		                        });
		                    }		            
		                    break;
		                }		    		   
		            }		 
		        }       
		    },
		    function(){
		    	if($(">div.dropdown",$(this)).html()!=null)
		        {
		            switch(animation)
		            {
		                case "none":
		                {
		                    $(">div.dropdown",$(this)).css("display","none");
		                    break;
		                }
		                case "fade":
		                {
		                    $(">div.dropdown",$(this)).fadeOut(settings.fadeOutSpeed);
		                    break;
		                }
		                case "slide":
		                {
		               	    $(">div.dropdown",$(this)).css("display","none");
		                    break;
		                }		    		   
		            }		
		        }	    
		    });
		    
		    //Add hover class
		    $(">div.dropdown",$(this)).hover(function(){
		        $(this).parent().addClass("item-hover");
		    },
		    function(){
		        $(this).parent().removeClass("item-hover");
		    });
		    
		    //Fixed width
		    $(">div.dropdown",$(this)).css({"width":settings.divWidth});	  
		    
		    //Animation  
		});			
	};
})(jQuery);
