
 var Main =
 {
 	init : function ()
 	{
 		this.setNoticeTab();
 		this.setLoginBox();
 		this.setPromotion();
 	},
 	
 	reloadLoginBox : function ()
 	{
 		
 		var F = function ()
 		{
 			var Html = ($("#LoginMark").find(".logout").length) ? '<a href="/Login">Login</a>' : '<a href="/" class="logout">Logout</a>';
			$("#LoginMark").html(Html);
									
 			Main.setLoginBox();
 		};
 		
 		$("#loginBox").setDocument('/loginBox.php', { onComplete : F });
 	},
 	
 	setLoginBox : function ()
 	{
 		$("#mainLogin").submit ( function ()
		{
			var id = $(this).find("[name='M_ID']").val();
			var pw = $(this).find("[name='M_PW']:first").val();
			
			if(id == '' || id == '아이디')
			{
				alert('아이디를 입력해 주세요');
				$(this).find("[name='M_ID']").focus();
				return false;
			}
			
			if(pw == '' || pw == '비밀번호' )
			{
				alert('비밀번호를 입력해 주세요');
				$(this).find("[name='M_PW_FAKE']").focus();
				return false;
			}
			
 			$(this).send( function (Result) 
 			{
				if(Result == 'OK')  Main.reloadLoginBox();
				else
				alert(Result);
				
			});
			
			return false;		
 		});
 		
 		$("#mainLogin").find("[name='M_ID']").focus( function () 
 		{ 
 			if($(this).val() == '아이디') $(this).val(''); 
 			
 		});
 		
 		$("#mainLogin").find("[name='M_PW_FAKE']").focus( function () 
 		{ 
 			$(this).hide();	
 			$("#mainLogin").find("[name='M_PW']:first").show();
 			$("#mainLogin").find("[name='M_PW']:first").val('').focus();
 		});
 		
 		Menu.loginBoxSet();
 		
 	},
 	
 	setNoticeTab : function ()
 	{
 		$(".mainBoard_tab").find('p.more').find('a:first').each( function () 
 		{   
				$(this).attr('href', $(this).parents('.mainBoard_tab:first').find("a[num]").attr('href'));
		});
 		
 		$(".mainBoard_tab").find("a[num]").css( 'cursor','pointer' );
 		
 		
 		$(".mainBoard_tab").find("a[num]").click( function () 
 		{          
 			
 			$(this).parents(".mainBoard_tab:first").find('p.more').find('a:first').attr('href', $(this).attr('href'));
 			
 			$(this).parents(".mainNotic:first").find(".mainBoard_tab").find("a[num]").each( function () 
 			{       
 				$(this).attr('class', $(this).attr('class').replace(/_on/g, ''));
 			
 			});
 			
 			
 			
 			var Cn = $(this).attr('class');
 			$(this).attr('class', Cn+'_on');
 			
 			$(this).parents(".mainNotic:first").find(".tabData").find("ul").hide();
 			$(this).parents(".mainNotic:first").find(".tabData").find("ul:eq("+($(this).attr('num')-1)+")").show();
 			
 			
 			//alert($(this).attr('class'));
 			return false;
 		});
 	},
 	action:setTimeout(";",0),
 	isBannerPlay:true,
 	bannerCount:0,
 	bannerIdx:1,
 	setPromotion : function()
 	{
 		$('.backLink a').attr("href",$('#promotionLayer a').eq(0).attr("href"));
 		this.action = setTimeout("Main.bannerRoll(1)",6000);
 		
 		this.bannerCount = $('#promotionLayer a').length;
 		$('.proNum').click(function()
 		{
 			var idx = $('.proNum').index(this);
 			Main.bannerRoll(idx);
 			return false;
 		});

 		$('#bannerPlay').click(function()
 		{
 			if(Main.isBannerPlay)
 				return false;
 			
 			Main.isBannerPlay=true;
 			Main.bannerRoll(Main.bannerIdx);
 			return false;
 		});

 		$('#bannerStop').click(function()
 		{
 			Main.isBannerPlay=false;
 			return false;
 		});
 	
 	},
 	
 	bannerRoll : function(idx)
 	{
 		clearTimeout(this.action);
 		if(!Main.isBannerPlay)
 			return false; 

 		$('.backLink a').attr("href",$('#promotionLayer a').eq(idx).attr("href"));
 		speed = (idx==0)?900:700;
 		$('#promotionLayer').animate({left:-(idx*231)-(idx*4)},speed);
 		
 		idx = ((++idx) > (this.bannerCount -1))?0:idx;
 		this.action = setTimeout("Main.bannerRoll(" + (idx) + ")",5000);
 		Main.bannerIdx = idx;
 	}
 };
 
$().ready( function () { 
	Main.init();
});
