﻿( function(jQuery) {
	TopY = 0;//初始化元素距父元素的距离
      this.popmsg = function(width,height,title,content)
      {
		$(document.body).prepend(
			'<div id="popmsgBox" style="display:none;width:'+width+';height:'+height+'px;">' +
			'<div class="title">' +
			'<div class="close"><a href="#"></a></div>' +
			'<div class="caption">'+title+'</div>' +
			'</div>' +
			'<div class="content">'+content+'</div>' +
			'</div>');

		$('#popmsgBox').slideDown(500);//弹出
		$("#popmsgBox .close a").click(function() {//当点击关闭按钮的时候
			if(TopY==0)
			{
				$("#popmsgBox").slideUp(500);//这里之所以用slideUp是为了兼用Firefox浏览器
			}
		    	else
			{
				$("#popmsgBox").animate({top: TopY+height}, "fast", function() { $("#popmsgBox").hide(); });//当TopY不等于0时  ie下和Firefox效果一样
			}
			return false;
      	});

		$(window).scroll(this.reset);
		$(window).resize(this.reset);
	};

	this.reset = function()
	{
         	$("#popmsgBox").css("top", $(window).scrollTop() + $(window).height() - $("#popmsgBox").height() - 6);//当滚动条滚动的时候始终在屏幕的右下角
		TopY=$("#popmsgBox").offset().top;//当滚动条滚动的时候随时设置元素距父原素距离
	}

	jQuery.messager = this;
	return jQuery;
})(jQuery);