﻿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 = "【新消息】— 591UP(BETA)";
            else
                window.document.title = "【　　　】— 591UP(BETA)";
            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 + ")";

                $('li.msgCount span').html(msgCount);
                msgNotify();
            }
            else {
                if (gblTimer1 != null)
                    clearTimeout(gblTimer1);
                if (gblTimer2 != null)
                    clearInterval(gblTimer2);
            }
        }
    });
}