jQuery(function(){
		   
	if (jQuery.browser.win()) {
		jQuery("#directory-list a").css("line-height", "26px");
	}
	
	jQuery("<div>").attr("id", "map-tooltip").appendTo("#directory-map").hide();
	
	jQuery("<div>").attr("id", "map-tooltip-inner").appendTo("#map-tooltip");
	
	// Set up spaces
	jQuery(".dir-table-store").each(function(index){
		var id = jQuery(this).attr("id");
		var name = jQuery.trim(jQuery(this).children(".dir-table-name").text());
		
		jQuery("#map" + id).show().data("store-title", name).data("rowid", id).click(function(event){
	  		event.preventDefault();
			scrollToAnchor(jQuery(this).children("a").attr("href"));
			highlightRow(jQuery(this).data("rowid"));
			jQuery("#" + jQuery(this).data("rowid")).trigger("click");
		}).mouseover(function(){
			highlightArea(jQuery(this).attr("id"));
			showTooltip(jQuery(this));
		}).mouseout(function(event){
			hideTooltip();
		});
	});
	
	/*
	jQuery(".dir-table-store").click(function(){
		jQuery("#directory-list li").removeClass("space-highlighted");
		jQuery("#map" + jQuery(this).attr("id")).addClass("space-highlighted");
		highlightRow(jQuery(this).attr("id"));
	});
	*/
	jQuery(".dir-table-space").click(function(event){
		event.preventDefault();
		jQuery("#directory-list li").removeClass("space-highlighted");
		jQuery("#map" + jQuery(this).parent().attr("id")).addClass("space-highlighted");
		highlightRow(jQuery(this).parent().attr("id"));
		scrollToAnchor("#directory-map");
	});
	
	function showTooltip(id) {
		jQuery("#map-tooltip").css("top", id.css("top"));
		jQuery("#map-tooltip-inner").text(id.data("store-title"));
		jQuery("#map-tooltip").show();
		//var tipWidth = parseFloat(jQuery("#map-tooltip").css("width"));
		var tipWidth = jQuery("#map-tooltip").width();
		//var left = parseFloat(id.css("left")) - (width / 2);
		var tipTop = id.offset().top - 45;
		var tipLeft = Math.round(id.offset().left - (tipWidth / 2)) + 12;
		//jQuery("#map-tooltip").css("left", left + "px");
		jQuery("#map-tooltip").offset({top: tipTop, left: tipLeft});
	}
	
	function hideTooltip() {
		jQuery("#map-tooltip").hide();
	}
	
	function highlightRow(id) {
		jQuery(".dir-table-store").removeClass("store-highlighted");
		jQuery("#" + id).addClass("store-highlighted");
	}
	
	function highlightArea(id) {
		
	}
	
	function hideArea() {
		
	}
});
