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

//loading popup with jQuery magic!
function loadPopup(elementid){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.9"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(elementid).fadeIn("slow");
	}
}

//disabling popup with jQuery magic!
function disablePopup(elementid){ 
	//disables popup only if it is enabled
	$("#backgroundPopup").fadeOut("slow");
	$(elementid).fadeOut("slow");
}

//centering popup
function centerPopup(elementid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(elementid).height();
	var popupWidth = $(elementid).width();
	//centering
	$(elementid).css({
		"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!
	$("#vid1").click(function(){
		//centering with css
		centerPopup("#popupContact1");
		//load popup
		loadPopup("#popupContact1");
		popupStatus=1;
	});
	$("#vid2").click(function(){
		//centering with css
		centerPopup("#popupContact2");
		//load popup
		loadPopup("#popupContact2");
		popupStatus=2;
	});
		$("#vid3").click(function(){
		//centering with css
		centerPopup("#popupContact3");
		//load popup
		loadPopup("#popupContact3");
		popupStatus=3;
	});
		$("#vid4").click(function(){
		//centering with css
		centerPopup("#popupContact4");
		//load popup
		loadPopup("#popupContact4");
		popupStatus=4;
	});
		$("#vid5").click(function(){
		//centering with css
		centerPopup("#popupContact5");
		//load popup
		loadPopup("#popupContact5");
		popupStatus=5;
	});
		$("#vid6").click(function(){
		//centering with css
		centerPopup("#popupContact6");
		//load popup
		loadPopup("#popupContact6");
		popupStatus=6;
	});
		$("#vid7").click(function(){
		//centering with css
		centerPopup("#popupContact7");
		//load popup
		loadPopup("#popupContact7");
		popupStatus=7;
	});
		$("#vid8").click(function(){
		//centering with css
		centerPopup("#popupContact8");
		//load popup
		loadPopup("#popupContact8");
		popupStatus=8;
	});
		$("#vid9").click(function(){
		//centering with css
		centerPopup("#popupContact9");
		//load popup
		loadPopup("#popupContact9");
		popupStatus=9;
	});
		$("#vid10").click(function(){
		//centering with css
		centerPopup("#popupContact10");
		//load popup
		loadPopup("#popupContact10");
		popupStatus=10;
	});
		$("#vid11").click(function(){
		//centering with css
		centerPopup("#popupContact11");
		//load popup
		loadPopup("#popupContact11");
		popupStatus=11;
	});
		$("#vid12").click(function(){
		//centering with css
		centerPopup("#popupContact12");
		//load popup
		loadPopup("#popupContact12");
		popupStatus=12;
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose1").click(function(){
		disablePopup("#popupContact1");
		popupStatus=0;
	});
	$("#popupContactClose2").click(function(){
		disablePopup("#popupContact2");
		popupStatus=0;
	});
	$("#popupContactClose3").click(function(){
		disablePopup("#popupContact3");
		popupStatus=0;
	});
	$("#popupContactClose4").click(function(){
		disablePopup("#popupContact4");
		popupStatus=0;
	});
	$("#popupContactClose5").click(function(){
		disablePopup("#popupContact5");
		popupStatus=0;
	});
	$("#popupContactClose6").click(function(){
		disablePopup("#popupContact6");
		popupStatus=0;
	});
	$("#popupContactClose7").click(function(){
		disablePopup("#popupContact7");
		popupStatus=0;
	});
	$("#popupContactClose8").click(function(){
		disablePopup("#popupContact8");
		popupStatus=0;
	});
	$("#popupContactClose9").click(function(){
		disablePopup("#popupContact9");
		popupStatus=0;
	});
	$("#popupContactClose10").click(function(){
		disablePopup("#popupContact10");
		popupStatus=0;
	});
	$("#popupContactClose11").click(function(){
		disablePopup("#popupContact11");
		popupStatus=0;
	});
	$("#popupContactClose12").click(function(){
		disablePopup("#popupContact12");
		popupStatus=0;
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		if (popupStatus==1) disablePopup("#popupContact1");
		if (popupStatus==2) disablePopup("#popupContact2");
		if (popupStatus==3) disablePopup("#popupContact3");
		if (popupStatus==4) disablePopup("#popupContact4");
		if (popupStatus==5) disablePopup("#popupContact5");
		if (popupStatus==6) disablePopup("#popupContact6");
		if (popupStatus==7) disablePopup("#popupContact7");
		if (popupStatus==8) disablePopup("#popupContact8");
		if (popupStatus==9) disablePopup("#popupContact9");
		if (popupStatus==10) disablePopup("#popupContact10");
		if (popupStatus==11) disablePopup("#popupContact11");
		if (popupStatus==12) disablePopup("#popupContact12");
		popupStatus=0;
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
