$j.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});	
	return this;
};
$j(function(){    
	//Remove outline from links
	$j("a").click(function(){$j(this).blur()});	
	// Common Function
	var clearOthers = function(){
		$j(".dropdownbox","#topContainer").css({display: 'none'});
		$j(".tn_topbg","#topContainer").css({display: 'none'});
		$j(".tn_dropdown","#topContainer").removeClass('tn_onact');	
		$j(".tn_loginbox","#topContainer").removeClass('tn_onact');
		$j(".tx-newloginbox-pi1","#topContainer").css({display: 'none'});
		$j(".tn_dropdown","#topContainer").children("a").removeClass('tn_onact');
		return false;
	};
	//Effect when hover
	//-- Main Items --
	$j(".tier1","#navContainer").hover(
		function(){
			clearOthers();			
			$j("#mask").css({display: 'block'}).stop().animate({opacity: '0.8'},{queue:false, duration:200});			
			$j(this).next("div").stop().animate({opacity: '1', height: '268px'},{queue:false, duration:400, easing: "easeInOutCirc"});			
			return false;
		},
		function(){		
			$j(this).next("div").stop().animate({opacity: 'hide', height: '0'},{queue:false, duration:200, easing: "easeInOutCubic"});
			$j("#mask").stop().animate({opacity: 'hide'},{queue:false, duration:200});
			return false;
		}
	);
	//-- Dropdown Area --
	$j(".divmenu","#navContainer").hover(
		function(){			
			$j(this).prev("a").addClass('selected');
			$j(this).stop().css({opacity: '1', height: '268px'});
			$j("#mask").stop().css({opacity: '0.8'});
			return false;
		},
		function(){
			$j(this).prev("a").removeClass('selected');	
			$j("#mask").stop().animate({opacity: 'hide'},{queue:false, duration:200});
			$j(this).stop().animate({opacity: 'hide'},{queue:false, duration:200});			
			return false;
		}
	);	
	//-- Header Navigation --
	var hn = $j(".tn_dropdown","#topContainer");
	hn.each(function(){
		var ddbox_width = $j(this).parent().width();		
		$j(this).next("ul").addClass("dropdownbox").css({'width': ddbox_width-4});
		$j(this).next("div").addClass("dropdownbox").css({'width': ddbox_width-4});		
	}).click(function(){
		if ($j(this).next(".dropdownbox").is(":hidden")) {
			clearOthers();	
			$j(this).prev(".tn_topbg").css({display: 'block'});
			$j(this).addClass('tn_onact');			
			$j(this).next(".dropdownbox").slideDown('fast');
			return false;
		}
		else {
			$j(this).prev(".tn_topbg").css({display: 'none'});
			$j(this).removeClass('tn_onact');
			$j(this).next(".dropdownbox").slideUp('fast');
			return false;
		}
	});	
	$j("#logout_submit").click(function(){		
		$j("#logout").submit();
		return false;
	});	
	//-- Search Box --	
	var df_searchtext = $j(".bg_search",".tx-macinasearchbox-pi1").attr("value");
	$j(".bg_search",".tx-macinasearchbox-pi1").focus(function(){
		if ($j(this).attr("value") == df_searchtext){
			$j(this).attr("value","")
		};
		return false;
	});
	$j(".bg_search",".tx-macinasearchbox-pi1").blur(function(){
		if ($j(this).attr("value") == ''){
			$j(this).attr("value",df_searchtext)
		};
		return false;
	});
	$j(".btn_search",".tx-macinasearchbox-pi1").hover(
		function(){$j(this).css({cursor: 'pointer'})},
		function(){$j(this).css({cursor: 'default'})}
	);		
	//-- Promotion Pop-up --
	var promobox = $j(".content","#promotion");
	var promomask = $j(".blackmask","#promotion");
	var icoball = $j(".ico_ball","#promotion");	
	var close = $j(".closebtn","#promotion");
	var open = $j(".ico_sforum","#promotion");
	close.click(function(){
		if (close.is(":visible")) {
			close.hide();
			promomask.hide();
			icoball.hide();			
			promobox.stop().animate({width: '0', opacity: '0.8'},{queue:false, duration:100, easing: "easeInOutCirc"});
			open.css({'background-position': '-128px 0'});
		}
		return false;
	});
	open.click(function(){
		if (close.is(":hidden")) {			
			promobox.stop().animate({width: '417px', opacity: '1'},{queue:false, duration:10, easing: "easeInOutCirc"});
			icoball.show();			
			promomask.show();
			close.show();
			open.css({'background-position': '0 0'});
		}
		return false;
	});	
});
//-- Black Mask --
$j(window).bind("load", function() { 
	var mheight = $j(document).height();
	$j("#mask").css({'height': mheight});
	$j("#notify").css({'height': mheight});
	return false;
});