﻿/***************************/
//@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;

function loadPopup(){
	//loads popup only if it is disabled
	var displayDIV = "#popupContact";
	var NEWdisplayDIV = displayDIV + videoclass;
	
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(NEWdisplayDIV).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	var displayDIV = "#popupContact";
	var NEWdisplayDIV = displayDIV + videoclass;
	
	if(popupStatus==1){
		
		$("#backgroundPopup").fadeOut("slow");
		$(NEWdisplayDIV).fadeOut("slow");
		popupStatus = 0;
		videoclass=0;
	}
}


//centering popup
function centerPopup(){
	//request data for centering
	var displayDIV = "#popupContact";
	var NEWdisplayDIV = displayDIV + videoclass;	
	
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(NEWdisplayDIV).height();
	var popupWidth = $(NEWdisplayDIV).width();
	//centering
	$(NEWdisplayDIV).css({
		"position": "absolute",
		"top": (windowHeight/2-popupHeight/2)+$(window).scrollTop(),
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
/*
function centerPopup(videoclass){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}*/


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#govideo1").click(function(){ videoclass=1; centerPopup(); loadPopup(); });
	$("#govideo2").click(function(){ videoclass=2; centerPopup(); loadPopup(); });
	$("#govideo3").click(function(){ videoclass=3; centerPopup(); loadPopup(); });
	$("#govideo4").click(function(){ videoclass=4; centerPopup(); loadPopup(); });
	$("#govideo5").click(function(){ videoclass=5; centerPopup(); loadPopup(); });
	$("#govideo6").click(function(){ videoclass=6; centerPopup(); loadPopup(); });
	$("#govideo7").click(function(){ videoclass=7; centerPopup(); loadPopup(); });
	$("#govideo8").click(function(){ videoclass=8; centerPopup(); loadPopup(); });
	$("#govideo9").click(function(){ videoclass=9; centerPopup(); loadPopup(); });
	$("#govideo10").click(function(){ videoclass=10; centerPopup(); loadPopup(); });
	$("#govideo11").click(function(){ videoclass=11; centerPopup(); loadPopup(); });
	$("#govideo12").click(function(){ videoclass=12; centerPopup(); loadPopup(); });
	$("#govideo13").click(function(){ videoclass=13; centerPopup(); loadPopup(); });
	$("#govideo14").click(function(){ videoclass=14; centerPopup(); loadPopup(); });
	$("#govideo15").click(function(){ videoclass=15; centerPopup(); loadPopup(); });
				
	//CLOSING POPUP
	//Click the x event!
	$(".popupContactClose").click(function(){disablePopup();});
	//$("#popupContactClose2").click(function(){disablePopup(2);});
	//Click out event!
	$("#backgroundPopup").click(function(){disableBGPopup();});
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
