$(document).ready(function(){
	if($("#atlas_sitemap_selector")) {
		$("#atlas_sitemap_selector").click(function () {
			//$("#atlas_sitemap").load("atlas_sitemap.html");
			$("#atlas_sitemap_container").toggleClass('loaded');
		});
	}
	
	// close the sitemap if user clicks somewhere out of sitemap 
	$(document).click(function(e){
		var selectorButton = false;
		var clickInSitemap = false;
		
		if($(e.target).attr("id") == "atlas_sitemap_selector") {
			selectorButton = true;
		}
		
		//bubble up -- get whole parents element 
		var parentsThis = $(e.target).parents();
		
		parentsThis.each(function () {
			if(this.id == "atlas_sitemap_container") {
				clickInSitemap = true;
			} 
		});
		if(selectorButton == false && clickInSitemap == false && $("#atlas_sitemap_container").hasClass('loaded') == true) {
			$("#atlas_sitemap_container").removeClass('loaded');
		}
	});
});
