﻿/***************************/
//@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;

//var url='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=2295+Peachtree+Road+NE+Atlanta,+GA+30309&sll=37.0625,-95.677068&sspn=33.077336,55.546875&ie=UTF8&hq=&hnear=2295+Peachtree+Rd+NE,+Atlanta,+Georgia+30309&ll=33.819464,-84.389033&spn=0.008468,0.013561&z=16&iwloc=r0&iwstate1=dir';
//loading popup with jQuery magic!


function loadPopupMap(pupid){
	//loads popup only if it is disabled
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");		
		$("#"+pupid).fadeIn("slow");
}
function pupUpClose()
{
	disablePopupMap();	
}
function disablePopupMap(){
	//disables popup only if it is enabled
	$("#backgroundPopup").fadeOut("slow");
	$(".popupContactMap").fadeOut("slow");
	popupStatus = 0;
		
}

function centerPopupMap(pupid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	//var popupHeight = $("#popupContact").height();
	//var popupWidth = $("#popupContact").width();
	var popupHeight = $("#" +pupid).height();
	var popupWidth = $("#"+pupid).width();
	//centering
	$("#"+pupid).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!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
	// disablePopup();
		disablePopupMap();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		//disablePopup();
		disablePopupMap();
	});
	$(".closelink").click(function(){								   
		disablePopupMap();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			//disablePopup();
			disablePopupMap();
		}
	});

});

function opengooglmap(divid)
{	
	centerPopupMap(divid);
	//load popup
	loadPopupMap(divid);	
	
}
