/*********************
//* jQuery Multi Level CSS Menu #2- By Dynamic Drive: http://www.dynamicdrive.com/
//* Last update: Nov 7th, 08': Limit # of queued animations to minmize animation stuttering
//* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
*********************/

//Update: April 12th, 10: Fixed compat issue with jquery 1.4x

//Specify full URL to down and right arrow images (23 is padding-right to add to top level LIs with drop downs):
var timeOut = false;
var timeOut01 = false;
var timeOut02 = false;

var arrowimages={down:['downarrowclass', 'down.gif'], right:['rightarrowclass', 'right.gif']}

var jqueryslidemenu={

animateduration: {over: 100, out: 100}, //duration of slide in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})

			$curobj.hover(
				function(e){
					timeOut = setTimeout(mask_on,"300");
					clearTimeout(timeOut02);
					var $targetul=$(this).children("ul:eq(0)")

					var curr = this;
					timeOut01 = setTimeout(function(){
						$curobj.addClass("active");

						curr._offsets={left:$(curr).offset().left, top:$(curr).offset().top}
						var menuleft=curr.istopheader? 0 : curr._dimensions.w
						menuleft=(curr._offsets.left+menuleft+curr._dimensions.subulw>$(window).width())? (curr.istopheader? -curr._dimensions.subulw+curr._dimensions.w : -curr._dimensions.w) : menuleft
						if ($targetul.queue().length<=1) //if 1 or less queued animations
							//$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).slideDown(jqueryslidemenu.animateduration.over)
							//$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).show();
							//$targetul.css({width:this._dimensions.subulw+'px'}).show();
							$targetul.css({width:curr._dimensions.subulw+'px'}).fadeIn(200);
					},300);
				},
				function(e){
					clearTimeout(timeOut);
					timeOut02 = setTimeout(mask_delay, "1");
					//mask_off();

					var $targetul=$(this).children("ul:eq(0)")

					clearTimeout(timeOut01);
					$curobj.removeClass("active");
					//$targetul.slideUp(jqueryslidemenu.animateduration.out)

					//$targetul.hide();
					$targetul.css({width:this._dimensions.subulw+'px'}).fadeOut(200);
				}
			) //end hover
			/*
			$curobj.click(function(){
				$(this).children("ul:eq(0)").hide()
			})
			*/
		}) //end $headers.each()

		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="myslidemenu" on page:
jqueryslidemenu.buildmenu("myslidemenu", arrowimages)


function mask_on(){
	$(".styledSelect").css({'z-index':'1'});
	if($(".lypop_box05")){
		$(".lypop_box05").css({'z-index':'1'});
	}

	$(".sliderkit").css({'z-index':'1'})
	var maskHeight = $(document).height() - 132;
	var maskWidth = $(window).width();

	$('#mask').fadeTo("fast",0.4);
	$('#mask').fadeIn(100);
	$('#mask').css({'width':maskWidth,'height':maskHeight,'margin-top':'132px'});

//	$("#myslidemenu").append($(".gnb").clone());
}

function mask_off(){
	$('#mask').fadeOut(100);
	$(".styledSelect").css({'z-index':'15'});
	if($(".lypop_box05")){
		$(".lypop_box05").css({'z-index':'15'});
	}
	//$(".sliderkit").css({'z-index':'5'})
	if($('form#firstExample08 select')){
		$('form#firstExample08 .styledSelect:eq(0)').css({'z-index':'25'});
		$('form#firstExample08 .styledSelect:eq(1)').css({'z-index':'20'});
		$('form#firstExample08 .styledSelect:eq(2)').css({'z-index':'15'});
	}
/*
	if(!timeOut){
	}else{
		$('#mask').fadeOut(100);
	}
*/
}

function mask_delay(){
	mask_off();
}	
