var popWindow  = {
	pageWidth:0,
	pageHeight:0,
	windowWidth:0,
	windowHeight:0,
	windows : 0,
	layout:false,
	wins : [],
	getPageSize:function ()//取的页面的宽度和浏览器的看杜
	{
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		//alert(yScroll);
		//alert(windowHeight);
		var pageHeight, pageWidth;
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		this.pageWidth=pageWidth;
		this.pageHeight=pageHeight;
		this.windowWidth= windowWidth;
		this.windowHeight= windowHeight;
	},	
	pop:function(obj)
	{
		this.getPageSize();
		this.layoutF();
		obj.style.display = "block";		
		window.onscroll = function(){popWindow.scroll(obj);};
		popWindow.scroll(obj);
		popWindow.wins.push(obj);
		popWindow.windows++;
		
	},
	scroll:function(obj)//页面的滚动式出发的
	{
		var de = document.documentElement;		
		var scrollX = self.pageXOffset || ( de && de.scrollLeft ) || document.body.scrollLeft;
		var scollY = self.pageYOffset || ( de && de.scrollTop ) || document.body.scrollTop; 
		obj.style.left = (popWindow.windowWidth-obj.offsetWidth)/2 + scrollX + "px";
		obj.style.top = (popWindow.windowHeight-obj.offsetHeight)/2 + scollY + "px";
		obj.style.zIndex = 1000;
	},
	layoutF:function ()//背景
	{
		if(!this.layout)
		{
			this.layout = document.createElement("iframe");
		}
		this.layout.className = "layoutforallpage";
		this.layout.style.width = this.pageWidth + "px";
		this.layout.style.height = this.pageHeight + "px";
		this.layout.style.right = "0px";
		this.layout.style.bottom = "0px";
		this.layout.style.zIndex = 999;
		this.layout.style.MozOpacity = 0.5;
		this.layout.style.KhtmlOpacity = 0.5;
		document.body.appendChild(this.layout);
		this.layout.contentWindow.document.open();
		this.layout.contentWindow.document.write("<BODY bgcolor='#000000'></body>");
		
	},
	close:function(obj,remove)
	{
		 popWindow.windows--;
		if(remove)
		{
			document.body.removeChild(obj);
		}else
		{
			obj.style.display = "none";
		}
		if(this.layout)
		{
			if(popWindow.windows <= 0)
			{
				document.body.removeChild(this.layout);
				this.layout = null;
				this.layout = false;
				window.onscroll = null;
				popWindow.windows = 0;
			}
		}
	},
	closeall:function()
	{
		for(var i = 0 ; i < popWindow.wins.length ; i++)
		{
			if(popWindow.wins[i])
			{
				popWindow.wins[i].style.display = "none";
			}
		}
		popWindow.windows = 0;
		if(this.layout)
		{
			if(popWindow.windows <= 0)
			{
				document.body.removeChild(this.layout);
				this.layout = null;
				this.layout = false;
				window.onscroll = null;
				popWindow.windows = 0;
			}
		}
	},
	alert:function(msg,w,bodyClass)
	{
		var width = w?w:250;	
		var css =  bodyClass ? bodyClass : "body" ;
		var div = document.createElement("div");
		div.style.width = width + "px";
		div.className = "alert_main";	
		div.innerHTML = '<h1>有伴提示<span><img src="/images/album/icon_del.gif" onclick="popWindow.close(this.parentNode.parentNode.parentNode,true);"></span></h1><div class="' + css +  '">'+msg+'</div><div class="action"><button class="button1" onclick="popWindow.close(this.parentNode.parentNode,true);">确定</button></div>'
		document.body.appendChild(div);
		this.pop(div);
	},	
	confrim:function(msg,func,agrs,w,ok,cancel,bodyClass)
	{
		this.confrim.func = func;
		this.confrim.agrs = agrs;
		var width = w?w:250;	
		var css =  bodyClass ? bodyClass : "body" ;
		var div = document.createElement("div");
		div.className = "alert_main";	
		div.style.width = width + "px";
		div.innerHTML = '<h1>有伴提示<span><img src="/images/album/icon_del.gif" onclick="popWindow.close(this.parentNode.parentNode.parentNode,true);"></span></h1><div class="' + css +  '">'+msg+'</div><div class="action"><button class="button1" onclick="popWindow.closeconfrim(this);">'+( ok ? ok : "确定")+'</button>&nbsp;<button class="button1" onclick="popWindow.close(this.parentNode.parentNode,true);">'+ (cancel ? cancel : "取消") + '</button></div>'
		document.body.appendChild(div);
		//alert(div.style.width );
		this.pop(div);
	},
	closeconfrim:function(obj)
	{		
		//alert(typeof this.confrim.func);
		if(typeof this.confrim.func == "function")
		{
			//alert(this.confrim.agrs);
			this.confrim.func(this.confrim.agrs);
		}
		popWindow.close(obj.parentNode.parentNode,true);
	}
};