$(document).ready(function(){
	hideLocations();
	$('#map a').click(function(){
		return showLocation($(this));
	});
	
	var path = document.location.toString();
	if (path.match('#')) {
		$("div.default").hide();
	}
});

function hideLocations() {
	$("#office_locations div.location").hide();	
}

function showLocation(item) {
	id = item.attr('href').replace('#', '');
		
	// Check if the element is already selected, if so do nothing
	if ($("#" + id).is(':visible')) {
		return false;
	}
	
	// Handle map marker selection
	$("#map a").removeClass("selected");
	$("#" + id + "_marker a").addClass("selected");
	
	// Handle information panel
	hideLocations();
	$("div.default").hide();
	$("#" + id).fadeIn("slow");
	
	document.location = item.attr('href');
	return false;
}
