﻿var MovpopupStatus = 0;

//loading popup with jQuery magic!
function MovloadPopup(){
	//loads popup only if it is disabled
	if(MovpopupStatus==0){
		$("#MovpopupContact").fadeIn("slow");
		MovpopupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function MovdisablePopup(){
	//disables popup only if it is enabled
	if(MovpopupStatus==1){
		$("#MovpopupContact").fadeOut("slow");
		MovpopupStatus = 0;
		document.getElementById("MovpopupMovie").Stop();
	}
}


//centering popup
function MovcenterPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#MovpopupContact").height();
	var popupWidth = $("#MovpopupContact").width();
	var x = 0;
	var y = 0;
//	alert(popupHeight + " " + popupWidth);
//	alert(windowHeight + " " + windowWidth);
//	alert((document.documentElement.scrollTop +(windowHeight-popupHeight)/2+y)+'px' + " " + (document.documentElement.scrollLeft+(windowWidth -popupWidth )/2+x)+'px');
//	
	//centering
	$("#MovpopupContact").css({
		"position": "absolute",
		"left": (document.documentElement.scrollLeft+(windowWidth -popupWidth )/2+x)+'px',
        "top": (document.documentElement.scrollTop +(windowHeight-popupHeight)/2+y)+'px'
	});
}


//LOADING POPUP
//Click the button event!
function Movpopup(){
    //centering with css
    MovcenterPopup();
    //load popup
	MovloadPopup();
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
					
	//CLOSING POPUP
	//Click the x event!
	$("#MovpopupContactClose").click(function(){
		MovdisablePopup();
	});
	$(document).keypress(function(e){
		if(e.keyCode==27 && MovpopupStatus==1){
			MovdisablePopup();
		}
	});

});