//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var mapPopupStatus = 0;

//loading popup with jQuery magic!
function loadMap(){
	//loads popup only if it is disabled
	if(mapPopupStatus==0){
		$("#backgroundPopup").css({ "opacity": "0.5"});
		$("#backgroundPopup").fadeIn("slow");
		$("#mapPopup").fadeIn("slow");
		mapPopupStatus = 1;
	}
}

function disableMapPopup(){
	if(mapPopupStatus==1) {
		$("#backgroundPopup").fadeOut("slow");
		$("#mapPopup").fadeOut("slow");
		mapPopupStatus = 0;
	}
}


//centering popup
function centerMap(){
	
	//Instead of centering it, I'm placing it X number of pixels below the top of the page
	var popupWidth = $("#mapPopup").width();
	var windowWidth = $(window).width();
	var pixelsFromTop = 100;
	$("#mapPopup").css({
		"position": "absolute",
		"top": pixelsFromTop,
		"left": windowWidth/2-popupWidth/2
	});
	
	//only need force for IE6
	var windowHeight = $(window).height();
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function popupMap() {
	loadMap();	
	centerMap();
}

function initializeMap() {
	var map = new FusionMaps("/ext/infosoft/fusionmaps/Maps/FCMap_USA.swf", "map", 800, 550, "0", "0");
    map.setDataURL("/xml/map.xml");
    map.setTransparent(true);
    map.render("FooterMapContainer");
					
	$("#closePopup").click(function(){
		disableMapPopup();
	});

	$("#backgroundPopup").click(function(){
		disableMapPopup();
	});
	
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disableMapPopup();
		}
	});
	
	$('.map img').click(function(){
			loadMap();
			centerMap();
		});
}

$(document).ready(function() {
	initializeMap();    

});