var popup1 = {
	start:function(sizex,sizey) {
		this.root = "popup1div";
		if (!$("popup1div")) {
			popup1.create();			
		}
		addResizeEvent(popup1.actions);
		
/*		window.onresize = function() {
			popup1.resize();
			popup1.centrale();
			popup1.sotto();
		}
*/
		this.sizex = parseInt(sizex);
		this.sizey = parseInt(sizey);
	},
	actions:function() {
		popup1.resize();
		popup1.centrale();
		popup1.sotto();		
	},
	create:function(content) {	
		elem = document.createElement("div");
		elem.id = this.root;
		document.body.appendChild(elem);
		
	},
	open:function(params,voffset) {
		this.voffset = voffset;
		if (!this.voffset) {
			this.voffset = 0;
		}		
		this.preImg();
		this.getText();
		this.params = params;
		if (!this.params) this.params = "";
		$(this.root).innerHTML = "<div id='popup1_layer0' onclick='popup1.close()'></div><div id='popup1_layer1' ><div id='popup1_cnt'><div id='popup1_body'></div></div></div><div id='popup1_close_button'><a href='javascript:popup1.close()'>chiudi</a></div>";
		//$("popup1_close_button").style.top="150px";
		if (this.sizex) $("popup1_layer1").setStyle({width:this.sizex+"px"});
		if (this.sizey) $("popup1_layer1").setStyle({height:this.sizey+"px"});
	
		$("popup1_body").innerHTML=this.text;
		this.resize();
		this.centrale();
		this.sotto();
	},
	close:function() {
		$(this.root).remove();
		popup1.create();
		
	},
	getText:function() {
		this.text = $(this.root).innerHTML;
	},
	resize:function() {
		if (this.params != "resize") {
			if ($("popup1_layer0")) {
				$("popup1_layer0").style.width = "100%";
				//$("popup1_layer0").style.height = get_wsize().y+"px";
				$("popup1_layer0").style.height = xDocSize().h+"px";
			}	
		}
	},
	centrale:function(tdiv) {
		var novcenter;
		if (this.params) {
			novcenter=(this.params.match("novcenter"));
		} else {
			novcenter="";
		}
		if (!tdiv) tdiv = "popup1_layer1";
		var scroll = xScrollTop();
		var wnd = get_wsize();
		if ($(tdiv)) {
			dxx = $(tdiv).offsetWidth;
			dyy = $(tdiv).offsetHeight;
			newx = (wnd.x/2)-(dxx/2);	
			newy = (wnd.y/2)-(dyy/2)+scroll;		
			$(tdiv).style.left = newx+"px";
			if (!novcenter) {
				$(tdiv).style.top = parseInt(newy+this.voffset)+"px";
			}
			return newx+"---"+newy;
		}
	},
	sotto:function() {
		var novcenter;
		if (this.params) {
			novcenter=(this.params.match("novcenter"));
		} else {
			novcenter="";
		}

		tr = "popup1_close_button";
		vars = this.centrale(tr);
		if ($("popup1_layer1")) {
			dxx = $("popup1_layer1").offsetWidth;
			dyy = $("popup1_layer1").offsetHeight;
			vars = vars.split("---");
			if (vars[1]) {				
				if (!novcenter) {
					$(tr).style.top = parseInt(vars[1])+parseInt((dyy/2))+8+this.voffset+"px"; 
				} 
			}
			$(tr).style.left = parseInt(vars[0])+(dxx/2)-16+"px"; 
		}	
	},
	preImg:function() {
		a = $(this.root).getElementsByTagName("img");
		for (f=0;f<a.length;f++) {		
			this_class =a[f].className;
			if (this_class) {
				spt = this_class.split("x");
				a[f].width = spt[0];
				a[f].height = spt[1];
			}
		}
	}
}