
// 'backgroundPopup', 'popupContact', 'popupContactClose'
function PopupSWD( backgroundPopup, popupContact, popupContactClose  ) {

	this.backgroundPopup = $( '#' + backgroundPopup );
	this.popupContact = $( '#' + popupContact );
	this.popupContactClose = $( '#' + popupContactClose );
	
	var pobj = this;
	
	//CLOSING POPUP
	//Click the x event!
	this.popupContactClose.click( function(e) {
		pobj.disablePopup();
	});
	//Click out event!
	this.backgroundPopup.click( function(e) {
		pobj.disablePopup();
	});	
}

PopupSWD.prototype = {
	popupStatus: false,
	backgroundPopup : null,
	popupContact : null,
	popupContactClose : null,

	showPopup : function () {
		//centering with css
		this.centerPopup();
		//load popup
		this.loadPopup();	
	},
	//loading popup with jQuery magic!
	loadPopup : function () {
		// loads popup only if it is disabled
		if ( !this.popupStatus ){
			this.backgroundPopup.css({
				"opacity": "0.7"
			});
			this.backgroundPopup.fadeIn("slow");
			
			this.popupContact.fadeIn("slow");
			this.popupStatus = true;
		}
	},	// loadPopup
	
	//disabling popup with jQuery magic!
	disablePopup : function (){
		//disables popup only if it is enabled
		if ( this.popupStatus ){
			this.backgroundPopup.fadeOut("slow");
			this.popupContact.fadeOut("slow");
			this.popupStatus = false;
		}
	}, // disablePopup
	
	//centering popup
	centerPopup : function (){
		//request data for centering

		// var windowWidth = document.documentElement.clientWidth;
		// var windowHeight = document.documentElement.clientHeight;

		var windowWidth = $(window).width();
		var windowHeight = $(window).height();
		var documentHeight = $(document).height();
		
		var popupHeight = this.popupContact.height();
		var popupWidth = this.popupContact.width();

		//centering
		this.popupContact.css({
			"position": "absolute",
			"top": windowHeight/3-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		
		this.backgroundPopup.css({
			"height":documentHeight, "width":windowWidth
		});
	}	// centerPopup
}



