$(function(){

	//* for  pulldown target classname *//
	var pulldown = "kfPullDownMenu";

	//* for  pulldown type 0=Normal,1=Slider,2=Fade *//
	var pulldowntype = 0;

	//* for  effect time(*ms) *//
	var effectTime = 200;

	//* for  mouseout time(*ms) *//
	var delay = 500;

	//* for  stayClass *//
	var stayClass = "here";

	//* getBodyId *//
	var bodyId = $("body").attr("class");


	// pulldown ///////////////////////////////////////////////////////////////////////////
	var timestop = false;
	var timer;

	$("." + pulldown + " ul li ul").css("position","absolute");
	
	if(pulldowntype == 1){
		$("." + pulldown + " ul li ul").css("height",0);
	};
	if(pulldowntype == 0 || pulldowntype == 2){
		$("." + pulldown + " ul li ul").css("display","none");
	};

	$("." + pulldown).find('ul:first-child > li').each(function(){
		
		var myId = $(this).attr("id");
		if(bodyId==myId){
			$(this).addClass(stayClass);
		}
		
		//
		this.style.position ="relative";
		if(pulldowntype == 0){
		
		}else if(pulldowntype == 1){
			this.style.overflow ="hidden";
		}else if(pulldowntype == 2){
		}
		//
		
		$(this).hover(function(){
			var myClass = $(this).attr("class");
			if(myClass == "kf_overFirst"){
				$(this).removeClass('kf_overFirst');
			}
			clear();
			timestop = true;
			clearTimeout(timer);
			var secondHeight = $(this).find("ul.kfsecond li").length;
			var myHeight = $(this).innerHeight();
			$(this).find("ul").css("top",myHeight + "px");
			var myClass = $(this).attr("class");
			
			$(this).css("overflow","visible");
			
			if(pulldowntype == 0){
				$(this).find("ul").css("display","block");
			};
			
			if(pulldowntype == 1){
				$(this).find("ul").css("height",0);
				if(myClass != "kf_overFirst"){
					$(this).find("ul").animate({height:myHeight*secondHeight + "px"},effectTime);
					$(this).addClass('kf_overFirst');
				}else{
					$(this).find("ul").css("height",myHeight*secondHeight + "px");
				}
			};
			
			if(pulldowntype == 2){
				if(myClass != "kf_overFirst"){
					$(this).find("ul").css({'opacity':0,'display':'block'});
					$(this).find("ul").animate({'opacity':1},effectTime,'linear');
					$(this).addClass('kf_overFirst');
				}else{
					$(this).find("ul").css({'opacity':1,'display':'block'});
				}
			};
			
			$(this).addClass('kf_over');
		},function(){
			rolloverEnd();
		});
		
	});
	 
	function rolloverEnd(){
		if(!timestop) return;
		timestop = false;
		
		timer = setTimeout(function(){
			clearTimeout(timer);
			clear();
		}, delay);
	};
	
	function clear(){
		
		if(pulldowntype == 0){
			$("li.kf_over").css("overflow","hidden");
		};
		
		if(pulldowntype == 1){
			$("li.kf_over ul").css("height",0);
			$("li.kf_over").css("overflow","hidden");
		};
		//alert(pulldowntype);
		if(pulldowntype == 2){
		//	$("li.kf_over ul").stop();
			$("li.kf_over ul").css({"opacity":0,"display":"none"});
		};

		$("li.kf_over").removeClass('kf_over');
	}
	
});
/////////////////////////////////////////////////////////////////////////////

