﻿/***************************/
//@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(num){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		 $("#popupContact"+num).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(num){
 //disables popup only if it is enabled

//alert(tempnum);
 if(popupStatus==1){
  $("#backgroundPopup").fadeOut("slow");
  
  
  $("#popupContact"+tempnum).fadeOut("slow");
  
  popupStatus = 0;
 }
}

var tempnum;
//centering popup
function centerPopup(num){
tempnum=num;
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight =$("#popupContact"+num).height();
	var popupWidth =$("#popupContact"+num).width();
	//centering
	$("#popupContact"+num).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!
	
	//For x content
		$('#button1').click(function(){
		//centering with css
			centerPopup('1');
		//load popup
			loadPopup('1');
		});
		$('#button2').click(function(){
		//centering with css
			centerPopup('2');
		//load popup
			loadPopup('2');
		});
		
		$('#button3').click(function(){
		//centering with css
			centerPopup('3');
		//load popup
			loadPopup('3');
		});
		
		$('#button4').click(function(){
		//centering with css
			centerPopup('4');
		//load popup
			loadPopup('4');
		});
		
		$('#button5').click(function(){
		//centering with css
			centerPopup('5');
		//load popup
			loadPopup('5');
		});
		
		$('#button6').click(function(){
		//centering with css
			centerPopup('6');
		//load popup
			loadPopup('6');
		});
		
		$('#button7').click(function(){
		//centering with css
			centerPopup('7');
		//load popup
			loadPopup('7');
		});
		
		$('#button8').click(function(){
		//centering with css
			centerPopup('8');
		//load popup
			loadPopup('8');
		});
		
		$('#button9').click(function(){
		centerPopup('9');
		loadPopup('9');
		});
		
		$('#button10').click(function(){
		centerPopup('10');
		loadPopup('10');
		});
		
		$('#button11').click(function(){
		centerPopup('11');
		loadPopup('11');
		});
		
		$('#button12').click(function(){
		centerPopup('12');
		loadPopup('12');
		});
		
		$('#button13').click(function(){
		centerPopup('13');
		loadPopup('13');
		});
		
		$('#button14').click(function(){
		centerPopup('14');
		loadPopup('14');
		});
		$('#button15').click(function(){
		centerPopup('15');
		loadPopup('15');
		});
		$('#button16').click(function(){
		centerPopup('16');
		loadPopup('16');
		});
		$('#button17').click(function(){
		centerPopup('17');
		loadPopup('17');
		});
		
		$('#button18').click(function(){
		centerPopup('18');
		loadPopup('18');
		});
		
		$('#button19').click(function(){
		centerPopup('19');
		loadPopup('19');
		})
	
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose1").click(function(){
		disablePopup('1');
	});
	$("#popupContactClose2").click(function(){
		disablePopup('2');
	});
	$("#popupContactClose3").click(function(){
		disablePopup('3');
	});
	
	$("#popupContactClose4").click(function(){
		disablePopup('4');
	});
	
	$("#popupContactClose5").click(function(){
		disablePopup('5');
	});
	
	$("#popupContactClose6").click(function(){
		disablePopup('6');
	});
	
	$("#popupContactClose7").click(function(){
		disablePopup('7');
	});
	
	$("#popupContactClose8").click(function(){
		disablePopup('8');
	});
	
	$("#popupContactClose9").click(function(){
		disablePopup('9');
	});
	
	$("#popupContactClose10").click(function(){
		disablePopup('10');
	});
	
	$("#popupContactClose11").click(function(){
		disablePopup('11');
	});
	
	$("#popupContactClose12").click(function(){
		disablePopup('12');
	});
	
	$("#popupContactClose13").click(function(){
		disablePopup('13');
	});
	
	$("#popupContactClose14").click(function(){
		disablePopup('14');
	});
	
	$("#popupContactClose15").click(function(){
		disablePopup('15');
	});
	
	$("#popupContactClose16").click(function(){
		disablePopup('16');
	});
	
	$("#popupContactClose17").click(function(){
		disablePopup('17');
	});
	
	$("#popupContactClose18").click(function(){
		disablePopup('18');
	});
	
	
	$("#popupContactClose19").click(function(){
		disablePopup('19');
	});
	
	////////////////////////
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup('18');
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			
			disablePopup('18');
		}
	});

});
