﻿
/*  Ntreev Global Navigation Bar [ 2009-08-14 ]
*   Copyright (c) 2009, ALL right reserved.
*   Script by Su-hyung, park
*/

var NGNB =
{    	
	css : '<link rel="stylesheet" href="$path/ngnb.css" type="text/css" />',
	html : [
		'<div><div id="ngnb">',
		'	<div class="ngnb-wrap">',
		'		<a href="javascript:Ns.Content.home()" class="ngnb-logo"><img src="$path/img/logo.gif" alt="gametree" /></a>',
		'		<a class="ngnb-game" onmouseover="NGNB.showGames()" onmouseout="NGNB.hideGames()"><img src="$path/img/txt1.gif" onmouseover="this.src=\'$path/img/txt1o.gif\'" onmouseout="this.src=\'$path/img/txt1.gif\'" alt="게임" /></a>',
		'		<a href="$home/Event/" class="ngnb-txt"><img src="$path/img/txt2.gif" onmouseover="this.src=\'$path/img/txt2o.gif\'" onmouseout="this.src=\'$path/img/txt2.gif\'" alt="이벤트" /></a>',
		'		<a href="$home/Customer/" class="ngnb-txt"><img src="$path/img/txt3.gif" onmouseover="this.src=\'$path/img/txt3o.gif\'" onmouseout="this.src=\'$path/img/txt3.gif\'" alt="고객센터" /></a>',
		'		<a href="$home/SecurityCenter/" class="ngnb-txt"><img src="$path/img/txt4.gif" onmouseover="this.src=\'$path/img/txt4o.gif\'" onmouseout="this.src=\'$path/img/txt4.gif\'" alt="보안센터" /></a>',
		( Ns.Login.is()
			? '<a href="javascript:Ns.Content.info()" class="ngnb-member"><img src="$path/img/btn_mypage.gif" alt="마이페이지" /></a>'+
				'<a href="javascript:Ns.Login.out()" class="ngnb-member"><img src="$path/img/btn_logout.gif" alt="로그아웃" /></a>'
			: (Ns.rsn() && Ns.rsn() == 10) 
				? '<a href="javascript:Ns.Login.go()" class="ngnb-member"><img src="$path/img/btn_logins.gif" alt="로그인" /></a>'
				: '<a href="javascript:Ns.Content.join()" class="ngnb-member"><img src="$path/img/btn_join.gif" alt="회원가입" /></a>'+
					'<a href="javascript:Ns.Login.go()" class="ngnb-member"><img src="$path/img/btn_login.gif" alt="로그인" /></a>'
		),
		'		<p class="ngnb-banner" id="ngnb-promotions"></p>',
		'	</div>',
		'</div>',

		'<div id="ngnb-games"  onmousemove="NGNB.showGames()" onmouseout="NGNB.hideGames()">',
			'<dl class="sportCasual" id="ngnb-games-div">',
				'<dt><img src="$path/img/title_sportCasual.png" alt="스포츠/캐주얼 게임" style="width:77px;height:10px;"/></dt>',
				'<dd class="nowing"><a href="http://$servicebm.gametree.co.kr"><img src="$path/img/nowing_sports.png" alt="프로야구 매니저" /></a></dd>',
				'<dd><a href="http://$servicealicia.gametree.co.kr">말과 나의 이야기, 앨리샤</a></dd>',
				'<dd><a href="http://$servicebm.gametree.co.kr">프로야구 매니저</a></dd>',
				'<dd><a href="http://$servicepangya.gametree.co.kr">팡야</a></dd>',
				//'<dd><a href="http://$servicedinomachia.gametree.co.kr">디노마키아</a></dd>',
			'</dl>',
			'<dl class="gameRpg">',
				'<dt><img src="$path/img/title_rpg.png" alt="RPG 게임" style="width:39px;height:9px;"/></dt>',
				//2010.07.28 천영전 로컬에 존재 하길래 삭제
			    //'<dd class="nowing"><a href="http://$servicetrickster.gametree.co.kr"><img src="$path/img/nowing_rpg.png" alt="트릭스터" /></a></dd>',
				'<dd class="nowing"><a href="http://$servicesky.gametree.co.kr"><img src="$path/img/nowing_sky.png" alt="천자영웅전" /></a></dd>',
				//'<dd class="nowing"><a href="http://$servicepower.gametree.co.kr"><img src="$path/img/nowing_power.png" alt="파워레인저 온라인" /></a></dd>',
				'<dd><a href="http://$servicepower.gametree.co.kr">파워레인저 온라인</a></dd>',
				'<dd><a href="http://$servicetrickster.gametree.co.kr/Events/201004_7th/Default.aspx">트릭스터</a></dd>',
				'<dd><a href="http://$servicesky.gametree.co.kr">천자영웅전</a></dd>',
				'<dd><a href="http://$servicesinmadae.gametree.co.kr">신 마법의 대륙</a></dd>',
			'</dl>',
			'<dl class="gameWeb">',
			'	<dt><img src="$path/img/title_aos.png" alt="AOS게임" style="width:39px;height:9px;"/></dt>',
			'	<dd class="nowing"><a href="http://$servicehon.gametree.co.kr"><img src="$path/img/nowing_aos.png" alt="히어로즈 오브 뉴어스" /></a></dd>',
			'	<dd><a href="http://$servicehon.gametree.co.kr">히어로즈 오브 뉴어스</a></dd>',
			'	<dt class="fps"><img src="$path/img/title_web_fps.png" alt="웹 게임&fps게임" class="web_fps" style="width:73px;height:9px;"/></dt>',
			'	<dd><a href="http://$servicearche.gametree.co.kr">문명전쟁 아르케</a></dd>',
			'	<dd><a href="http://$serviceblackshot.gametree.co.kr">블랙샷</a></dd>',
			'</dl>',
			'<dl class="gameMobile">',
			'	<dt><img src="$path/img/title_mobile.png" alt="모바일 게임" style="width:43px;height:9px;" /></dt>',
			'	<dd class="nowing"><a href="http://www.tstore.co.kr/userpoc/game/viewProduct.omp?insDpCatNo=DP01004&insProdId=0000257580&prodGrdCd=PD004401&t_top=DP000501" target="_blank"><img src="$path/img/nowing_rpg2.png" alt="트릭스터 모바일" /></a></dd>',
			'	<dd><a href="http://www.tstore.co.kr/userpoc/game/viewProduct.omp?insDpCatNo=DP01004&insProdId=0000257580&prodGrdCd=PD004401&t_top=DP000501" target="_blank">트릭스터 모바일</a></dd>',
			'	<dd><a href="http://www.gxg.com/detail/detailGameInfoBasic.gp?vpid=0031826050&dataType=1&searchKeyword=" target="_blank">미소녀틀린그림찾기</a></dd>',
			'	<dd><a href="http://www.gxg.com/detail/detailGameInfoBasic.gp?vpid=0031559911&dataType=1&searchKeyword=" target="_blank">졸업의기술2</a></dd>',
			'	<dd><a href="http://www.gxg.com/detail/detailGameInfoBasic.gp?vpid=0031928448&dataType=1&searchKeyword=" target="_blank">미니게임1분만</a></dd>',
			'	<dd><a href="http://www.gxg.com/detail/detailGameInfoBasic.gp?vpid=0030113187&dataType=1&searchKeyword=" target="_blank">화이트데이</a></dd>',
			'</dl>',
		'</div>'

	].join('\n'),

	http: Ns.isSecure() ? 'https://' : 'http://',
	service: Ns.getServiceDomain(),
	
	showGames : function() { document.getElementById('ngnb-games').style.display = 'block' },
	hideGames : function() { document.getElementById('ngnb-games').style.display = 'none' },

	Write : function()
	{
		var home =  'http://' + this.service + 'www.gametree.co.kr';
		var path = this.http + this.service + 'common.gametree.co.kr/NGNB';
		//var gamelist = this.http + this.service + 'www.gametree.co.kr/NGNB/GameList.aspx';
		var promotions = this.http + this.service + 'www.gametree.co.kr/NGNB/PromotionList.aspx';
		//gamelist = 'http://qa.www.gametree.co.kr/NGNB/GameList.aspx';
		//promotions = 'http://qa.www.gametree.co.kr/NGNB/PromotionList.aspx';

		// init ngnb html
		var doc = document;
		doc.write(this.css.replace(/\$path/gm, path));
		doc.write(this.html.replace(/\$path/gm, path).replace(/\$home/gm, home).replace(/\$service/gm, this.service));

		// init Game banners
		// html 사용으로 제거 2011.01.17 by 임창규
		/*
		Ns.Ajax.request(gamelist, {
			method : 'get',
			onSuccess : function(res) {
				try {
					NGNB.initGames(res.getElementsByTagName('Item'));
				}
				catch (e) {}
			},
			onFailed : function() {
			}
		});
		*/

		// init Promotion banners
		Ns.Ajax.request(promotions, {
			method : 'get',
			onSuccess : function(res) {
				try {
					NGNB.initPromotions(res.getElementsByTagName('Item'));
				}
				catch (e) {}
			},
			onFailed : function() {
			}
		});

		// min-width fix for ie ( 998px )
		if (doc.all) {
			var ngnb = doc.getElementById('ngnb');
			var body = !doc.compatMode || doc.compatMode.indexOf('CSS1') == -1 ? doc.body : doc.documentElement || doc.body;
			Ns.Event.add(window, 'resize', function() { ngnb.style.width = Math.max(998, body.clientWidth) + 'px' });
			ngnb.style.width = Math.max(998, body.clientWidth) + 'px';
		}
	
	},

	clearXML : function(nodes)
	{
		for (var i = 0, n; n = nodes[i]; i++) if (n.nodeType != 1) n.parentNode.removeChild(n);
		return nodes;
	},
/*
	initGames : function(items)
	{
		NGNB.clearXML(items);
		var len = items.length;
		var target = document.getElementById('ngnb-games-div');

		for (var i = 0; i < len; i++) {
			var infos = NGNB.clearXML(items[i].childNodes);
			var titKr = infos[1].firstChild.nodeValue;
			var img = infos[2].firstChild.nodeValue.replace('http://', NGNB.http);
			var url = infos[3].firstChild.nodeValue;
			var tgt = infos[4].firstChild.nodeValue;
			var dd = document.createElement('dd');
			dd.innerHTML = '<a href="'+url+'" target="'+tgt+'" title="'+titKr+' 웹사이트 바로가기">'+titKr+'</a>';
			target.appendChild(dd);
			dd = null;
		}

		// 게임목록수가 홀수일시 빈 게임목록 영역 추가
		if ( len % 2 == 1 ) {
			var dummy = document.createElement('dd');
			with (dummy.style) {
				width = "144px";
				height = "40px";
				background = "#ffffff";
			}
			target.appendChild(dummy);
		}

	},
*/

	initPromotions : function(items)
	{
		NGNB.clearXML(items);
		var len = items.length;
		var target = document.getElementById('ngnb-promotions');
		var add = function(item) {
			var infos = NGNB.clearXML(item.childNodes);
			var img = infos[0].firstChild.nodeValue.replace('http://', NGNB.http);
			var url = infos[1].firstChild.nodeValue;
			var desc = infos[2].firstChild.nodeValue;
			var method = infos[3] ? infos[3].firstChild.nodeValue : '';
			var span = document.createElement('span');
			span.innerHTML = '<a href="'+url+'" target="'+method+'"><img src="'+img+'" width="170" height="47" alt="" title="'+desc+'" /></a>';
			target.appendChild(span);
			span = null;
		}

		if (len == 1) {
			// 배너가 1개면 롤링 중지
			add(items[0]);
			return;
		} else {
			// 배너가 여러개일경우 자연스러운 롤링을 위해 첫번째 배너를 복사하여 마지막에 추가로 삽입
			for (var i = 0; i < len; i++) {
				add(items[i]);
			}
			add(items[0]);
		}

		var count = Math.ceil(target.scrollWidth / 170) , now = 1, sp, ep, loop;
		setInterval(function()
		{
			if (now == count) target.scrollLeft = 0, now = 1;
			ep = 170 * now++;
			loop = setInterval(function() {
				sp = target.scrollLeft;
				if (sp == ep) clearInterval(loop);
				target.scrollLeft += Math[sp < ep ? 'ceil' : 'floor']((ep-sp)/7);
			}, 15);
		}, 4000);

	}
};

NGNB.Write();
