(function (jQuery){
/*
 * jQuery Plugin - Messager
 * Author: corrie	Mail: corrie@sina.com	Homepage: www.corrie.net.cn
 * Copyright (c) 2008 corrie.net.cn
 * @license http://www.gnu.org/licenses/gpl.html [GNU General Public License]
 *
 * $Date: 2008-08-30 
 * $Vesion: 1.1
 @ how to use and example: Please Open demo.html
 */
	this.version = '@1.1';
	this.layer = {'width' : 220, 'height': 120};
	this.title = '站内消息';
	this.times = 4000;
	this.anims = {'type' : 'slide', 'speed' : 600};
	this.timeout='';
	this.IsIe=!!document.all;
	this.inits = function(title, text, infolength ,idstring){
		if($("#message").is("div")){ return; }
		$(document.body).prepend('<div id="message" style="border:#b9c9ef 1px solid;z-index:120;width:'+this.layer.width+'px;height:'+this.layer.height+'px;position:absolute; display:none;background:#cfdef4; bottom:0; right:0; overflow:hidden;"><div style="border:1px solid #fff;border-bottom:none;width:100%;height:45px;font-size:12px;overflow:hidden;color:#1f336b;"><span id="message_close" style="float:right;padding:5px 0 5px 0;width:16px;line-height:auto;color:red;font-size:12px;font-weight:bold;text-align:center;cursor:pointer;overflow:hidden;"><img src="/image/EXIT_X.gif" width="13" height="13" border="0" alt="关闭"></span><div style="padding:5px 5px 5px 5px;width:auto;line-height:38px;text-align:left;overflow:hidden;float:left;"><img src="/images/msg_logo.gif" width="144" height="30" border="0" style="margin-bottom:-8px">'+title+'</div><div style="clear:both;"></div></div> <div style="padding-bottom:5px;border:1px solid #fff;border-top:none;width:100%;height:auto;font-size:12px;"><div id="message_content" style="margin:0 5px 0 5px;border:#999 1px solid;padding:10px 0 10px 5px;font-size:12px;width:'+(this.layer.width-17)+'px;height:'+(this.layer.height-90)+'px;color:#1f336b;text-align:left;overflow:hidden;">'+text+'</div><div style="text-align:left;color:#000">&nbsp;&nbsp;<input id="message_ck" type="checkbox" value="'+idstring+'" />不再显示该 <font color=\"red\">' + infolength + '</font>  条新消息</div></div></div>');
	};
	
	
	
	
	this.show = function(title, text, infolength, idstring , times,width, height){
		if($("#message").is("div")){ return; }
		if(title==0 || !title)title = this.title;
		this.lays(width, height);
		this.inits(title, text, infolength,idstring);
		this.pos();
		if(times)this.times = times;
		switch(this.anims.type){
			case 'slide':$("#message").slideDown(this.anims.speed);break;
			case 'fade':$("#message").fadeIn(this.anims.speed);break;
			case 'show':$("#message").show(this.anims.speed);break;
			default:$("#message").slideDown(this.anims.speed);break;
		}
		$("#message_close").click(function(){		
			setTimeout('this.close()', 1);
		});
		$("#message_ck").click(function(){
			//alert($("#message_ck").attr("checked")+$("#message_ck").val())
			setCookies() ;
			setTimeout('this.close()', 1);
		});
		//$("#message").slideDown('slow');
		var timeoutobj,timeoutnum;
		timeoutnum=this.times;
		//timeoutobj=setTimeout('this.close()', this.times);
		//$("#message").mouseover(function(){clearTimeout(timeoutobj);});
		$("#message").mouseout(function(){
			var out=true;
			//$("#message > a").focus(function(){out=false;clearTimeout(timeoutobj);})
			//if(out) timeoutobj=setTimeout('this.close()', timeoutnum);
			});
		$(window).scroll(function(){this.pos()});
	};
	
	
	
		
	this.pos =function(){
		$("#message").css({'bottom':0-$(document).scrollTop(),'right':0-$(document).scrollLeft()});
		};
	
	this.lays = function(width, height){
		if($("#message").is("div")){ return; }
		if(width!=0 && width)this.layer.width = width;
		if(height!=0 && height)this.layer.height = height;
	}
	this.anim = function(type,speed){
		if($("#message").is("div")){ return; }
		if(type!=0 && type)this.anims.type = type;
		if(speed!=0 && speed){
			switch(speed){
				case 'slow' : ;break;
				case 'fast' : this.anims.speed = 200; break;
				case 'normal' : this.anims.speed = 400; break;
				default:					
					this.anims.speed = speed;
			}			
		}
	}
	this.rmmessage = function(times){
		//this.timeout=setTimeout('this.close()', times);
		//setTimeout('$("#message").remove()', times+1000);
	};
	this.close = function(){
		switch(this.anims.type){
			case 'slide':$("#message").slideUp(this.anims.speed);break;
			case 'fade':$("#message").fadeOut(this.anims.speed);break;
			case 'show':$("#message").hide(this.anims.speed);break;
			default:$("#message").slideUp(this.anims.speed);break;
		};
		setTimeout('$("#message").remove();', this.anims.speed);
		this.original();
	};
	this.original = function(){	
		this.layer = {'width' : 200, 'height': 100};
		this.title = '信息提示';
		this.times = 4000;
		this.anims = {'type' : 'slide', 'speed' : 600};
	};
    jQuery.messager = this;
    return jQuery;
})(jQuery);

function setCookies(){
		var ids=$("#message_ck").val()
		jQuery.ajax({type:"GET",contenttype :"application/x-www-form-urlencoded;charset=utf-8", url:"/message.asp",dataType:"html",data:"ac=setcookie&idstr="+ids,beforeSend:function(XMLHttpRequest){},success:function(msg){}, complete:function(XMLHttpRequest,textStatus){}, error:function(){ alert('adsf')}});
		
}

function chkmsg()
{
	jQuery.ajax({type:"GET",contenttype :"application/x-www-form-urlencoded;charset=utf-8", url:"/message.asp?",dataType:"xml",data:"",beforeSend:function(XMLHttpRequest){},success:function(msg){parseResults(msg);}, complete:function(XMLHttpRequest,textStatus){}, error:function(){ }});
}
 
jQuery(document).ready(function(){
	chkmsg();
});
 
function parseResults(xmlDOM) {   
try{
	var root = xmlDOM.documentElement; 
	var info = root.getElementsByTagName('message'); 
	var out  = "";   
	var message = null;   
	var current = null; 
	var idstr="";
	if(info.length>0){
		if(info.length==1){
			var message = info[0]; 
			var sender= message.getElementsByTagName("sender")[0].firstChild.data; 
			var id = message.getElementsByTagName("id")[0].firstChild.data; 
			var mid = message.getElementsByTagName("mid")[0].firstChild.data; 
			var tt = message.getElementsByTagName("title")[0].firstChild.data;
			var dt = message.getElementsByTagName("time")[0].firstChild.data;
			out="<font color=\"red\">" + sender + "</font> 给你发送了一条短消息:<BR>"+"<a style=\"font-size:12px; color: #6D93C8; face: Tahoma\" title='内容提要：\n" +tt +"\n\n发送时间："  +dt +"'"+" href='/myindex.asp?f=msg&ac=read&id="+mid+"' >"  +tt +"</a><BR>";
			idstr=idstr + "|" + mid
		}
		else{
			out="你收到了 <font color=\"red\">" + info.length + "</font>  条新的短消息，请注意查收：<BR>"
			var topn=6;
			if (info.length<topn) topn=info.length
			for(var i=0;i<topn;i++){   
				var message = info[i];   
				var id = message.getElementsByTagName("id")[0].firstChild.data;  
				var mid = message.getElementsByTagName("mid")[0].firstChild.data;  
				var tt = message.getElementsByTagName("title")[0].firstChild.data;
				var dt = message.getElementsByTagName("time")[0].firstChild.data;
				var sender= message.getElementsByTagName("sender")[0].firstChild.data; 
				  out=out+"&nbsp;<img src='/images/top"+(i+1)+".gif' width='14' height='13' style='margin-bottom:-3px'>&nbsp;"+"<a style=\"font-size:12px; color: #6D93C8; face: Tahoma\" title='发送人："  
				  +sender +"\n发送时间："  +dt +"'"+" href='/myindex.asp?f=msg&ac=read&id="+mid+"' >"  +tt  +"</a><BR>";   
			   	idstr=idstr + "|" + mid
			   } 
		}
		 // getMsg("<BR>"+out);  
		 jQuery.messager.show(0,out+"<BR>",info.length,idstr,6000,250,200);
		 setTimeout('chkmsg()',50000);
		
	  }
}
  
 catch(exception){   
 //     alert("出错了！");   
    }    
}   
