﻿/***************************/
//@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(arg){
	
	var text ="";

	if(arg==1)
	{
		text = 	"<a id='popupContactClose' onclick='disablePopup()'><strong>X</strong></a>"+
				"<h1><strong>Society</strong></h1>"+
				"<p id='contactArea'>"+
				"<strong>VAN-IT SARL</strong><br /><br />"+
				"21 rue Massenet 94190 <br />"+
				"VILLENEUVE SAINT GEORGES<br /><br />"+
				"N° SIRET : 509 658 597 00018<br />"+
				"R.C.S Creteil : 509658597<br /><br />"+
				"<u>Telephone Number</u>: +33 (0)6.70.43.11.86<br />"+
				"<u>Fax </u>: +33 (0)9.58.78.02.97<br /></p>";	
				
				$("#popupContact").css({
							"height": "300",
							"width": "350"
				});
				$("#popupContact").html(text);
	}
	else
	{
	   if(arg==2)
	   {
		  text =  "<a id='popupContactClose' onclick='disablePopup()'><strong>X</strong></a>"+
					"<h1><strong>How do I come ?</strong></h1>"+
					"<p id='contactArea' align='left'>"+
		  			"1 - Go to Villeneuve Saint Georges Train station, RER D (which is only 10 minutes away from Gare de Lyon)<br />"+
					 "2 - When you're there, cross the road (using the tunnel) and go to the bus station on the left.<br />"+
					 "3 - Take the bus (J1 or J2) for 5 minutes and get down at the stop 'Massenet' (ask the driver).<br />"+
					 "4 - You're now at the end of the road. Go to the number 21. You're here!</p>"+
				     "<p>Thank you for contacting us by mail or phone if you don't have a pre-arranged appointment. </p>"+  
				    "<div align='center'>"+
				    "<strong>VAN-IT SARL<br />"+
					"21 rue Massenet<br />"+
					"94190 VILLENEUVE SAINT GEORGES</strong><br /><br />"+
				    "<iframe src='http://www.my-google-maps.com/my-google-maps.php?SID=1234002165-rpkmd' width='470' height='330' frameborder='0' hspace='0' vspace='0' marginheight='0' marginwidth='0' scrolling='no'></iframe>"+
				   "</div></p>";	  
				  
				  $("#popupContact").css({
							"height": "560",
							"width": "760"
				});
				$("#popupContact").html(text);
	   }
	}
	
	
	
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//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;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.offsetWidth;
	if ((windowWidth == "undefined") || (windowWidth == 0))
	{
		windowWidth = document.documentElement.clientWidth
	}
	
	
	var windowHeight =   document.documentElement.offsetHeight; 
	if ((windowHeight == "undefined" ) || (windowHeight == 0))
	{
		windowHeight =  window.innerHeight ;
	}
//	 alert(windowWidth);
	//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!
/*	$("#buttonPopup").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});*/
				
	//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();
		}
	});

});