﻿//v2.5
document.domain = "365ub.com";
var strLength = function(str) {
    var charset = document.characterSet == undefined ? document.charset : document.characterSet;

    var len = 0;
    for (var i = 0; i < str.length; i++) {
        len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset.toUpperCase() == "UTF-8" ? 3 : 2) : 1;
    }
    return len;
}
//function to get a cookies
function GetCookie(cookieName, keyName) {
    if (document.cookie.length > 0) {
        var re = new RegExp((keyName ? cookieName + "=(.*?&)*?" + keyName + "=(.*?)(&|;)" : cookieName + "=(.*?);"), "i");
        return re.test(decodeURIComponent(document.cookie)) ? (keyName ? RegExp["$2"] : RegExp["$1"]) : "";
    }
    else {
        return "";
    }
}

function GetCookieUpal(cookieName, keyName) {
    if (document.cookie.length > 0) {
    	try{
	    	var recookiename=new RegExp(cookieName+'=([^;]+);?','i');
	    	var rekeyName=new RegExp(keyName+'=([^&]+)','i');
	    	var values=document.cookie.match(recookiename)[1];
	    	if(keyName)
	    	{
	    		var value=decodeURIComponent(values).match(rekeyName)[1];
	    		return value;
	    	}
			else
			{
					return values;
			}
		}catch(e){
			return "";
		}
    }
    else {
        return "";
    }
}

// function to set a cookie
function SetCookie(name, value) {
    expires = new Date();
    expires.setTime(expires.getTime() + (1000 * 86400 * 365));
    document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}


// function to delete a cookie
function DelCookie(name) {
    var expireNow = new Date();
    document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}
var userId = GetCookieUpal("Upal_COOKIES", "UpalUserId");
var strUserName = (GetCookieUpal("Upal_COOKIES", "UpalUserName"));
var strNickName = (GetCookieUpal("Upal_COOKIES", "UpalNickName"));
var tophtml = '<div id="top_main\">'+
        '<div id=\"top_nav\">'+
            '<div class=\"top_inner\">'+
                '<a href=\"http://www.365ub.com/\" class=\"top_logo\">365游宝</a>'+
                '<ul class=\"top_list\">'+
                    '<li class=\"top_reg\">' + '<a href=\"http://www.365ub.com/\">首页</a></li>' +
                     '<li class=\"top_catalog\" id=\"top_catalog\">游戏'+
                        '<div id=\"top_show\">'+
                            '<div class=\"top_outer\">'+
                                '<div class=\"top_inner\">'+
                                    '<h2> 运营中的游戏</h2>'+
                                    '<ul class=\"top_listing \">'+
                                       '<li class=\"top_fswd\"><a href=\"http://fswd.365ub.com/\" target=\"_blank\">封神无敌</a></li>'+
										'<li class=\"top_wszm\"><a href=\"http://wszm.365ub.com/\" target=\"_blank\">我是掌门</a></li>'+
										'<li class=\"top_wlzw\"><a href=\"http://wlzw.365ub.com/\"  target=\"_blank\">武林之王</a></li>' +
										'<li class=\"top_frxz2\"><a href=\"http://frxz2.365ub.com/\" target=\"_blank\">凡人修真2</a></li>' +
										'<li class=\"top_frxz\"><a href=\"http://frxz.365ub.com/\" target=\"_blank\">凡人修真</a></li>' +
										'<li class=\"top_hmlt\"><a href=\"http://hmlt.365ub.com/\"  target=\"_blank\">虹猫蓝兔</a></li>' +
										'<li class=\"top_lj\"><a href=\"http://long.365ub.com/\"  target=\"_blank\">龙将</a></li>' +
                                    '</ul>'+
                                    '<div id=\"top_line\">'+
                                    '</div>'+
                                    '<h2>测试中的游戏</h2>'+
                                    '<ul class=\"top_listing top_listing-no\">'+
                                        '<li class=\"top_mhfs\"><a href=\"http://mhfs.365ub.com/\"  target=\"_blank\">梦幻封神</a></li>' +
                                        '<li class=\"top_fswd2\"><a href=\"http://fswd2.365ub.com/\"  target=\"_blank\">封神无敌2</a></li>' +
                                    '</ul>'+                                    
                                '</div>'+
                            '</div>'+
                            '<div class=\"top_bot\">'+
                            '</div>'+
                        '</div>'+
                    '</li>'+
                    '<li class=\"top_catalog1\" id=\"top_catalog1\">服务' +
                        '<div id=\"top_show1\">'+
                            '<div class=\"top_outer\">'+
                                '<div class=\"top_inner\">'+
                                    '<ul class=\"top_listing1\">'+
                                        '<li class=\"top_smrz\" ><a href=\"http://passport.365ub.com/realname.aspx\">实名认证</a></li>' +
                                        '<li class=\"top_sjbd\" ><a href=\"http://passport.365ub.com/BindPhone.aspx\">手机绑定</a></li>'+
                                    '</ul>'+
                                    '<div id=\"top_line_1\">'+
                                    '</div>'+
                                    '<ul class=\"top_listing1 \">'+
                                        '<li class=\"top_zfzx\"><a href=\"http://pay.365ub.com/\">支付中心</a></li>'+
                                        '<li class=\"top_aqzx\"><a href=\"http://passport.365ub.com/\">安全中心</a></li>'+
                                        '<li class=\"top_kfzx\"><a href=\"http://cs.365ub.com/\">客服中心</a></li>'+
                                    '</ul>'+
                                '</div>'+
                            '</div>'+
                            '<div class=\"top_bot\">'+
                            '</div>'+
                        '</div>'+
                    '</li>' +
                    '<li class="top_catalog2" id="top_catalog2">最新开服'+
	                    '<div id="top_show2"> '+
       	                    '<div class="top_outer">'+ 
           	                    '<div class="top_inner" >'+ 
				                    '<ul class="top_listing2">'+//'<li >07-15<a href="#" >我是掌门</a><a href="#" >24区</a></li>'+
				                    '</ul>'+
			                    '</div>'+
                            '</div>'+
		                    '<div class="top_bot"></div>'+ 
                        '</div>'+
                    '</li>' +
                    '<li class="top_jiankong"><a href="http://www.365ub.com/jiazhang/index.html" target="_blank">家长监控</a></li>' +
                '</ul>' +
                '<div id=\"top_info\">'+ //登录状态切换                    
                '</div>'+
            '</div>'+
        '</div>'+
    '</div>';


document.write(tophtml);
(function($) {
    var msgInfo = function() {
        var getMsgUrl = "http://www.365ub.com/MsgInviteCount.ashx?userid=" + userId + "&v=" + Math.random() + "&jsoncallback=?";
        $.getJSON(getMsgUrl, null, function(data) {
            if (data != null) {
                if (data.MsgCount > 0) {
                    var msgURL = '';
                    msgURL += data.MsgCount
                    msgURL += '条新消息 <a href="http://www.365ub.com/messageinbox.aspx" >查看消息</a>';
                    $("#msginbox").poshytip({
                        className: 'tip-yellowsimple',
                        content: msgURL,
                        alignTo: 'target',
                        alignX: 'center',
                        alignY: 'bottom',
                        offsetX: 0,
                        offsetY: 5
                    }).poshytip("hide").poshytip("show");
                }
                else {
                    $("#msginbox").poshytip("hide");
                }

            }
        });
    };
    var userInfo = function() {
        userId = GetCookieUpal("Upal_COOKIES", "UpalUserId");
        strUserName = (GetCookieUpal("Upal_COOKIES", "UpalUserName"));
        strNickName = (GetCookieUpal("Upal_COOKIES", "UpalNickName"));
        //已登录
        if (strNickName != "" && strLength(strNickName) >= 4) {
            userHtml = '<table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">' +
                    '<tr>' +
                        '<td width=\"20\" height=\"41\" align=\"left\" valign=\"middle\">' +
                            '&nbsp;' +
                        '</td>' +
                        '<td width=\"150\" align=\"right\" valign=\"middle\"  height="41" ><a class="top_logout" href="http://passport.365ub.com/RealName.aspx">' + strNickName + '</a></td>' +
                        '<td width=\"40\" align=\"left\" valign=\"middle\">' +
                            '<a href="http://www.365ub.com/messageinbox.aspx" class="top_logout" id="msginbox">消息</a>' +
                        '</td>' +
                        '<td width=\"40\" align=\"left\" valign=\"middle\">' +
                            '<a href=\"http://passport.365ub.com/logout.aspx?returnUrl=' + escape(returnUrl()) + '\" class=\"top_logout\">退出</a>' +
                        '</td>' +
                    '</tr>' +
                '</table>';
            $("#top_info").empty().append(userHtml);
            //每1分钟获取一次未读站内信。
            msgInfo();
            setInterval(msgInfo, 6000);
        }
        else {//未登录
            userHtml = '<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">' +
                        '<tr>' +
                            '<td align=\"left\" valign=\"middle\">&nbsp;</td>' +
                            '<td width=\"60\" height=\"41\" align=\"left\" valign=\"middle\">&nbsp;</td>' +
                            '<td width=\"54\" align=\"left\" valign=\"middle\"><a href=\"http://passport.365ub.com/Login.aspx\"><img src=\"http://images.365ub.com/global/top_nav/top_images/top_icon_3.gif\" width=\"54\" height=\"28\" /></a></td>' +
                            '<td width=\"54\" align=\"left\" valign=\"middle\"><a href=\"http://passport.365ub.com/register.aspx\"><img src=\"http://images.365ub.com/global/top_nav/top_images/top_icon_4.gif\" width=\"54\" height=\"28\" /></a></td>' +
                        '</tr>' +
                    '</table>';
            $("#top_info").empty().append(userHtml);
            setTimeout(userInfo, 5000)
            clearInterval(msgInfo);
        }

        //获取最新开服服务器
        $.getJSON("http://www.365ub.com/NewGames.ashx?jsoncallback=?", function(data) {
            if (data.ServerList.length > 0) {
                $('.top_listing2').empty()
                var arryLength = data.ServerList.length - 1
                for (i = arryLength; i >= 0; i--) {
                    $('.top_listing2').append('<li>' + data.ServerList[i].OpenTime + ' <a href="' + data.ServerList[i].WebUrl + '" target="_blank">' + data.ServerList[i].GameName + '</a><a href="http://passport.365ub.com/checklogin.ashx?gameid=' + data.ServerList[i].GameId + '&serverId=' + data.ServerList[i].ServerId + '">' + data.ServerList[i].ServerName + '</a> </li>');
                }
            }
        });
    };

    var returnUrl = function() {
        var currentHost = window.location.host;
        currentHost = currentHost.toLowerCase();
        var url = "http://www.365ub.com"
        if (currentHost == "www.365ub.com") {
            url = "http://www.365ub.com";
        }
        else if (currentHost == "game.365ub.com") {
            url = "http://game.365ub.com";
        }
        else if (currentHost == "passport.365ub.com") {
            url = "http://passport.365ub.com";
        }
        else if (currentHost == "pay.365ub.com") {
            url = "http://pay.365ub.com";
        }
        else if (currentHost == "cs.365ub.com") {
            url = "http://cs.365ub.com";
        }

        return url;
    };

    $(function() {
        userInfo();
        //        $('#msginbox').CreateBubblePopup({manageMouseEvents: false});
    })

    $(function() {
        $("#top_catalog").hover(function() {
            $("#top_catalog").addClass("top_catalog-hover");
            $("#top_catalog").find("#top_show").stop().animate({ show: 'show' }, 600);
        },
		        function() {
		            $("#top_catalog").removeClass("top_catalog-hover");
		            $("#top_catalog").find("#top_show").stop().animate({ show: 'hide' }, 0);
		        }
	        );
    });
    $(function() {
        $("#top_catalog1").hover(function() {
            $("#top_catalog1").addClass("top_catalog1-hover");
            $("#top_catalog1").find("#top_show1").stop().animate({ show: 'show' }, 600);
        },
		        function() {
		            $("#top_catalog1").removeClass("top_catalog1-hover");
		            $("#top_catalog1").find("#top_show1").stop().animate({ show: 'hide' }, 0);
		        }
	        );
    });
    $(function() {
        $("#top_catalog2").hover(function() {
            $("#top_catalog2").addClass("top_catalog2-hover");
            $("#top_catalog2").find("#top_show2").stop().animate({ show: 'show' }, 600);
            window.parent.document.getElementById('cyou-content').style.height = $("#top_show2").outerHeight() + $("#top_catalog2").offset().top + $("#top_catalog2").outerHeight() + 'px';
            //$("#top_catalog").find("#top_show").stop().show();
        },
		function() {
		    $("#top_catalog2").removeClass("top_catalog2-hover");
		    $("#top_catalog2").find("#top_show2").stop().animate({ show: 'hide' }, 0);
		    window.parent.document.getElementById('cyou-content').style.height = '77px'
		}
	);
    })
})(jQuery)
