﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var activeDiv
var scrollPos
//loading popup with jQuery magic!
function showContent(oDiv){
	var i, j=1;
	activeDiv = oDiv
	document.getElementById('divContent_0').innerHTML = document.getElementById(activeDiv).innerHTML
	centerPopup();loadPopup();
	return false;
}

function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.8"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
	return false;
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
//	document.getElementById(activeDiv).style.display='none';
	document.getElementById('divContent_0').innerHTML = '';
}

//centering popup
function centerPopup(){
	//request data for centering
	//debugger
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	var popMargTop = ($('#popupContact').height() + 80) / 2;
	var popMargLeft = ($('#popupContact').width() + 80) / 2;
	//Apply Margin to Popup
	$('#popupContact').css({
		'position' : 'fixed',
		'top'  : '50%',
		'left' : '50%',
		'float' : 'left',
		'z-index' : 99999,
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	});


	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	//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();
		}
	});

});
