﻿/***************************/
//@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>Soci&eacute;t&eacute;</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>Tél</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>Comment venir ?</strong></h1>"+
					"<p id='contactArea' align='left'>"+
		  			"1 - Allez &agrave; la gare de Villeneuve Saint Georges &ndash; RER D<br />"+
					 "2 - Une fois arriv&eacute;s &agrave; la gare traversez la route (en passant  par le souterrain) et tournez &agrave; gauche pour se diriger vers les arr&ecirc;ts de bus.<br />"+
					 "3 - Prenez le bus J1 ou J2 pendant 5 minutes et descendez &agrave;  l&rsquo;arr&ecirc;t Massenet (demandez au chauffeur).<br />"+
					 "4 - Vous &ecirc;tes au bout de la rue. Allez jusqu&rsquo;au 21. Vous  &ecirc;tes&nbsp;arriv&eacute;.</p>"+
				     "<p>Merci de nous contacter &agrave; l&rsquo;avance, soit par mail soit par  t&eacute;l&eacute;phone, si vous n&rsquo;avez pas de rendez vous programm&eacute;. </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": "580",
							"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();
		}
	});

});