/**
 * @author mediaowlman
 */

var popupStatus = 0;
var isSubNav = 0;

function loadPopup() {
	
	if(popupStatus==0) {
		$("#backgroundPopup").css({
			"opacity": "0.85",
			"-moz-opacity": "0.85",
			"-webkit-opacity": "0.85",
			"filter": "alpha(opacity=85)",
			"-ms-filter": "progid:DXImageTransform.Microsoft.Alpha(opacity=85)"
		});
		$("#backgroundPopup").fadeIn(500);
		$("#popupContact").fadeIn(500);
		popupStatus = 1;
	}
}

function disablePopup() {
	
	if(popupStatus==1){
		setTimeout(function(){
			//$("div#popupContact div#contactArea").load("");
			var elem = document.getElementById('contactArea');
			//alert(elem.innerHTML);
			elem.innerHTML = "";
		}, 550);
		$("#backgroundPopup").fadeOut(500);
		$("#popupContact").fadeOut(500);
		popupStatus = 0;
	}
}

function centerPopup() {
	
	var windowWidth = $(document).width();
	var windowHeight = $(document).height();
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	
	$("#popupContact").css({
		"position": "absolute",
		"top": "50%",
		"left":"50%",
		"margin-left": popupWidth / -2,
		"margin-top": popupHeight / -2
	});
	
	//only need force for IE6
	$("#backgroundPopup").css({
		"width": "100%",
		"height": windowHeight
	});

}

function showPopup() {
	//alert("show");
	centerPopup();
	loadPopup();
}

$("#popupContactClose").click(function() {
	disablePopup();
});

/*
$("#backgroundPopup").click(function() {
	disablePopup();
});
*/

$(document).keypress(function(e) {
	if(e.keyCode==27 && popupStatus==1) {
		disablePopup();
	}
});

