var Popups = {
	initialized : false,
	popup : null,
	popup_1 : null,
	popup_2 : null,
	offset_1 : [-50, 0],
	offset_2 : [0,65],
	sOffset_1 : [-55, -10],
	sOffset_2 : [20, 90],
	mapPos : null,
	shadow_1 : null,
	shadow_2 : null,
	
	initialize : function() {
		if (!this.initialized) {
			this.popup_1 = $('popup_1');
			this.popup_2 = $('popup_2');
			this.popup = this.popup_1;
			this.mapPos = Position.page($('map'));
			this.initialized = true;
		}
	},
		
	show : function(content, x, y, order) {
		this.hide();
		//this.close();
		this.shadow_1 = $('popup_shadow_1');
		this.shadow_2 = $('popup_shadow_2');
		if (y < 140) {
			this.popup = this.popup_2;
			document.getElementById("popup_2_content").innerHTML = content;
			if (order) {
				document.getElementById("popup_2_SiteNo").innerHTML = order;
			}

			this.shadow = this.shadow_2;
			this.popup.show();
			this.popup.setStyle({
				left: this.mapPos[0] + x + this.offset_2[0] + 'px',
				top: this.mapPos[1] + y - this.popup.getHeight() + this.offset_2[1] + 'px'
			});
			this.shadow.setStyle({
				left: this.mapPos[0] + x + this.sOffset_2[0] + 'px',
				top: this.mapPos[1] + y - this.shadow.getHeight() + this.sOffset_2[1] + 'px'
			});
			this.shadow.show();
			document.getElementById("popup_2_content").scrollTop = 0;
			
		} else {
			this.popup = this.popup_1;

			document.getElementById("popup_1_content").innerHTML = content;
			if (order) {
				document.getElementById("popup_1_SiteNo").innerHTML = order;
			}

			this.shadow = this.shadow_1;
			this.popup.show();
			this.popup.setStyle({
				left: this.mapPos[0] + x + this.offset_1[0] + 'px',
				top: this.mapPos[1] + y - this.popup.getHeight() + this.offset_1[1] + 'px'
			});
			this.shadow.setStyle({
				left: this.mapPos[0] + 50 + x + this.sOffset_1[0] + 'px',
				top: this.mapPos[1] + y - this.shadow.getHeight() + this.sOffset_1[1] + 'px'
			});
			this.shadow.show();			
			document.getElementById("popup_1_content").scrollTop = 0;


		}
	},
	
	hide : function() {
		this.popup_1.hide();
		if (this.shadow_1) {
			this.shadow_1.hide();
		}
		this.popup_2.hide();
		if (this.shadow_2) {
			this.shadow_2.hide();
		}
	},

	move : function(x, y) {
		if (this.popup == this.popup_2) {
			this.popup.setStyle({
				left: this.mapPos[0] + x + this.offset_2[0] + 'px',
				top: this.mapPos[1] + y - this.popup.getHeight() + this.offset_2[1] + 'px'
			});
			this.shadow.setStyle({
				left: this.mapPos[0] + x + this.sOffset_2[0] + 'px',
				top: this.mapPos[1] + y - this.shadow.getHeight() + this.sOffset_2[1] + 'px'
			});
		} else {
			this.popup.setStyle({
				left: this.mapPos[0] + x + this.offset_1[0] + 'px',
				top: this.mapPos[1] + y - this.popup.getHeight() + this.offset_1[1] + 'px'
			});
			this.shadow.setStyle({
				left: this.mapPos[0] + 50 + x + this.sOffset_1[0] + 'px',
				top: this.mapPos[1] + y - this.shadow.getHeight() + this.sOffset_1[1] + 'px'
			});
		}
	},
	
	isOpen : function() {
		if ($('popup_1').style.display != "none") {
			return true;
		} 
		if ($('popup_2').style.display != "none") {
			return true;
		} 
		return false;
	}
}