// load the maps js
google.load("maps", "2");

function start_map() {
	var map_div = $('#map');
    gmap = new google.maps.Map2(map_div[0]);
    gmap.setUIToDefault();
    //gmap.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
	geocoder = new google.maps.ClientGeocoder();
}

function get_hash()
{
	
}

function clickables()
{
	$('.office').each(function()
	{
		$(this).mouseover(function()
		{
			$(this).addClass('officeOver');
		});
		$(this).mouseout(function()
		{
			$(this).removeClass('officeOver');
		});
	});
}

var prev_office = 0;

function show_office(slug,office_id,address,text)
{
	geocoder.getLatLng(
	    address,
	    function(point) {
	      if (!point) {
	        alert(address + " not found");
	      } else {
	        gmap.setCenter(point, 13);
	        var marker = new google.maps.Marker(point);
	        gmap.addOverlay(marker);
	        marker.openInfoWindowHtml(text);
	      }
	    }
	  );
	location.hash = '#'+slug;
	if($('#office_'+prev_office).length) $('#office_'+prev_office).removeClass('officeSelected');
	$('#office_'+slug).addClass('officeSelected');
	prev_office = slug;
}

function load_first()
{
	if(location.hash == '') $('.office:first').click();
	else {
		$('#office_'+location.hash.substr(1)).click();
	}
}

$(document).ready(function()
{
	start_map();
	clickables();
	load_first();
});