
function T3funGnb() {
    this._domain = "http://admin.t3fun.com";
    this._imagePath = "http://www.t3fun.com/images/gnb/";    
    this._xmlnamespace = "http://www.t3fun.com/Service";
    this._url = "http://www.t3fun.com/Service/Promotion.asmx";
    this._tPreviewGameOpen = null;
    this._divGameId = "divGnbGameList";
    this._divAdBannerId = "AdBanner";
  
    this._isComplete = false;
    this._response = new Object();    
};

T3funGnb.prototype.init = function() 
{    
    this.createStyle();
    this.createDiv("divT3funGnb", this.getGnbTable(), "GolbalTopGnb");
    this.getPromotion(0, t3funGnbHandler.setGnbBanner, 5020, 1, true, 1); 
};

T3funGnb.prototype.createStyle = function() {
    var sheet = new CssStyleSheet();
    sheet.addRule(".GolbalTopGnb .GolbalGnbWarp .GolbalGnbLh .GolbalOpenMenu", "margin:0; padding:0;");
    sheet.addRule(".GolbalTopGnb", "position:relative; width:100%; height:33px; background:url('" + this._imagePath + "bg_gnb.gif') left top repeat-x; z-index:999; ");
    sheet.addRule(".GolbalTopGnb .GolbalGnbWarp", "position:relative; width:876px; height:28px; margin:0 auto; padding:5px 0 0 8px; z-index:999;");
    sheet.addRule(".GolbalGnbWarp .bi", "float:left; width:39px; height:20px; margin:0 38px 0 0; ");
    sheet.addRule(".GolbalGnbWarp .bi a","display:block; width:39px; height:20px; background:url('" + this._imagePath + "gnb_img_set.jpg') 0 0 no-repeat; overflow:hidden; text-indent:-10000em; font:normal 0/0 verdana;");
    sheet.addRule(".GolbalGnbLh","float:left; }");
    sheet.addRule(".GolbalGnbLh dd","float:left; height:9px; margin:7px 7px 0 0; padding:0 0 0 10px; background:url('"+this._imagePath+"bg_v_bar.gif') 0 0 no-repeat;");
    sheet.addRule(".GolbalGnbLh .nChd","padding:0;");
    sheet.addRule(".GolbalGnbLh dd a","display:block; height:9px; background-image:url('"+this._imagePath+"gnb_img_set.jpg'); background-repeat:no-repeat; overflow:hidden; text-indent:-10000em; font:normal 0/0 verdana;");
    sheet.addRule(".GolbalGnbLh .games a","width:33px; background-position:0 -25px;");
    sheet.addRule(".GolbalGnbLh .forums a","width:28px; background-position:0 -35px;");
    sheet.addRule(".GolbalGnbLh .support a","width:44px; background-position:0 -45px;");
    sheet.addRule(".GolbalRhBtn","float:right; margin:6px 0 0 0;");
    sheet.addRule(".GolbalRhBtn a","float:left; display:inline; height:13px; background-image:url('"+this._imagePath+"gnb_img_set.jpg'); background-repeat:no-repeat; overflow:hidden; text-indent:-10000em; font:normal 0/0 verdana;");
    sheet.addRule(".GolbalRhBtn .myAcc","width:60px; background-position:-55px -45px;");
    sheet.addRule(".GolbalRhBtn .logOut","width:41px; margin:0 0 0 6px; background-position:-55px -30px;");
    sheet.addRule(".GolbalRhBtn .signUp","width:46px; background-position:-55px 0;");
    sheet.addRule(".GolbalRhBtn .logIn","width:41px; margin:0 0 0 6px; background-position:-55px -15px;");
    sheet.addRule(".GolbalMenuWrap","position:absolute; top:33px; left:63px; padding:2px; background:#fff; border:1px solid #d2d2d2; border-top:0 none; z-index:999;");
    sheet.addRule(".GolbalMenuWrap .GolbalOpenMenu","width:70px; padding:0 5px; background:#ebebeb url('"+this._imagePath+"bg_openMenu.jpg') left top no-repeat;");
    sheet.addRule(".GolbalOpenMenu dt","overflow:hidden; text-indent:-10000em; font:normal 0/0 verdana;");
    sheet.addRule(".GolbalOpenMenu dd","margin:4px 0 0 0; padding:0 0 4px 0; border-bottom:1px solid #d2d2d2;");
    sheet.addRule(".GolbalOpenMenu dd a","font-size:11px; color:#666; font-family:Tahoma; text-decoration:none;");
    sheet.addRule(".nChd","background:none; border:0 none !important;");
    sheet.addRule(".gameBanner", "float:right;margin:0 5px 0 0;");
    sheet.addRule(".gameBanner img", "border:0 none;");
};

T3funGnb.prototype.createDiv= function(id, innertag, style) {
    var divObj = this.createTag("div",id, style);
    divObj.innerHTML = innertag;
    divObj.className = style;
    document.body.insertBefore(divObj, document.body.firstChild);
};

T3funGnb.prototype.createTag = function(tag, id) {
    var ret = document.createElement(tag);
    ret.setAttribute("id", id);
    ret.setAttribute("name", id);
    return ret;
};

T3funGnb.prototype.displayGame= function (id, bShow) {
    document.getElementById(id).style.display = bShow ? 'block' : 'none';
};

T3funGnb.prototype.gameOpen = function(id) {
	clearTimeout(this._tPreviewGameOpen);	
	this._tPreviewGameOpen = setTimeout('t3funGnbHandler.displayGame(\"'+ id +'\", true);', 0);
};

T3funGnb.prototype.gameClose = function(id) {
	clearTimeout(this._tPreviewGameOpen);
	this._tPreviewGameOpen = setTimeout('t3funGnbHandler.displayGame(\"'+ id +'\", false);',300);
};

T3funGnb.prototype.getGnbTable= function() {
    var getGameMouseEvent= function(id) {
        return "onmouseover='t3funGnbHandler.gameOpen(\"" + id + "\");' onmouseout='t3funGnbHandler.gameClose(\"" + id + "\");'";
    };
    var ret = "";
    ret +="<script type='text/javascript'>";
    ret +=" try { document.execCommand(\"BackgroundImageCache\",false,true) } catch (e) {};";
    ret +="</script>";
    ret +="<div style='width:100%; height:33px; padding:0; margin:0;'>";
    ret +=" <div class='GolbalTopGnb'>";
    ret +="		<div class='GolbalGnbWarp'>";
    ret +="			<dl class='GolbalGnbLh'>";
    ret +="				<dt class='bi'><a href='http://www.t3fun.com'>T3FUN</a></dt>";
    ret +="				<dd class='games nChd'><a href='http://www.t3fun.com' title='GAMES' " + getGameMouseEvent(this._divGameId) +">GAMES</a></dd>";
//  ret +="				<dd class='forums'><a href='http://forum.t3fun.com' title='FORUMS'>FORUMS</a></dd>";
    ret +="				<dd class='forums'><a href='http://www.t3fun.com/TCash/Payment.aspx' title='TCOIN' target='_blank' );\">TCOIN</a></dd>";
    ret +="				<dd class='support'><a href='http://www.t3fun.com/Support/Faq_List.aspx' title='SUPPORT'>SUPPORT</a></dd>";
    ret +="			</dl>";
    ret +="			<div class='GolbalRhBtn'>";   
    
    if(this.isAuthenticated())
    {    
        ret +="				<a href='http://www.t3fun.com/MemberShip/User_ModifyCheck.aspx' class='myAcc' title='MY ACCOUNT'>MY ACCOUNT</a>";
        ret +="				<a href='javascript:RequestLogout();' class='logOut' title='LOGOUT'>LOG OUT</a>";
    }
    else    
    {
        ret +="				<a href='http://www.t3fun.com/MemberShip/SignUp_01.aspx' class='signUp' title='SIGN UP'>SIGN UP</a>";
        ret +="				<a href='http://www.t3fun.com/MemberShip/Login.aspx' class='logIn' title='LOG IN'>LOG IN</a>";
    }
    ret +="			</div>";
    ret +="     <div class='gameBanner'>";
		ret +="       <img id='"+ this._divAdBannerId +"' src='http://www.t3fun.com/images/gnb/bg_gnb.gif' alt='' valign='top' height='23' style='cursor:hand'  />";
		ret +="			</div>";
    ret +="			<div class='GolbalMenuWrap' id='" + this._divGameId + "' style='display:none;'" + getGameMouseEvent(this._divGameId) +">";
    ret +="				<dl class='GolbalOpenMenu'>";    
    ret +="					<dt>Games</dt>";
//    ret +="					<dd><a href='http://aika.t3fun.com'>AIKA GLOBAL</a></dd>";
    ret +="					<dd><a href='http://wyd.t3fun.com'>WYD</a></dd>";
    ret +="					<dd><a href='http://camon.t3fun.com'>CARDMON HERO</a></dd>";
    ret +="					<dd><a href='http://hellgate.t3fun.com'>HELLGATE</a></dd>";
    ret +="					<dd><a href='http://mythos.t3fun.com'>MYTHOS</a></dd>";
    ret +="					<dd class='nChd'><a href='http://www.t3fun.com/GameInfo/GrandMer.aspx?Game=Grandmer'>Coming Soon</a></dd>";    
    ret +="				</dl>";
    ret +="			</div>";
    ret +="		</div>";    
    ret +="	</div>";
    ret +="</div>";
    
    return ret;
};

T3funGnb.prototype.isAuthenticated = function() {
    return (xmlHttpRequest.getcookie("UserID") != "" && xmlHttpRequest.getcookie("t3funinfo") !="" && xmlHttpRequest.getcookie("t")) ? true : false;
};

T3funGnb.prototype.setGnbBanner= function() { 
    t3funGnbHandler.setBanner(0, document.getElementById('AdBanner'));
    t3funGnbHandler._isComplete= true;    
};

T3funGnb.prototype.setBanner= function(index, obj) {     
    try {
    
      var response = t3funGnbHandler._response.responseText;       
	    if (response == 'undefined') 
	        return;
	 
	    var res = xmlHttpRequest.createDocument(response);
	    if(res.getElementsByTagName('Promotion').length == 0)
	    {
	        obj.style.display = 'none';
	        return;
	    }
	    obj.src = t3funGnbHandler._domain + xmlHttpRequest.getNode(res, 'Image');
	    var url = xmlHttpRequest.getNode(res, 'Url'); 
	    url = url + ((url.indexOf("?") > 0) ? "&" : "?") + "Game=" + this._game + "&Name=" + xmlHttpRequest.getNode(res, 'MainCopy');
	    obj.onclick = function() {t3funGnbHandler.goUrl(url, parseInt(xmlHttpRequest.getNode(res, 'Target')))};
	    obj.style.display = 'block';
	} catch(e) { obj.style.display = 'none'; }
};

T3funGnb.prototype.goUrl= function(url, target, width, height) {
	if (url.substring(0, 7) != 'http://' &&  url.substring(0, 8) != 'https://')
	    url = 'http://' + url;   
	
	if(target == "2")
	  window.open(url,"_blank","");
	else
	  top.location.href = url;
};

T3funGnb.prototype.check = function()
{
    while(!xmlHttpRequest.checkFlash) this.wait(100);
};

T3funGnb.prototype.wait = function(msecs)
{
    var start = new Date().getTime();
    var cur = start;
    while(cur - start < msecs)
        cur = new Date().getTime();
};

T3funGnb.prototype.getPromotion= function(index, onComplate, classKey, codeKey, random, number) {   
   
    if(this._isComplete) 
        return;
    try {
          this.check();         
          var paramNames = ["classKey", "codeKey", "random", "number"];        
          var paramValues = [classKey, codeKey, random, number];        
          var soapMessage = xmlHttpRequest.createSoap(this._xmlnamespace, "Get", paramNames, paramValues);          
          this._response.responseLoad = onComplate;                                 
          xmlHttpRequest.send(this._response, this._url, this._xmlnamespace + "/Get", soapMessage);        
    } 
    catch (e) {        
        setTimeout("t3funGnbHandler.getPromotion(" + index + ", " + onComplate + ", " + classKey + ", " + codeKey + ", " + random + ", " + number + ")", 1000);
    }
};

var t3funGnbHandler = new T3funGnb();
t3funGnbHandler.init();
