// JavaScript Document

// TO ADD A NEW MAP LAYER
//	- Add listing to 'init' section
//	- Use the class name in the 'name' attribute in the directory link

$("document").ready( function() {
	
	
	// init
	$("#map_directory").addClass("map_show");
	$("#map_map1").addClass("map_hide").css({opacity:"0"});
	$("#map_map2").addClass("map_hide").css({opacity:"0"});
	$(".map_details_shadow").css({opacity:0});
	var map_details_current = "none";
	var map_icon_clicked=false;
	
	
	//testing. turn this on to see a pane
	//$("#map_map1").removeClass("map_hide").css({opacity:"1"}).addClass("map_show");

	
//directory nav
	$(".directory_listing ul li a").click( function() {
		var map_select = $(this).attr("name");
		$("#map_directory").removeClass("map_hide").addClass("map_show");
		$("#"+map_select).animate({opacity: 1}, "slow").removeClass("map_hide").addClass("map_show");
	});
	// assign numbers to map items using name attr
	$(".map_container div a").each( function() {
		var this_name = $(this).attr("name");
		var name_number = $(".map_nav_window ul li a[name="+this_name+"]").siblings().html();
		$(this).html(name_number);
	});
	
	
	
//clears selections 
function map_clear_selections() {
	$(".map_nav_window ul li a").removeClass("map_item_number_active");
	$(".map_nav_window ul li .numbers").removeClass("map_item_number_active");
	$(".map_nav_window ul li").removeClass("map_item_active");
	$(".map_container .selected").removeClass("selected");	
}

	
// opens/closes details panel. map_point_name is the name attr of the element
function map_details_window(map_point_name) {
	
	// make details window fly out and sets the current details variable
	if (map_details_current!=map_point_name) {
		$("#"+map_details_current).animate({left: 720});
		$("#"+map_point_name).animate({left: 0});
		map_details_current = map_point_name;
	} else {
		$("#"+map_details_current).animate({left: 720});
		map_clear_selections();
		map_details_current = "none";
	}
	
	return map_details_current;
	
	// drop shadow appears 
	$(".map_details_shadow").animate({opacity:1});	
}

	
	
	
// map nav
	$(".map_nav_window ul li").click( function() {
		// remove active classes from previous item and put window away
		$(".map_item_active").removeClass("map_item_active");
		$(".map_item_number_active").removeClass("map_item_number_active");
		// add it to the new one
		$(this).children("ul li .numbers").addClass("map_item_number_active");
		$(this).children("ul li a").addClass("map_item_number_active");
		$(this).addClass("map_item_active");
		// details window
		var map_details = $(this).children("a").attr("name");
		map_details_window(map_details);
	});
	
	
	
	
	
	
// icon nav
	$(".map_container").children("div").click( function() {
		// details window
		var map_details = $(this).children().children().attr("name");
		$(".map_nav_window ul li a[name='"+map_details+"']").addClass("map_item_number_active");
		$(".map_nav_window ul li a[name='"+map_details+"']").parent().addClass("map_item_active");
		map_icon_clicked=true;
		map_details_window(map_details);
	});
	
	
	
	
	
	
	
	
	
// connect icon hover with nav hover	
	$(".map_nav_window ul li").hover( function() {
		//remove previous selected
		$(".map_container .selected").removeClass("selected");
		// highlight the cooresponding map icon
		var map_icon_selected = $(this).children("a").attr("name");
		$(".map_container div a[name="+map_icon_selected+"]").parent().parent().addClass("selected");
	});
	
	$(".map_nav_window ul li a").mouseout( function() {
		$(".map_container .selected").removeClass("selected");
	});
	
	$(".map_icon_contact").hover( function() {
		// remove active classes
		$(this).parent().addClass("selected");
		var map_details = $(this).next().children().attr("name");
		//alert(map_details);
		$(".map_nav_window ul li a[name='"+map_details+"']").addClass("map_item_number_active");
		$(".map_nav_window ul li a[name='"+map_details+"']").parent().addClass("map_item_active");
		$(".map_nav_window ul li a[name='"+map_details+"']").siblings(".numbers").addClass("map_item_number_active");
	});
	
	$(".map_container").children("div").mouseout( function() {
		// remove active classesy
		$(this).removeClass("selected");
		if (map_icon_clicked!=true) {
			map_clear_selections();
		}
		// add it to the new one
	});
	






// return to directory 
	$(".map_return a").click( function() {
		$(this).parent().parent().animate({opacity: 0}, function() {
			$(this).removeClass("map_show").addClass("map_hide")
			});
		});
	
	
	
	
	
	
	
	
// map details window close
	$(".map_details_close").click( function() {
		$(this).parent().animate({left: 720});
		// drop shadow disappears 
		$(".map_details_shadow").animate({opacity:0});
		map_details_current = "none";
		map_icon_clicked=false;
		map_clear_selections();
	});
	
	
	
	
	
	
	
	
}); //end
