/*
 * @author Bartosz Siudak
 */
var PopUp = {
	/*
	 * fields
	 */
	width: 350,
	height: 150,
	zIndex: 1001,
	popUpId: 0,
	closeOtion: true,
	baseUrl: '',
	
	/*
	 * methods
	 */
	showPopUp: function(xhtml) {
		this.popUpId++;
		var closePopUpImg = this.closeOtion ? '<img class="closePopUp" src="'+Helper.baseUrl+'/public/images/icons/exit.png" onClick="PopUp.closePopUp('+this.popUpId+');" />'+"\n" : '';
		$("body").append(
			'<div id="popUpBackground_'+this.popUpId+'" class="popUpBackground popUpAll" style="z-index: '+(++this.zIndex)+';"></div>'+"\n"+
			'<div id="popUp_'+this.popUpId+'" class="popUp popUpAll" style="width: '+this.width+'px; min-height: '+this.height+'px; z-index: '+(++this.zIndex)+';">'+"\n"+
				'<div id="popUpText_'+this.popUpId+'" class="popUpText popUpAll" style="z-index: '+(++this.zIndex)+';">'+xhtml+'</div>'+"\n"+closePopUpImg+
			'</div>'+"\n"
		);
		var doc = $(document);
		var popUp = $("div#popUp_"+this.popUpId);
		
		var bodyWidth	= parseInt(doc.width());
		var bodyHeight	= parseInt(doc.height());
		var popUpWidth	= parseInt(this.width);
		var popUpHeight	= parseInt(this.height);
		var scrollPos	= parseInt(doc.scrollTop());
		
		var positionLeft = (bodyWidth / 2) - (this.width / 2);
		$("#popUpBackground_"+this.popUpId).css({ 'height':bodyHeight, 'top':'0', left:'0' });
		$("#popUpBackground_"+this.popUpId).fadeTo(1000, 0.6);
		popUp.css({ 'top':(scrollPos + 100), 'left':positionLeft });
		popUp.fadeIn(1000);
		
		return false;
	},
	closePopUp: function(id) {
		$("#popUpBackground_"+id+", #popUp_"+id).remove();
		return false;
	},
	closeAllPopUp: function() {
		$(".popUpAll").remove();
	},
	createButton: function(name, action) {
		var xhtml = '<div class="popUpButton" onClick="javascript:'+action+'">'+name+'</div>';
		return xhtml;
	},
	createConfirmButtons: function(yes, no, action, popUpId, noButtonAction) {
		noButtonAction = noButtonAction ? noButtonAction : '';
		var xhtml = '<div>'+"\n"+
						'<div style="float: left;">'+this.createButton(yes, action)+'</div>'+"\n"+
						'<div style="float: right;">'+this.createButton(no, 'PopUp.closePopUp('+popUpId+');'+noButtonAction)+'</div>'+"\n"+
						'<div style="clear: both;"></div>'+"\n"+
					'</div>'+"\n";
		return xhtml;
	},
	createAjaxLoader: function(id) {
		$("#popUpText_"+id).html('<div style="width: 100%; background: transparent url('+Helper.baseUrl+'/public/images/ajaxLoader.gif) no-repeat center; height: 300px;"></div>');
	}
}
