﻿//0 means disabled; 1 means enabled;
var popupStatus = 0;

function loadPopup () {
	if(popupStatus==0){
		new Effect.Appear('backgroundPopup', {
			duration: 0.5,
			to: 0.7
		});
		new Effect.Appear('popupContact', {
			duration: 0.5,
			afterFinish: function () {
			}
		});
		popupStatus = 1;
	}
}

function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		new Effect.Fade('backgroundPopup', {
			duration: 0.5
		});
		new Effect.Fade('popupContact', {
			duration: 0.5
		});
		popupStatus = 0;
	}
}

function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("popupContact").getHeight();
	var popupWidth = $("popupContact").getWidth();
	
	$('popupContact').setStyle({
		"position": "absolute",
/*		"top": (windowHeight/2-popupHeight/2) + "px",*/
		"top": "20px",
		"left": (windowWidth/2-popupWidth/2) + "px"
	});

	$('backgroundPopup').setStyle({
		"height": windowHeight
	});	
}



Event.observe(window,'load',function () {
	loadPopup();
	centerPopup();
	Event.observe('popupContactClose','click',function () {
		disablePopup();
	});
});


/*
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
*/

