/*  
	Copyright (C) 2007, 2008, 2009 Intercon e-consulting, http://www.intercon.pl
	Created 2009.01.07 by mz :: v.2.0 :: 2009.12.08 by pp
*/

var __PopUtils__ = function() {

	var w = window;
	var d = document;

	this.UA = {
		IE : (document.all ? true : false)
	};

	this.getWindowW = function () {
		var x;
		if (x = w.innerWidth) {}
		else if (d.documentElement && (x = d.documentElement.clientWidth)) {}
		else if (d.body && (x = d.body.clientWidth)) {}
		return x||0;
	};

	this.getWindowH = function () {
		var x;
		if (x = w.innerHeight) {}
		else if (d.documentElement && (x = d.documentElement.clientHeight)) {}
		else if (d.body && (x = d.body.clientHeight)) {}
		return x||0;
	};
}

__PopUtils__.prototype.docHeight = function() {
	var sH = document.body.scrollHeight;
	var oH = document.body.offsetHeight;
	var wH = PopUtils.getWindowH();
	if (sH < oH) sH = oH;			
	if (sH < wH) sH = wH;
	return sH;
};

__PopUtils__.prototype.docWidth = function() {
	var sW = document.body.scrollWidth;
	var oW = document.body.offsetWidth;
	var wW = PopUtils.getWindowW();
	if (sW < oW) sW = oW;
	if (sW < wW) sW = wW;

	if (PopUtils.getWindowH() <= document.body.scrollHeight) {
		var c = PopUtils.UA.IE ? 0 : 16;
		sW = sW - c;
	}
	return sW;
};

var PopUtils = new __PopUtils__();

var popup = new function() {
	
	var self = this;

	this.args = null;
	this.tLId = 'bigPopup';
	this.swfId = 'polecam-swf';
	this.rCId = 'rightColumn2';
	this.tL = null;
	this.swf = null;
	this.rC = null;
	this.width = 0;
	this.height = 0;
	this.source = '';
	this.cookie = '';

	var tLLPos = 0;
	var tLTPos = 0;
	var pW = 988;
	var rCW = 202;
	var rCPos = 0;

	this.open = function() {
		if (self.cookie) {
			var tmp = self.cookie.split(':');
			if (readCookie(tmp[0]))
				return false;
			else
				saveCookie(tmp[0], tmp[1], tmp[2]);
		}
		if (self.width && self.height && self.source) {
			self.create();
			createSWFObj({cnt : self.swfId, params : {movie : self.source, width : self.width, height : self.height, name : self.swfId, wmode : 'transparent', bgcolor: '#ffffff'}});
		}
	};

	var calcPos = function() {
		tLLPos = (PopUtils.docWidth() - self.width) / 2 + 12;
		//tLTPos = (PopUtils.docHeight() - self.height) / 2;
		rCPos = pW - rCW + ((PopUtils.docWidth() - pW) / 2);
	};
	
	var handleArgs = function() {
		if (typeof self.args != "object")
			return false;
		for (var i in self.args)
			self[i] = self.args[i];
	};

	var createWindow = function() {
		
		self.tL = document.createElement('div');
		self.swf = document.createElement('div');
		self.rC = document.createElement('div');
		
		calcPos();

		self.tL.style.width = self.width + "px";
		self.tL.style.height = self.height + "px";
		self.tL.style.position = "absolute";
		self.tL.style.top = tLTPos + "px";
		self.tL.style.left = tLLPos + "px";

		self.tL.id = self.tLId;
		self.swf.id = self.swfId;

		self.tL.appendChild(self.swf);
		document.body.appendChild(self.tL);

		self.rC.style.width = rCW + "px";
		self.rC.style.position = "absolute";
		self.rC.style.top = "155px";
		self.rC.style.left = rCPos + "px";
		self.rC.id = self.rCId;

		try {
			var login = getId('loginActionsBox').cloneNode(true);
			self.rC.appendChild(login);
		} catch (e) {}
		try {
			var client = getId('becomeAClientBox').cloneNode(true);
			self.rC.appendChild(client);
		} catch (e) {}	

		document.body.appendChild(self.rC);	
	};

	this.create = function() {			
		createWindow();
		addEvent(window, self.changePos, 'resize');
	};

	this.changePos = function () {
		calcPos();
		self.tL.style.left = tLLPos + "px";
		self.rC.style.left = rCPos + "px";
		self.swf.style.visibility = 'visible';
	};

	this.close = function() {	
		removeEvent(window, self.changePos, 'resize');
		try {
			self.rC.parentNode.removeChild(self.rC);
			self.tL.parentNode.removeChild(self.tL);
		} catch (e) {}

		if (PopUtils.UA.IE) {
			try {
				self.rC.removeNode(true);	
				self.tL.removeNode(true);	
			} catch (e) {}
		}
		popup = false;
	};

	this.init = function() {
		handleArgs();
		addEvent(window, self.open, 'load');
	};
};

function closePopup() {
	popup.close();
}

function openPopup() {
	popup.args = arguments[0];
	popup.init();
}