﻿/*
 * jQuery dashengMenu plug-in
 * http://www.dasheng.com/
 *
 * Copyright (c) 2009-2012
 * Author: Dasheng
 *
 * Date: 2009-12-07 (Mon, 07 Dec 2009)
 * Revision: 0.01
 */
(function($){
	$.fn.dashengMenu=function(setting){
		return this.each(function(){
			
			//分析参数并设定默认值
			var way	=	"fade";		//显示方式:show|fade|slide|animate 默认值:fade
			var speed=	"normal";	//显示速度:"fast"|"nomarl"|"slow"|(毫秒数) 默认值:"nomarl"
			var alpha=	1;			//透明度:(0-1的小数) 默认值:1
			var delay	=500;		//操作延时:(毫秒) 默认值:500
			
			if(!(typeof(setting)=="undefined")){
				if(!(typeof(setting.way)=="undefined")) way=setting.way;
				if(!(typeof(setting.speed)=="undefined")) speed=setting.speed;
				if(!(typeof(setting.alpha)=="undefined")) alpha=setting.alpha;
				if(!(typeof(setting.delay)=="undefined")) delay=setting.delay;
			}
			
			var $this=$(this);
			var menuItem=$(this).find("li");
			menuItem.each(function(){
				//获取菜单内容DIV
				var menuCont=$(this).children("div");
				if(menuCont.length<=0) menuCont.append("<div></div>");;
				
				//设定样式
				menuCont.css("left",$this.offset().left);
				menuCont.css("top",$(this).offset().top+$(this).height());
				menuCont.animate({opacity:alpha},0)
				
				//鼠标悬停
				var timeoutID=null;//延时
				$(this).hover(function(){
					if(!$(this).is("animated")){
						timeoutID=setTimeout(showEffect,delay);
						$(this).attr("class","menu_li_on");
					}
				},function(){
					hideEffect();
					clearTimeout(timeoutID);
					$(this).attr("class","menu_li");
				});
				
				//切换效果--显示
				var h=menuCont.height();
				function showEffect(){
					switch(way){
						case "show"://普通显示
							menuCont.show(speed);
							break;
						case "fade"://淡入淡出
							menuCont.fadeIn(speed);
							break;
						case "slide"://卷帘效果
							menuCont.slideDown();
							break;
						case "animate"://动画效果
							menuCont.animate({height:0,opacity:0},0);
							menuCont.animate({height:h,opacity:alpha},speed);
							break;
					}
				}
				//切换效果--隐藏
				function hideEffect(){
					switch(way){
						case "show"://普通显示
							menuCont.hide(speed);
							break;
						case "fade"://淡入淡出
							menuCont.fadeOut(speed);
							break;
						case "slide"://卷帘效果
							menuCont.slideUp();
							break;
						case "animate"://动画效果
							menuCont.animate({height:0,opacity:0},speed);
							break;
					}
				}

			});
		});
	}
})(jQuery);