var _awoo_title = window.document.title;
var _awoo_new_title = null;

var windowTitleStatus = function(){
	if(window.document.title.indexOf('【')!=-1){
		if(window.document.title.indexOf('新的')!=-1 ){
			 window.document.title = "【　　　】 - " + _awoo_title;
		}else{
			 window.document.title = "【"+_awoo_new_title+"】 - " + _awoo_title;
		}
		window.setTimeout(windowTitleStatus, 1000);
	}
}

var getAppRequest = function() {
			var url = cgi.wwwURL + "/user/getAppStat.html?" + Math.random();
			var getDataURL = url+"&callback=appRes";
			headEle = document.getElementsByTagName("head").item(0);
			scriptEle = document.createElement("script");
			scriptEle.setAttribute("type", "text/javascript");
			scriptEle.setAttribute("src", getDataURL);
			headEle.appendChild(scriptEle);
}

function appRes(obj) {
	_awoo_new_title = appStatTitle(obj);
	if(_awoo_new_title!=''){
		window.document.title = "【"+_awoo_new_title+"】 - " + _awoo_title;
		windowTitleStatus();
	}else{
		 window.document.title = _awoo_title;
	}
}


var getAppStat = function(){
	window.setTimeout(getAppStat ,1000*60);
	getAppRequest();
}

var appStatTitle = function(obj){
	var a = '';
	var b = '';
	if(obj.pokeNum>0){
		a += '招呼 ';
		b += '<span class="iconLine icon-poke"><a href="'+cgi.wwwURL+'/poke/pokeList.html">'+obj.pokeNum+'个招呼</a></span>';
	}
	if(obj.sysMsgNum>0){
		a+= '提醒 ';
		b += '<span class="iconLine icon-sysMsg"><a href="'+cgi.wwwURL+'/msg/message.html?box=sys">'+obj.sysMsgNum+'个提醒</a></span>';
	}
	if(obj.friendRequestNum>0){
		a+= '好友申请 ';
		b += '<span class="iconLine icon-addFriends"><a href="'+cgi.friendURL+'/penddingRequest.html">'+obj.friendRequestNum+'个好友邀请</a></span>';
	}
	if(obj.remindNum>1){
		a+= '留言及回复 ';
		var div = document.getElementById('remindListDiv');
		if(obj.remindNum==2&&null!=div){
			getRemindList();
		}
	}
	if(obj.msgNum>0){
		a+= '小纸条 ';
		var img = document.getElementById('xztiaoImg');
		var span = document.getElementById('xztiaoSpan');
		img.src = cgi.pageURL+'/images/commons/zhanneiyoujian.gif';
		span.innerHTML = '<span>小纸条'+obj.msgNum+'</span>';
		var chatMsgCount = document.getElementById('chat_msg_count');
		if(null!=chatMsgCount){
			chatMsgCount.innerHTML = obj.msgNum;
			chatMsgCount.style.display = '';
		}
	}
	if(a!=''){
		a = '新的'+a;
	}

	if(b!=''){
		b = '<div class="noticeBox" style="margin:10px 0px;">'+b+'</div>';
	}
	var div = document.getElementById('userAppStatDiv');
	if(null!=div&&b!=''){
		div.innerHTML = b;
		div.style.display = '';
	}
	return a;
}

var getRemindList = function(){
	var url = cgi.wwwURL + "/remind/getRemindListAjax.html?" + Math.random();
	var getDataURL = url+"&callback=remindListRes";
	headEle = document.getElementsByTagName("head").item(0);
	scriptEle = document.createElement("script");
	scriptEle.setAttribute("type", "text/javascript");
	scriptEle.setAttribute("src", getDataURL);
	headEle.appendChild(scriptEle);
}

function remindListRes(obj){
	if(obj!=null&& obj.remindList.length>0){
		var list = obj.remindList;
		var a = '<div  class="noticeBox"><div class="middleBoxTitle">最新留言及评论</div><ul class="noticeCenter">';
		for(var i=0;i<list.length;i++){
			a += '<li id="remind'+list[i].id+'"><span class="rightBlock"><a class="j a_delete_remind remind_id_'+list[i].id+' grayLink" href="#" title="删除">X</a></span>'+list[i].body+'</li>';
		}
		a += '</ul></div>';
		var div = document.getElementById('remindListDiv');
		div.innerHTML = a;
		div.style.display = '';
		load_event_monitor($('#remindListDiv'));
	}
}



