﻿var originTitle = window.document.title;
var gblTimer1 = null;   //标题闪烁的timer
var gblTimer2 = null;   //字符闪烁的timer
var bshow = true;
var globalSpaceWebRoot = ".";

function msgNotify() {
    if (gblTimer1 == null) {
        gblTimer1 = window.setInterval(function() {
            if (bshow)
                window.document.title = "【新消息】-- 91空间";
            else
                document.title = "【　　　】-- 91空间";
            bshow = !bshow;
        }, 800);
    }
//    if (gblTimer1 == null) {
//        gblTimer1 = window.setTimeout(function() {
//            window.setTimeout(msgNotify, 800);
//        }, 800);
////    }
}

function getmessage(uin) {
    if (globalSpaceWebRoot == "." && $("#globalSpaceWebRoot")) {
        globalSpaceWebRoot = $("#globalSpaceWebRoot").val();
    }    
    $.ajax({ type: "POST", url: "/" + globalSpaceWebRoot + "/h/NewMessageNotify.ashx", data: "uin=" + uin,
        beforeSend: null, dataType: "json",
        success: function(data) {
            //msgObj = json_parse(data);
            var msgCount = parseInt(data.personalMsg) + parseInt(data.sysMsg);
            //            var hasMsg = (data.personalMsg != 0 || data.sysMsg != 0);
                        
            if (msgCount > 0) {
                var myurl = "";
                if (data.personalMsg != 0)
                    myurl = "/m/PersonalMessage.html";
                else
                    myurl = "/m/SystemMessage.html";
                var msghtml = "(" + msgCount + ")";
//                if (document.location.href.indexOf("/m/") != -1) {    //后台
//                    if ($("a#hnewMsg").length == 0) {
//                        $("li.navNews").html("<a id='hnewMsg' href='" + myurl + "' title='查看新消息'>消息" + msghtml + "</a>");
//                        var nma = $("a#hnewMsg");
//                        if (gblTimer2 == null) {
//                            gblTimer2 = window.setInterval(function() {
//                                if (nma.css("color") == "#fff")
//                                    nma.css("color", "#ffaa00");
//                                else
//                                    nma.css("color", "#fff");
//                            }, 500);
//                        }
//                    }
//                }
//                else {      //前台
//                    if ($("a#hnewMsg").length == 0) {
//                        $("div.login").after("<div id='hnewMsg' style='float:right;'><a href='" + myurl 
//                            + "' title='查看新消息'>新消息" + msghtml + "</a></div>");
//                        var nma = $("div#hnewMsg>a");
//                        if (gblTimer2 == null) {
//                            gblTimer2 = window.setInterval(function() {
//                                if (nma.css("color") == "#dadada")
//                                    nma.css("color", "#ffaa00");
//                                else
//                                    nma.css("color", "#dadada");
//                            }, 500);
//                        }
//                    }
//                }
                if ($("a#hnewMsg").length > 0) {
                        $("li.navNews").html("<a id='hnewMsg' href='" + myurl + "' title='查看新消息'>消息" + msghtml + "</a>");
                        var nma = $("a#hnewMsg");
                        if (gblTimer2 == null) {
                            gblTimer2 = window.setInterval(function() {
                                if (nma.css("color") == "#fff")
                                    {nma.css("color", "#ffff00");nma.css("fontWeight","bold");}
                                else
                                    nma.css("color", "#fff");
                            }, 500);
                        }
                    }
                msgNotify();
            }
            else {
                if (gblTimer1 != null)
                    clearTimeout(gblTimer1);
                if (gblTimer2 != null)
                    clearInterval(gblTimer2);
            }
        }
    });
}