function _init()
{
	var host = Host();
		
	if(host=="www.newitemmania.net" || host=="newitemmania.net")
	{
		initXhr();
	}
	else
	{
		setEvent()
		bnRollingstarter()
//		at_setEvent()
//		at_bnRollingstarter()
//		mz_setEvent()
//		select_zone()
		//itv_setEvent()
		//itv_bnRollingstarter()

		if($("id_saveS"))
		{
			$("id_saveS").onclick = function()
			{
				if($("id_saveS").checked == true)
				{
					alert('로그인 저장 기능을 사용하시겠습니까?\n\n단, 게임방, 학교등 공공장소에서 이용시 개인정보가 유출될수 있으니 주의해주세요.');
				}
			}
		}
		popupManager();
	}

	var frm		= $("frmLogin");

	/* ▼ 로그인 check */
	if(frm)
	{
		if(!$("user_id").value.isEmpty()){
			fnLoginText("loff");
		}
		
		checker = new _form.checker(frm);
		checker.add({custom:function() {
			if(frm.user_id.value.isEmpty()){
				alert("아이디를 입력해주세요.")
				frm.user_id.focus();
				fnLoginText("loff");
				return false;
			}
			if(frm.user_password.value.isEmpty()){
				alert("비밀번호를 입력해주세요.")
				frm.user_password.focus();
				return false;
			}
			else {
				return true;
			}
		
		}});

		Object.extend(checker,{
			OnSubmit: function()
			{
				if(host=="www.newitemmania.net" || host=="newitemmania.net")
				{
					frm.action="https://www.newitemmania.net:9443/portal/user/login_form_ok.php";
				}
				return true;
			}
		});
	}
	/* ▲ 로그인 check */

	/* ▼  로그인시 capslock 체크*/
	var Ftcapslock = false;
	var Ftshift = false;

	Object.extend(_form.protect,
	{
		capslock_help : function(input)
		{
			this.set(input,
				function(Event)
				{
					var keycode = _event.keycode(Event);
					if(keycode == 16)
					{
						Ftshift = true;
					}
				},
				function(Event)
				{
					passwordCheck(Event);
				}
			);
			$('user_password').onblur = function(Event)
			{
				Object.extend($('capslock_help'),_item.layer).behind();
				fnLoginText('pon');
			}
			$('user_password').onkeyup = function(Event)
			{
				var keycode = _event.keycode(Event);
				if(keycode == 16)
				{
					Ftshift = false;
				}

				if (Ftshift == true && keycode ==9 )
				{
					Ftshift = false;
				}
			}
			$('user_password').onkeypress = function(Event)
			{
				Ftcapslock = false;
				var keycode = _event.keycode(Event);
				if((keycode >= 65 && keycode <= 90) && !Ftshift)
				{
					Ftcapslock = true;
				}
				else if((keycode >= 97 && keycode <= 122) && Ftshift)
				{
					Ftcapslock = true;
				}
			}
		}
	});

	Object.extend(_form.protect,
	{
		user_id : function(input)
		{
			$('user_id').onfocus = function(Event)
			{
				Object.extend($('capslock_help'),_item.layer).behind();
			}
		}
	});

	_form.protect.capslock_help(frm.user_password);
	_form.protect.user_id(frm.user_id);

	function passwordCheck(Event)
	{
		var keycode = _event.keycode(Event);
		if(keycode == 16)
		{
			Ftshift = false;
		}

		if(frm.user_password.value.length > 0 && Ftcapslock && !Ftshift)
		{
			Object.extend($('capslock_help'),_item.layer).show();
			make_caps_login('capslock_help','Caps-lock','kr');
		}
		else
		{
			Object.extend($('capslock_help'),_item.layer).behind();
		}
	}
	/* ▲ 로그인시 capslock 체크 */
}

/* ▼ 게임매니아 */
var obf;
var bfrollpos= 4;  //?
var nbfd = 4000;	// 롤링 간격
var nbfr = nbfd;	// 현재턴 남은 시간
var nbfi = 500;		// 체크 간격

function bf(srt ,bfrolllen)  // 롤링 방향
{
	if(nbfr>0)
		nbfr -= nbfi;
	if(nbfr <= 0 )
		bfnext(srt ,bfrolllen);
		bfresume(srt ,bfrolllen);
}

function bfnext(srt ,bfrolllen) //다음배너로 이동
{
 	++bfrollpos;
	if(bfrollpos>bfrolllen)
		bfrollpos=1;
  	for(var i=1; i<=bfrolllen; i++ )
	{
		idx = new String(srt) ;
		idx += i ;
		k = $(idx).style;
 		if(k)
		{
			if(i==bfrollpos)
				k.display = "block";
			else
				k.display = "none";
		}
 	}
	nbfr = nbfd;
}

function bfpreview(srt,bfrolllen) //이전배너로 이동
{
	--bfrollpos;
	if(bfrollpos==0) bfrollpos=bfrolllen;
	for(var i=1; i<=bfrolllen; i++)
	{
		idx = new String(srt);
		idx += i;
		k = $(idx).style;
		if(k)
		{
			if (i==bfrollpos)
				k.display = "block";
			else
				k.display = "none";
		}
	}
	nbfr = nbfd;
}

function bfpause()	//롤링정지 함수
{
	clearTimeout(obf);
}
function bfresume(srt,bfrolllen)  // 롤링 함수
{
  	bfpause();
 	obf = window.setTimeout("bf('"+srt+"',"+bfrolllen+")",nbfi);
}

function bnRollingstarter() // 롤링시작
{
   	bfnext($('roll_bn').value,$('roll_cnt').value);
 	bfresume($('roll_bn').value,$('roll_cnt').value);
}

function setEvent()
{
  	$('pt_gmmania_game').onmouseover	= bfpause; //신규 롤오버시 정지
	$('pt_gmmania_game').onmouseout	= function()//신규 롤아웃시 resume
	{
		bfresume($('roll_bn').value,$('roll_cnt').value);
	}
	$('new_up').onclick = function()
	{
		bfpreview($('roll_bn').value,$('roll_cnt').value);
	}
	$('new_down').onclick = function()
	{
		bfnext($('roll_bn').value,$('roll_cnt').value);
	}
}
/* ▲ 게임매니아 */
/* ▼ 매니아옥션 */
var at_obf;
var at_bfrollpos= 4;  //?
var at_nbfd = 4000;	// 롤링 간격
var at_nbfr = at_nbfd;	// 현재턴 남은 시간
var at_nbfi = 500;		// 체크 간격
var itv_obf;
var itv_bfrollpos= 4;  //?
var itv_nbfd = 4000;	// 롤링 간격
var itv_nbfr = at_nbfd;	// 현재턴 남은 시간
var itv_nbfi = 500;		// 체크 간격


function at_bf(srt ,bfrolllen)  // 롤링 방향
{
	if(at_nbfr>0)
		at_nbfr -= at_nbfi;
	if(at_nbfr <= 0 )
		at_bfnext(srt ,bfrolllen);
		at_bfresume(srt ,bfrolllen);
}

function at_bfnext(srt ,bfrolllen) //다음배너로 이동
{
 	++at_bfrollpos;
	if(at_bfrollpos>bfrolllen)
		at_bfrollpos=1;
  	for(var i=1; i<=bfrolllen; i++ )
	{
		idx = new String(srt) ;
		idx += i ;
		k = $(idx).style;
 		if(k)
		{
			if(i==at_bfrollpos)
				k.display = "block";
			else
				k.display = "none";
		}
 	}
	at_nbfr = at_nbfd;
}

function at_bfpreview(srt,bfrolllen) //이전배너로 이동
{
	--at_bfrollpos;
	if(at_bfrollpos==0) at_bfrollpos=bfrolllen;
	for(var i=1; i<=bfrolllen; i++)
	{
		idx = new String(srt);
		idx += i;
		k = $(idx).style;
		if(k)
		{
			if (i==at_bfrollpos)
				k.display = "block";
			else
				k.display = "none";
		}
	}
	at_nbfr = at_nbfd;
}

function at_bfpause()	//롤링정지 함수
{
	clearTimeout(at_obf);
}
function at_bfresume(srt,bfrolllen)  // 롤링 함수
{
  	at_bfpause();
 	at_obf = window.setTimeout("at_bf('"+srt+"',"+bfrolllen+")",at_nbfi);
}

function at_bnRollingstarter() // 롤링시작
{
   	at_bfnext($('at_roll_bn').value,$('at_roll_cnt').value);
 	at_bfresume($('at_roll_bn').value,$('at_roll_cnt').value);
}

function at_setEvent()
{
  	$('pt_auction').onmouseover	= at_bfpause; //신규 롤오버시 정지
	$('pt_auction').onmouseout	= function()//신규 롤아웃시 resume
	{
		at_bfresume($('at_roll_bn').value,$('at_roll_cnt').value);
	}
	$('at_left').onclick = function()
	{
		//alert("left");
		at_bfpreview($('at_roll_bn').value,$('at_roll_cnt').value);
	}
	$('at_right').onclick = function()
	{
		//alert("right");
		at_bfnext($('at_roll_bn').value,$('at_roll_cnt').value);
	}
}

	/* ▼ 옥션 낙찰자 */
	function itv_bnRollingstarter() // 롤링시작
	{
		itv_bfnext($('at_roll_itv_bn').value,$('at_roll_itv_cnt').value);
		itv_bfresume($('at_roll_itv_bn').value,$('at_roll_itv_cnt').value);

	}
	function itv_setEvent()
	{
		$('pt_auction').onmouseover	= itv_bfpause; //신규 롤오버시 정지
		$('pt_auction').onmouseout	= function()//신규 롤아웃시 resume
		{
			itv_bfresume($('at_roll_itv_bn').value,$('at_roll_itv_cnt').value);
		}
	}
	function itv_bfnext(srt ,bfrolllen) //다음배너로 이동
	{
		++itv_bfrollpos;
		if(itv_bfrollpos>bfrolllen)
			itv_bfrollpos=1;
		for(var i=1; i<=bfrolllen; i++ )
		{
			idx = new String(srt) ;
			idx += i ;
			k = $(idx).style;
			if(k)
			{
				if(i==itv_bfrollpos)
					k.display = "block";
				else
					k.display = "none";
			}
		}
		itv_nbfr = itv_nbfd;
	}
	function itv_bfresume(srt,bfrolllen)  // 롤링 함수
	{
		itv_bfpause();
		itv_obf = window.setTimeout("itv_bf('"+srt+"',"+bfrolllen+")",itv_nbfi);
	}
	function itv_bfpause()	//롤링정지 함수
	{
		clearTimeout(itv_obf);
	}
	function itv_bf(srt ,bfrolllen)  // 롤링 방향
	{
		if(itv_nbfr>0)
			itv_nbfr -= itv_nbfi;
		if(itv_nbfr <= 0 )
			itv_bfnext(srt ,bfrolllen);
			itv_bfresume(srt ,bfrolllen);
	}
	/* ▲ 옥션 낙찰자 */
/* ▲ 매니아옥션 */

/* ▼ 매니아존 */
var mz_obf;
var mz_bfrollpos= 4;  //?
var mz_nbfd = 3000;	// 롤링 간격
var mz_nbfr = mz_nbfd;	// 현재턴 남은 시간
var mz_nbfi = 500;		// 체크 간격
var zone_i = 0;			//현재 컨텐츠(0:영화, 1:만화, 2:운세, 3:노래방)

function mz_bf(srt ,bfrolllen)  // 롤링 방향
{
	if(mz_nbfr>0)
		mz_nbfr -= mz_nbfi;
	if(mz_nbfr <= 0 )
	{
		if(mz_bfrollpos==bfrolllen)
		{
			select_zone(++zone_i);		//만약 롤링이 모두 돌아갔다면 다음 컨텐츠로 이동(영화->만화->운세->노래방->영화...)
		}
		else
		{
			mz_bfnext(srt ,bfrolllen);		//롤링이 남아있다면 다음 롤링으로 이동
		}
	}
		mz_bfresume(srt ,bfrolllen);
}

function mz_bfnext(srt ,bfrolllen, g_load) //다음배너로 이동
{
 	++mz_bfrollpos;
	if(mz_bfrollpos>bfrolllen)
	{
		mz_bfrollpos=1;
		if (g_load!='s')
		{
			select_zone(++zone_i);
		}
	}
  	for(var i=1; i<=bfrolllen; i++ )
	{
		idx = new String(srt) ;
		idx += i ;
		k = $(idx).style;
 		if(k)
		{
			if(i==mz_bfrollpos)
				k.display = "block";
			else
				k.display = "none";
		}
 	}
	mz_nbfr = mz_nbfd;
}

function mz_bfpreview(srt,bfrolllen) //이전배너로 이동
{
	--mz_bfrollpos;
	if(mz_bfrollpos==0)
	{
		mz_bfrollpos=bfrolllen;
		select_zone(--zone_i);
	}
	for(var i=1; i<=bfrolllen; i++)
	{
		idx = new String(srt);
		idx += i;
		k = $(idx).style;
		if(k)
		{
			if (i==mz_bfrollpos)
				k.display = "block";
			else
				k.display = "none";
		}
	}
	mz_nbfr = mz_nbfd;
}

function mz_bfpause()	//롤링정지 함수
{
	clearTimeout(mz_obf);
}
function mz_bfresume(srt,bfrolllen)  // 롤링 함수
{
  	mz_bfpause();
 	mz_obf = window.setTimeout("mz_bf('"+srt+"',"+bfrolllen+")",mz_nbfi);
}

function mz_setEvent(obj)
{
	/* ▼ 만화 제거 By 백종일 (2010/12/30) */
	//objArray = new Array("mv", "mh", "ft", "nr");
	/* ▲ 만화 제거 By 백종일 (2010/12/30) */
	objArray = new Array("mv", "ft", "nr");
	if (obj==undefined)
	{
		obj = 0;
	}

	for (i=0;i<objArray.length;i++)
	{
		if (obj!=i)
		{
			$(objArray[i]+'_pt_zone').style.display = "none";
		}
		else
		{
			$(objArray[i]+'_pt_zone').style.display = "block";
		}
	}
  	$(objArray[obj]+'_pt_zone').onmouseover	= mz_bfpause; //신규 롤오버시 정지
	$(objArray[obj]+'_pt_zone').onmouseout	= function()//신규 롤아웃시 resume
	{
		mz_bfresume($(objArray[obj]+'_roll_bn').value,$(objArray[obj]+'_roll_cnt').value);
	}
	$(objArray[obj]+'_left').onclick = function()
	{
		mz_bfpreview($(objArray[obj]+'_roll_bn').value,$(objArray[obj]+'_roll_cnt').value);
	}
	$(objArray[obj]+'_right').onclick = function()
	{
		mz_bfnext($(objArray[obj]+'_roll_bn').value,$(objArray[obj]+'_roll_cnt').value);
	}
	//롤링시작
   	mz_bfnext($(objArray[obj]+'_roll_bn').value,$(objArray[obj]+'_roll_cnt').value, 's');
 	mz_bfresume($(objArray[obj]+'_roll_bn').value,$(objArray[obj]+'_roll_cnt').value);
}

function select_zone(sel)
{
	zone_i = sel;
	if (zone_i==undefined)
	{
		zone_i = 0;
	}
	else if (zone_i>objArray.length-1)
	{
		zone_i = 0;
	}
	else if (zone_i<0)
	{
		zone_i = 3;
	}
	objUl = document.getElementById("pt_zone_category");
	objSpan = objUl.getElementsByTagName("span");
	for (i=0;i<objSpan.length;i++)
	{
		objSpan[i].style.fontWeight = "normal";
		objSpan[i].style.color = "#5A5A5A";
	}
	//선택 컨텐츠에 글씨 스타일 주기
	$(objArray[zone_i]+"_zone").style.fontWeight = "bold";
	$(objArray[zone_i]+"_zone").style.color = "#F86900";
	//해당 컨턴츠 롤링 event 셋팅
	mz_setEvent(zone_i);
}
/* ▲ 매니아존 */

/* ▼ 메인팝업관리 */
function popupManager()
{
	var rgPopup = Array(
		//{name:"20090701_events", url:"/portal/popup/ipoint_20090701.html", width:400, height:385, top:0, left:0}
	);

	var nLength = rgPopup.length;

	for(var i=0; i<nLength; i++)
	{
		if(rgPopup[i].name.isEmpty() || rgPopup[i].url.isEmpty())
		{
			continue;
		}
		if(_cookie.get(rgPopup[i].name)!="deny")
		{
			var wnd = window.open(rgPopup[i].url,rgPopup[i].name,"top="+rgPopup[i].top.toString()+",left="+rgPopup[i].left.toString()+",status=no,toolbar=no,menubar=no,location=no,fullscreen=no,scrollbars=no,resizable=no,titlebar=no,width="+rgPopup[i].width+",height="+rgPopup[i].height).focus();
		}
	}
}
/* ▲ 메인 팝업관리 */


/* ▼ 호스트가져오기 */
function Host()
{
	var DomainName;
	DomainName=location.href;
	DomainName=DomainName.split("//");
	DomainName=DomainName[1].substr(0,DomainName[1].indexOf("/"));
	return DomainName;
}
/* ▲ 호스트가져오기 */

function mv_img(url, img)
{
	$('img_poster').innerHTML = "<a href='"+url+"'><img src='"+img+"' width='88' height='118' class='box_line' /></a>";
}

function fnLoginText(tType)
{
	var strLogin = null;
	switch(tType)
	{
		case "lon" 	: if($("user_id").value.isEmpty()){ $("user_id").style.background = "url('/images/login/id.gif') 3px 3px no-repeat"; $("user_id").style.backgroundColor = "#F0F6FB"; }
						break;
		case "loff" : $("user_id").style.background = "none";
						break;
		case "pon" 	: if($("user_password").value.isEmpty()) { $("user_password").style.background = "url('/images/login/pw.gif') 3px 3px no-repeat"; $("user_password").style.backgroundColor = "#F0F6FB"; }
						break;
		case "poff" : $("user_password").style.background = "none";
						break;
	}	
}
