

function GametopStart() {
	//GetChBtn();
}



var ChannelBtn = new Array();

function GetChBtn() {
	var chBtns = document.getElementsByTagName('li');	
	var ViewMode = new Array('set_game2','set_game3','set_game40'); //°üÀü¸ðµå ÀÖ´Â °ÔÀÓ	
	var ThisGame = document.body.className.split(" ");
	var IconJoin = new Array
	var j = 0;
	var num = 3;
	
	for(k=0; k<ViewMode.length; k++) {
		if (GetGameSet() == ViewMode[k]) {
			num = 5;
			break;
		}
	}
		
	//Ã¤³Î°ü·Ã object¾òÀ½
	for(i=0;i<chBtns.length;i++) {
		if(chBtns[i].parentNode.parentNode.className=='channel') {
			ChannelBtn[j] = chBtns[i];
			++j;
		}
	}
	
	var catGameThis = GetCategorySet();
	
	//ÀÌ¹ÌÁö »çÀÌÁî¿¡ ´ëÇÑ fitting
	for(i=0; i<ChannelBtn.length; i++) {		
		if(ChannelBtn[i].className=='') {
			var btnW = ChannelBtn[i].firstChild.width;
			ChannelBtn[i].style.width = btnW+"px";
		}
		else if(ChannelBtn[i].className == 'on') {
			var btnW = ChannelBtn[i].firstChild.firstChild.width;
			ChannelBtn[i].style.width = btnW+"px";
		}
		else if(ChannelBtn[i].className == 'view') {
			var btnW = ChannelBtn[i].firstChild.firstChild.width;
			ChannelBtn[i].style.width = btnW+"px";
		}
	}
	
}


// ÁÂÇ¥±¸ÇÔ
function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {
		posTop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {
		posLeft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return posLeft;
}


// ¿Â¿À¹ö È¿°ú
function ChBtnMove(num,width) {
	ChannelBtn[num].firstChild.firstChild.style.left = -width+"px";
}


// Åä³Ê¸ÕÆ® Ã¤³Î ÅÇ
function ChTmOpen(name) {
	ChTmTab = new Array('channel_nm','channel_tm');
	for(i=0; i<ChTmTab.length; i++ ) {
		document.getElementById(ChTmTab[i]).style.display = "none";
		if(ChTmTab[i] = name) document.getElementById(ChTmTab[i]).style.display = "block"; 			
	}
	fitNewsEvent();
}
function ChTmOn(id) {
	var chNm = document.getElementById('channel_nm');
	var chTm = document.getElementById('channel_tm');
	var chTab1 = document.getElementById('ChTmTab').getElementsByTagName('img')[0];
	var chTab2 = document.getElementById('ChTmTab').getElementsByTagName('img')[1];
	
	if(id=='channel_nm') {
		if(chTab1.src.slice(chTab1.src.length-7,chTab1.src.length-4) != "_on") chTab1.src = chTab1.src.slice(0,chTab1.src.length-4) + "_on.gif";
		if(chTab2.src.slice(chTab2.src.length-7,chTab2.src.length-4) == "_on") chTab2.src = chTab2.src.slice(0,chTab2.src.length-7) + ".gif";
		chTab1.style.marginLeft = '0';
		chNm.style.display = 'block';
		chTm.style.display = 'none';
	}
	else if(id=='channel_tm') {
		if(chTab1.src.slice(chTab1.src.length-7,chTab1.src.length-4) == "_on") chTab1.src = chTab1.src.slice(0,chTab1.src.length-7) + ".gif";
		if(chTab2.src.slice(chTab2.src.length-7,chTab2.src.length-4) != "_on") chTab2.src = chTab2.src.slice(0,chTab2.src.length-4) + "_on.gif";
		chTab1.style.marginLeft = '-9px';
		chNm.style.display = 'none';
		chTm.style.display = 'block';
	}
	fitNewsEvent();
}


// ´º½ºÀÌº¥Æ® ·Ñ¸µ
function fitNewsEvent() {
	var maxNum = checkMaxNum('newsevent',1);
	var chHeight = document.getElementById('channel').clientHeight;
	for(i=1; i<=maxNum; i++) {
		var banHeight = (document.getElementById('newsevent'+i).getElementsByTagName('img')[0].clientHeight>178) ? document.getElementById('newsevent'+i).getElementsByTagName('img')[0].clientHeight : 178;
		document.getElementById('newsevent'+i).getElementsByTagName('a')[0].style.padding = parseInt((chHeight-banHeight-47)/2)+'px 0';
	}
}
function checkMaxNum(id,startNum) {
	var startNum = (startNum==null)?0:startNum;
	var maxNum = 0;	
	while(document.getElementById(id+startNum)) {
		++startNum;
		++maxNum
	}	
	return maxNum;	
}
function onNewsEvent(no) {	
	var maxNum = checkMaxNum('newsevent',1);
	fitNewsEvent();
	for(j=1; j<=maxNum; j++) {
		//document.getElementById('newsevent'+i).getElementsByTagName('a')[0].style.padding = parseInt((chHeight-document.getElementById('newsevent'+i).getElementsByTagName('img')[0].clientHeight-47)/2)+'px 0';
		if(j==no) document.getElementById('newsevent'+j).className = 'on';
		else document.getElementById('newsevent'+j).className = '';		
	}
}
function goNewsEvent(no) {
	var maxNum = checkMaxNum('newsevent',1);
	if(no==null) no=1;
	
	onNewsEvent(no);
	
	no = (++no>maxNum)?1:no;
	rollingEvent = setTimeout("goNewsEvent("+no+")",4000);
}

// ¸ð¹ÙÀÏ ÅÇ
function MobileTab(num) {
	for (i=1; i<=3; i++) {		
		tab = "MobileTab"+i;
		document.getElementById(tab).style.display = "none";
		if ( i==num) {
			document.getElementById(tab).style.display = "block";
		}
	}
}


// Ã¤³Î ÃÊ°ú¸Ó´Ï 
function ChOverMoney() {
	var icon = document.getElementById('ico_overmoney');
	var layer = document.getElementById('LayerOverMoney');
	
	if(icon.src.substring(icon.src.length-19,icon.src.length-6) == 'ico_top_money') icon.src = icon.src.substring(0,icon.src.length-4) + '_off.gif';
	
	if(layer) {
		layer.style.left = findPosX(icon) - layer.clientWidth/2 - 185 + 'px';
		layer.firstChild.style.left = layer.clientWidth/2 + 3 + 'px';
		layer.style.visibility = 'visible';	
	}
}
function ChOutMoney() {
	var icon = document.getElementById('ico_overmoney');
	var layer = document.getElementById('LayerOverMoney');	
	
	if(icon.src.substring(icon.src.length-23,icon.src.length-10) == 'ico_top_money') icon.src = icon.src.substring(0,icon.src.length-8) + '.gif';
	
	if(layer) {	layer.style.visibility = 'hidden';}
}


/* ÆÁ¹Ú½º */
function ChTipOver(tip,id) {	

	var ThisCh = event.srcElement;
	
	if(!document.getElementById(id)) {
		var Tipbox = document.createElement('div');
		var Tipbox_Link = document.createElement('a');
		var Tipbox_in = document.createElement('p');
		
		var channel = document.getElementById('channel');
		
		
		Tipbox.className = 'channel_tip';
		Tipbox.id = id;
		Tipbox.style.position = 'absolute';
		Tipbox.style.display = 'none';
		Tipbox.style.top = findPosY(event.srcElement)-findPosY(channel.firstChild)-15+'px';
		Tipbox.style.left = findPosX(event.srcElement)-findPosX(channel)-4+'px';
		
		Tipbox.appendChild(Tipbox_Link);
		Tipbox.appendChild(Tipbox_in);
		Tipbox_in.innerText = tip;
				
		channel.firstChild.appendChild(Tipbox);
				
			var ChLink = event.srcElement.parentElement;
			if(ChLink.tagName == 'A') { 
				var TipClass = 'tip_linkOn';
				var TipLink = 'href="'+ChLink.href+'"';
			}
			
		Tipbox_Link.outerHTML = '<a '+TipLink+' class="'+TipClass+'" onFocus="this.blur();" onMouseOut="ChTipOut(\''+id+'\');"></a>';		
	}
	
	overtip = window.setTimeout('ChTipCheck("'+id+'");',500);

	//document.getElementById(id).style.top = findPosY(event.srcElement)-123+'px';
	//document.getElementById(id).style.left = findPosX(event.srcElement)-137+'px';
	
}
function ChTipOut(id) {
	if(!document.getElementById(id)) return;	
	//if(event.toElement==null) return;
	outtip = window.setTimeout('ChTipClear("'+id+'");',300);	
	clearTimeout(overtip);
	
	
	//if(event.toElement.className=='tip_linkOn') clearTimeout(outtip);
	
}
function ChTipFix(id) {
	//alert(findPosX(event.srcElement)-137+'px');
	//document.getElementById(id).style.top = findPosY(event.srcElement)-123+'px';
	//document.getElementById(id).style.left = findPosX(event.srcElement)-137+'px';
}
function ChTipCheck(id) {
	document.getElementById(id).style.display = 'block';	
	//ChTipFix(id);
}
function ChTipClear(id) {	
	document.getElementById(id).style.display = 'none';
}


// »óÇÏÀÌÇÃ·¯½º °¡ÀÌµå
function CloseGuide48Pop() {
	var alldiv = document.getElementsByTagName('div');
	var popnum = 0;
	var popGuide = new Array();
	
	for(i=0; i<alldiv.length; i++) {
		if(alldiv[i].className == 'pop_guide48') {
			alldiv[i].style.display = 'none';
		}
	}
}


// ÇªÅÍ °ÔÀÓÁ¤º¸ ÅÇ
function gameinfoImgAll() {
	if(!document.getElementById('gameinfoImg')) return;	
	document.getElementById('gameinfoImg').style.top = '0px';
}
function gameinfoImg19() {
	if(!document.getElementById('gameinfoImg')) return;	
	document.getElementById('gameinfoImg').style.top = '-63px';
}


// ÁÖ·Â»óÇ° ¿µ¿ª 
function showSbn(o) {
	var name, num, newOffset;
	if (typeof o === 'object') {
		name = '.' + o.href.split('#').pop();
		num = parseInt(name.split('_').pop(), 10);
	} else {
		num = parseInt(o, 10);
	}

	var sbnPos = parseInt($('#spotlight').attr('sbnPos'), 10) || num;
	var sbnOffset = parseInt($('#spotlight').attr('sbnOffset'), 10) || num;
	
	var newOffset = sbnOffset + (num - sbnPos);

	$('#spotlight').attr({'sbnOffset':newOffset, 'sbnPos': num});

	$('#spotlight .banner').hide();
	$('#spotlight .banner:nth-child(' + num + ')').show();
	$('#spotlight .btns li').removeClass('on');
	$('#spotlight .btns li:nth-child(' + num + ')').addClass('on');
		
	$('#spotlight .btns').removeClass('btnsOffset1 btnsOffset2 btnsOffset3').addClass('btnsOffset' + newOffset);
}


function spotBannerGo(dir) {
	var offset = 63;
	var currentPos = parseInt($('#spotlight').attr('sbnPos'), 10);
	var currentOffset = parseInt($('#spotlight').attr('sbnOffset'), 10);
	var min = 1;
	var move = false;
	var max = $('#spotlight .banner').size();
	
	if (dir === 'next') {
		offset *= -1;
		if (currentPos < max) {
			currentPos += 1;
			move = true;
		} 
		if (currentOffset < 3) {
			currentOffset += 1;
			move = false;
		} 
	} if (dir === 'prev') {
		if (currentPos > min) {
			currentPos -= 1;
			move = true;
		} 
		if (currentOffset > 1) {
			currentOffset -= 1;
			move = false;
		} 
	}

	if (move) {
		$('#spotlight .nav ul')
			.css('top', function() {
				var pos = parseInt($(this).css('top'), 10) + offset;
				return pos;
			});

	}
	$('#spotlight').attr({'sbnOffset': currentOffset, 'sbnPos': currentPos});
	showSbn(currentPos);
}

function spotItemGo(el, dir) {
	var offset = ( dir === 'next') ? -114 : 114;
	var max = ($(el + ' ul li').size() - 5) * -114;
	$(el + ' ul')
		.css('left', function() {
			var pos = parseInt($(this).css('left'), 10) + offset;
			if (pos <= max) pos = max;
			if (pos > 0) pos = 0;
			return pos;
		});
}


//end of ÁÖ·Â»óÇ° ¿µ¿ª 



// ·¹ÀÌ¾îÆË¾÷ bg¼¼ÆÃ
function set_pmlayer() {	
	$('.pop_pmlayer:visible .pmlayer_bg:not(:has(.pmlayer_bg1))').append('<div class="pmlayer_bg1"/><div class="pmlayer_bg2"/><div class="pmlayer_bg3"/><div class="pmlayer_bg4"/><div class="pmlayer_bg5"/><div class="pmlayer_bg6"/>');
	$('.pop_pmlayer:visible').width($('.pop_pmlayer:visible .pmlayer_img').width());
	$('.pop_pmlayer:visible .pmlayer_bg3, .pop_pmlayer:visible .pmlayer_bg4').height($('.pop_pmlayer:visible .pmlayer_img').height());
	$('.pop_pmlayer .btn_close, .pop_pmlayer .btn_close2').click(function() {	$(this).parent().hide(); });
}

function set_pmlayer2() {	
	if($.browser.msie && (($.browser.version==7.0)||($.browser.version==8.0))) {
		if(!$('.pmlayer:visible .pmlayer_bg_r:visible').height()) {
			$('.pmlayer:visible .pmlayer_bg_r').height($('.pmlayer:visible .pmlayer_img').height());
		}
	}
	
	if($.browser.msie && $.browser.version==6.0) {
		if($('.pmlayer:visible .pmlayer_img').width() < $('.pmlayer:visible .pmlayer_bg_lb').width()) {
			$('.pmlayer:visible .pmlayer_bg_lb').width($('.pmlayer:visible .pmlayer_img').width());
			$('.pmlayer:visible').css('overflow','visible');
		} else { $('.pmlayer:visible').css('overflow','visible'); }
	}
}

$(document).ready(function() {
	set_pmlayer();
	set_pmlayer2();
	$('.poplayer .btn_close, .poplayer .btn_close2').click(function() {	$(this).parent().hide(); });
});
$(window).bind('load', function() {
	set_pmlayer();
	set_pmlayer2();
});



