/**
* Popup layer
*/
$.clientCoords = function() {
	var dimensions = {width: 0, height: 0};
	var ua = navigator.userAgent.toLowerCase(); 	
	var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
	if (isIE){
		dimensions.width = document.body.clientWidth;
		dimensions.height = document.body.clientHeight;
	} else if (document.documentElement) {
		dimensions.width = document.documentElement.clientWidth;
		dimensions.height = document.documentElement.clientHeight;
	} else if (window.innerWidth && window.innerHeight) {
		dimensions.width = window.innerWidth;
		dimensions.height = window.innerHeight;
	}
	return dimensions;
}


function oPopupLayer(params){
	this._init();
}

oPopupLayer.prototype = {

	_layer : null,
	_layer_bg : null,
	_main_layer : null,
	
	_init: function(params){
		
		this._main_layer = this._layer_bg = document.createElement("div");
		$(this._main_layer).attr('class', 'popup-layer').css('display', 'none');
	
		this._layer_bg = document.createElement("div");
		var coords = $.clientCoords();
		var athis = this;
		
		$(this._layer_bg).attr({"id": "oLayerBG", 'class' : 'background'}).click(function(){athis.close(athis)});
		$('<img/>').attr('src', '/img/dot.png').css({'width' : coords.width, 'height' : coords.height}).appendTo(this._layer_bg);
				
		// delete old element if exists
		this._layer = document.createElement("div");
		
		$(this._layer).attr({"id" : "oLayerPopup", 'class' : 'inner'});
		
		$(this._layer_bg).appendTo(this._main_layer);
		$(this._layer).appendTo(this._main_layer);
		$(this._main_layer).appendTo("body");
			
	},
	
	create : function (content){
		
		if (typeof content != 'undefined'){
			this._layer.innerHTML = content;
			
			var coords = $.clientCoords();
		
			$(this._main_layer).css({'display' : 'block'});
			var odims = {'width' : this._layer.offsetWidth, 'height' : this._layer.offsetHeight};
			var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
			//alert(scrollTop+'---'+coords.height+'---'+odims.height);
			//alert(document.body.clientHeight+'--'+document.documentElement.clientHeight+'--'+window.innerHeight);
			//coords.height = $(document).height;
			//var lft = (coords.width - odims.width)/2;
			var tp  = scrollTop+($(window).height() - odims.height)/2;
			//alert(coords.width+'---'+odims.width+'--'+coords.height+'---'+odims.height);
			$(this._layer).css({/*'left' : lft+'px',*/ 'top': tp+'px'});
					
		}		
	},
	
	close : function (owner){
		$(owner._main_layer).css({'display' : 'none'});
	}
}
