$(document).ready(function() {
	if(GBrowserIsCompatible()) {
		JMetroMap.loadMap();
		JMetroMap.viewMap();
		JMetroMap.startHashPolling();
	}
});

$(document).unload(function() {GUnload();});

JMetroMap = function() {};

JMetroMap.mapName = 'storesmap';
JMetroMap.metroName = '';
JMetroMap.expectedHash = '';

JMetroMap.viewState = 'overall';
JMetroMap.firstFilterType = '';
JMetroMap.secondFilterType = '';
JMetroMap.currentHoodId = 0;
JMetroMap.currentTag = '';
JMetroMap.currentStoreId= 0;
	
JMetroMap.map = null;
	
JMetroMap.storeInfo = new Object();
JMetroMap.hoodInfo = new Object();
JMetroMap.tagInfo = new Object();

JMetroMap.latLngStores = new Object();
JMetroMap.storeLatLngs = new Object();
JMetroMap.storeMarkers = new Object();
JMetroMap.storeScrollers = new Object();
JMetroMap.markerNum = 1;
	
JMetroMap.baseIcon = new GIcon();
JMetroMap.baseIcon.iconSize = new GSize(20, 34);
JMetroMap.baseIcon.iconAnchor = new GPoint(10, 34);
JMetroMap.baseIcon.infoWindowAnchor = new GPoint(10, 1);
JMetroMap.baseIcon.imageMap = [9,0,6,0,5,1,2,3,1,5,0,7,0,12,1,14,2,16,4,17,6,19,8,21,8,33,11,33,11,21,13,19,15,17,17,16,18,14,19,12,19,7,18,5,17,3,14,1,6,0,12,0,10,0];
JMetroMap.baseIcon.transparent = "/images/maps/marker_gray_xparent.png";

JMetroMap.blueIcon =  new GIcon(JMetroMap.baseIcon);
JMetroMap.blueIcon.image = "/images/maps/png/marker_blue.png";
JMetroMap.blueIcon.printImage = "/images/maps/gif/marker_blue.gif";
JMetroMap.blueIcon.mozPrintImage = "/images/maps/gifmoz/marker_blue.gif";

JMetroMap.windowOptions = new Object();
JMetroMap.windowOptions.maxWidth = 275;


//This functions loads the map in the div for the first time
JMetroMap.loadMap = 
function() {
	JMetroMap.map = new GMap2(document.getElementById(JMetroMap.mapName));
	if(!JMetroMap.map) {
		return;
	}
	JMetroMap.map.addControl(new GSmallZoomControl());
};


/*
This helper function performs a modulus
on floating point numbers
*/
JMetroMap.modulus = 
function(y, x) {
	var z = y - x * Math.floor((y / x));
	return z;
};


/*
This function returns an array of latitude/longitude pairs,
that lie in circle of radius r (in meters) around the given
latitude/longitude pair
*/
JMetroMap.calcPointsAroundLatLng = 
function(lat, lng, radius, numPoints) {
	//had problems with lat being a string, so this
	//is a crude way of forcing it to be a number
	lat = lat * 1;
	lng = lng * 1;
	var latRad = lat * (Math.PI / 180);
	var lngRad = lng * (Math.PI / 180);
	var radiusEarth = 6378.160 * 1000;
	var distanceRad = radius / radiusEarth;
	var degree = 0;
	var degreeRad = 0;
	var degreInterval = 360 / numPoints;
	var points = Array();

	for(var point = 0; point < numPoints; point++) {
		degree = point * degreInterval;
		degreeRad = degree * (Math.PI / 180);
		lat2Rad = Math.asin(Math.sin(latRad) * Math.cos(distanceRad) + Math.cos(latRad) * Math.sin(distanceRad) * Math.cos(degreeRad));
		if(Math.cos(lat2Rad) == 0) {
			lng2Rad = lngRad;
		}
		else {
			lng2Rad = JMetroMap.modulus(lngRad + Math.asin(Math.sin(degreeRad) * Math.sin(distanceRad) / Math.cos(latRad)) + Math.PI, 2 * Math.PI) - Math.PI;
		}
		lat2 = lat2Rad * (180 / Math.PI);
		lng2 = lng2Rad * (180 / Math.PI);
		points.push(new Array(lat2, lng2));
	}
	return points;
};


//For internal use only
JMetroMap.updateHash = 
function() {
	var hash = '#';
	if(JMetroMap.firstFilterType != '') {
		if(JMetroMap.firstFilterType == 'hood') {
			hash += 'h=' + encodeURIComponent(JMetroMap.currentHoodId);
		}
		else if(JMetroMap.firstFilterType == 'tag') {
			hash += 't=' + encodeURIComponent(JMetroMap.currentTag);
		}

		if(JMetroMap.secondFilterType != '') {
			if(JMetroMap.secondFilterType == 'hood') {
				hash += '&h=' + encodeURIComponent(JMetroMap.currentHoodId);
			}
			else if(JMetroMap.secondFilterType == 'tag') {
				hash += '&t=' + encodeURIComponent(JMetroMap.currentTag);
			}
		}

		if(JMetroMap.currentStoreId != 0) {
				hash += '&s=' +encodeURIComponent(JMetroMap.currentStoreId.toString());
		}
	}

	//cant get this to work in safari, anyway I try it
	if(navigator.userAgent.indexOf('Safari') == -1) {
		window.location.hash = hash;
		JMetroMap.expectedHash = hash;
	}
};


//For internal use only
JMetroMap.startHashPolling = 
function() {
	//cant get this to work in safari, anyway I try it
	if(navigator.userAgent.indexOf('Safari') == -1) {
			x = window.setInterval(
			function() {
			var winLocHash = window.location.hash;
			var expectedHash = JMetroMap.expectedHash.slice(1);
			if(window.location.hash.charAt(0) == '#') {
				winLocHash = window.location.hash.slice(1);
			}
			if(expectedHash != winLocHash) {
				JMetroMap.viewMap();
			}
		}, 200);
	}
};

//Should only be called when class is beign initialized
JMetroMap.addStoreInfo = 
function(storeId, neighborhoodId, latitude, longitude) {

	var x = Object();
	var point = null;
	var icon = null;
	var marker = null;

	x['storeId'] = storeId;
	x['neighborhoodId'] = neighborhoodId;
	x['latitude'] = latitude;
	x['longitude'] = longitude;
	JMetroMap.storeInfo[storeId] = x;

	JMetroMap.hoodInfo[neighborhoodId]['bounds'].extend(new GLatLng(latitude, longitude));
	JMetroMap.hoodInfo[neighborhoodId]['num']++;
	JMetroMap.hoodInfo[neighborhoodId]['stores'].push(storeId);
};


//Should only be called when class is being initialized
JMetroMap.addHoodInfo = 
function(neighborhoodId, neighborhoodCodename, neighborhoodName, city) {
	var hoodText = neighborhoodName;
	hoodText = hoodText.replace("&amp;", "&");	
	hoodText = hoodText.replace("&quot;", "\"");
	hoodText = hoodText.replace("&#039;", "'");
	hoodText = hoodText.replace("&lt;", "<");
	hoodText = hoodText.replace("&gt;", ">");	
	var cityText = city;
	cityText = cityText.replace("&amp;", "&");
	cityText = cityText.replace("&quot;", "\"");
	cityText = cityText.replace("&#039;", "'");
	cityText = cityText.replace("&lt;", "<");
	cityText = cityText.replace("&gt;", ">");

	JMetroMap.hoodInfo[neighborhoodId] = new Object();
	if(JMetroMap.metroName !== city && city !== neighborhoodName) {
		JMetroMap.hoodInfo[neighborhoodId]['name'] = neighborhoodName + ', ' + city;
		JMetroMap.hoodInfo[neighborhoodId]['nameText'] = hoodText + ', ' + cityText;
	}
	else {
		JMetroMap.hoodInfo[neighborhoodId]['name'] = neighborhoodName;
		JMetroMap.hoodInfo[neighborhoodId]['nameText'] = hoodText;
	}
	JMetroMap.hoodInfo[neighborhoodId]['num'] = 0;
	JMetroMap.hoodInfo[neighborhoodId]['bounds'] = new GLatLngBounds();	
	JMetroMap.hoodInfo[neighborhoodId]['stores'] = new Array();
};


//Should only be called when class is being initialized
JMetroMap.addTagInfo = 
function(tag, tagPretty) {
	if(typeof(JMetroMap.tagInfo[tag]) == 'undefined') {
		JMetroMap.tagInfo[tag] = new Object();
		JMetroMap.tagInfo[tag]['name'] = tag;
		JMetroMap.tagInfo[tag]['namePretty'] = tagPretty;
		JMetroMap.tagInfo[tag]['bounds'] = new GLatLngBounds();
		JMetroMap.tagInfo[tag]['stores'] =  new Array();
	}
};


//Should only be called when class is being initialized
//addTagStores should only be called after all addTagInfo()
//calls are done
JMetroMap.addTagStores = 
function(tag, storeId) {
	if(typeof(JMetroMap.storeInfo[storeId]) != 'undefined') {
		x = JMetroMap.storeInfo[storeId];
		//Some of the stores tags may not be in the tag cloud
		//because they are not popular enough, so we throw
		//those away.
		if(typeof(JMetroMap.tagInfo[tag]) != 'undefined') {
			JMetroMap.tagInfo[tag]['bounds'].extend(new GLatLng(x['latitude'], x['longitude']));
			JMetroMap.tagInfo[tag]['stores'].push(storeId);
		}
	}
};


//For internal use only
JMetroMap.addLatLngStore = 
function(latitude, longitude, storeId) {
	if(typeof(JMetroMap.latLngStores[latitude]) == 'undefined') {
		JMetroMap.latLngStores[latitude] = new Object();
	}
	if(typeof(JMetroMap.latLngStores[latitude][longitude]) == 'undefined') {
		JMetroMap.latLngStores[latitude][longitude] = new Array();
	}
	JMetroMap.latLngStores[latitude][longitude].push(storeId);
};


//For internal use only
JMetroMap.createStoreMarker =
function(latitude, longitude, storeId) {
	var store = JMetroMap.storeInfo[storeId];
	var point = new GLatLng(latitude, longitude);
	var storeIcon =  new GIcon(JMetroMap.baseIcon);
	var markerOptions = new Object();

	if(JMetroMap.markerNum < 131) {
		iconSuffix = '_' + JMetroMap.markerNum;
		JMetroMap.markerNum++;
	}
	else {
		iconSuffix = '_gray';
	}

	storeIcon.image = "/images/maps/png/marker" + iconSuffix + ".png";
	storeIcon.printImage = "/images/maps/gif/marker" + iconSuffix + ".gif";
	storeIcon.mozPrintImage = "/images/maps/gifmoz/marker" + iconSuffix + ".gif";
	markerOptions.icon = storeIcon;
	markerOptions.clickable = true;
	markerOptions.title = $('#storebubbledesc'+storeId+' h3').html();

	var marker = new GMarker(point, markerOptions);

	GEvent.addListener(marker, "click", 
	function() {
		var infoTabs = new Array();

		$('#storebubbledesc'+storeId+' .photo').attr('src', $('#storebubbledesc'+storeId+' .imageSrc').html());
		html = $('#storebubbledesc'+storeId).html();
		infoTabs.push(new GInfoWindowTab('Description','<div class="storesmapbubbexcerpt">'+html+'</div>'));

		html = $('#storebubbledetails'+storeId).html();
		infoTabs.push(new GInfoWindowTab('Details', html));

		offset = $('#storesmapstores').offset();
		topHeight = offset.top;

		$('#storesmapstores').animate({scrollTop: JMetroMap.storeScrollers[storeId] - topHeight}, 1000, "easeOutExpo");

		marker.openInfoWindowTabsHtml(infoTabs, JMetroMap.windowOptions);

		JMetroMap.currentStoreId = storeId;

		JMetroMap.updateHash();
		
		window.scrollTo(0, 0);
	});

	return marker;
};


//For internal use only
JMetroMap.createHoodMarker =
function(neighborhoodId) {
	var bounds = JMetroMap.hoodInfo[neighborhoodId]['bounds'];
	var lat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat())/2;
	var lng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng())/2;
	var markerOptions = new Object();
	markerOptions.icon = JMetroMap.blueIcon;
	markerOptions.clickable = true;
	markerOptions.title = JMetroMap.hoodInfo[neighborhoodId]['nameText'] + ": " + 
		JMetroMap.hoodInfo[neighborhoodId]['num'] + " store(s)";
	var point = new GLatLng(lat, lng);	
	var marker = new GMarker(point, markerOptions);

	GEvent.addListener(marker, "click",
	function() {
		JMetroMap.viewFiltered(neighborhoodId, 'hood', true);
	});

	return marker;
};


//Here we zoom in on a store from any other state
JMetroMap.viewStore = 
function(storeId) {
	if(typeof(JMetroMap.storeInfo[storeId]) == 'undefined' ||
		(JMetroMap.viewState !== 'overall' && typeof(JMetroMap.storeMarkers[storeId]) == 'undefined')) {
		return;
	}

	if(JMetroMap.viewState == 'overall') {
		var store = JMetroMap.storeInfo[storeId];
		JMetroMap.viewFiltered(store['neighborhoodId'], 'hood', false);
	}	

	GEvent.trigger(JMetroMap.storeMarkers[storeId], "click");
};


//This sets the current hood/tag and then displays the store map
JMetroMap.viewFiltered = 
function(name, filterType, shouldUpdateHash) {
	var hood;
	var tag;
	var x;
	var y;


	if(filterType == 'hood') {
		if(typeof(JMetroMap.hoodInfo[name]) == 'undefined') {
			JMetroMap.viewHoods(true);
			return;
		}
		var hood = JMetroMap.hoodInfo[name];
	}
	else if(filterType == 'tag') {
		if(typeof(JMetroMap.tagInfo[name]) == 'undefined') {
			JMetroMap.viewHoods(true);
			return;
		}
		var tag = JMetroMap.tagInfo[name];
	}

	//Begin Window/Document work
	x = document.getElementById('storesmapfiltername1');
	y = document.getElementById('storesmapfiltername2');

	if(JMetroMap.firstFilterType == '' || JMetroMap.firstFilterType == filterType) {
		JMetroMap.firstFilterType = filterType;
		JMetroMap.secondFilterType = '';
		JMetroMap.currentStoreId = 0;
		if(filterType == 'hood') {
			JMetroMap.currentHoodId = name;
			JMetroMap.currentTag = '';
			x.innerHTML = ' &raquo; ' + '<a href="#" onclick="JMetroMap.viewFiltered(' + name + ', \'hood\', true); return false;">' + hood['name'] + '</a>';
		}
		else if(filterType == 'tag') {
			JMetroMap.currentTag = name;
			JMetroMap.currentHoodId = 0;
			x.innerHTML = ' &raquo; ' + '<a href="#" onclick="JMetroMap.viewFiltered(\'' + name + '\', \'tag\', true); return false;">' + tag['namePretty'] + '</a>';
		}
		y.innerHTML = '';
	}
	else if(JMetroMap.firstFilterType != filterType) {
		JMetroMap.secondFilterType = filterType;
		JMetroMap.currentStoreId = 0;
		if(filterType == 'hood') {
			JMetroMap.currentHoodId = name;
			y.innerHTML = ' &raquo; ' + '<a href="#" onclick="JMetroMap.viewFiltered(' + name + ', \'hood\', true); return false;">' + hood['name'] + '</a>';
		}
		else if(filterType == 'tag') {
			JMetroMap.currentTag = name;
			y.innerHTML = ' &raquo; ' + '<a href="#" onclick="JMetroMap.viewFiltered(\'' + name + '\', \'tag\', true); return false;">' + tag['namePretty'] + '</a>';
		}
	}

	if(shouldUpdateHash) {
		JMetroMap.updateHash();
	}

	JMetroMap.viewStores();

	window.scrollTo(0, 0);
};


//Helper function, For internal use only
//This shows all the stores in the selected tag/hood subset
JMetroMap.viewStores = 
function() {
	var hood;
	var tag;
	var boundsRef;

	if(JMetroMap.currentHoodId != '') {
		hood = JMetroMap.hoodInfo[JMetroMap.currentHoodId];
	}
	if(JMetroMap.currentTag != '') {
		tag = JMetroMap.tagInfo[JMetroMap.currentTag];
	}

	if(JMetroMap.currentHoodId != '') {
		boundsRef = hood;
		if(JMetroMap.currentTag != '') {
			JMetroMap.viewState = 'hybrid';
		}
		else {
			JMetroMap.viewState = 'hood';
		}
	}
	else if(JMetroMap.currentTag != '') {
		boundsRef = tag;
		JMetroMap.viewState = 'tag';
	}

	var lat = (boundsRef['bounds'].getNorthEast().lat() + 
		boundsRef['bounds'].getSouthWest().lat()) / 2;
	var lng = (boundsRef['bounds'].getNorthEast().lng() + 
		boundsRef['bounds'].getSouthWest().lng())/2;
	var marker;
	var stores;
	var x;
	var y;
	var i;
	var j;
	var k;


	JMetroMap.map.clearOverlays();
	JMetroMap.map.setCenter(new GLatLng(lat,lng));
	JMetroMap.map.setZoom(JMetroMap.map.getBoundsZoomLevel(boundsRef['bounds']));

	JMetroMap.latLngStores = new Object();
	JMetroMap.storeLatLngs = new Object();
	JMetroMap.storeMarkers = new Object();
	JMetroMap.storeScrollers = new Object();
	JMetroMap.markerNum = 1;

	if(JMetroMap.viewState == 'hood') {
		stores = hood['stores'];
	}
	else if(JMetroMap.viewState == 'tag') {
		stores = tag['stores'];
	}
	else {
		stores = new Array();
		var storesTemp = new Object();
		for(i in hood['stores']) {
			if(typeof(storesTemp[hood['stores'][i]]) == 'undefined') {
				storesTemp[hood['stores'][i]] = 1;
			}
			else {
				storesTemp[hood['stores'][i]]++;
			} 
		}
		for(i in tag['stores']) {
			if(typeof(storesTemp[tag['stores'][i]]) == 'undefined') {
				storesTemp[tag['stores'][i]] = 1;
			}
			else {
				storesTemp[tag['stores'][i]]++;
			} 
		}
	
		for(i in storesTemp) {
			if(storesTemp[i] == 2) {
				stores.push(i);
			}
		}
	}

	for(i in stores) {
		x = JMetroMap.storeInfo[stores[i]];
		JMetroMap.storeLatLngs[x.storeId] = new Array(x.latitude, x.longitude);
		JMetroMap.addLatLngStore(x.latitude, x.longitude, x.storeId);
	}

	for(i in JMetroMap.latLngStores) {
		for(j in JMetroMap.latLngStores[i]) {
			if(JMetroMap.latLngStores[i][j].length > 1) {
				if(JMetroMap.latLngStores[i][j].length < 5) {
					x = JMetroMap.calcPointsAroundLatLng(i, j, 4, JMetroMap.latLngStores[i][j].length);
				}
				else {
					x = JMetroMap.calcPointsAroundLatLng(i, j, 8, JMetroMap.latLngStores[i][j].length);
				}
				for(k in JMetroMap.latLngStores[i][j]) {
					JMetroMap.storeLatLngs[JMetroMap.latLngStores[i][j][k]][0] = x[k][0];
					JMetroMap.storeLatLngs[JMetroMap.latLngStores[i][j][k]][1] = x[k][1];
				}
			}
		}
	}

	for(i in JMetroMap.storeLatLngs) {
		marker = JMetroMap.createStoreMarker(JMetroMap.storeLatLngs[i][0], JMetroMap.storeLatLngs[i][1], i);
		JMetroMap.storeMarkers[i] = marker;
		JMetroMap.map.addOverlay(marker);
	}


	//Begin Window/Document work
	x = document.getElementById('storesmapintro');
	x.style.display = 'none';
	y = document.getElementById('storesmapstores');
	y.style.display = 'block';
	
	x = document.getElementById('storesmapnostores');
	if(stores.length == 0) {
		x.style.display = 'inline';
		x.style.visibility = 'visible';
	}
	else {
		x.style.display = 'none';
		x.style.visibility = 'hidden';
	}
	
	for(i in JMetroMap.hoodInfo) {
		x = JMetroMap.hoodInfo[i];
		y = document.getElementById('hood' + i);
		if(y) {
			y.className = 'inactive';
		}
	}

	for(i in JMetroMap.tagInfo) {
		x = JMetroMap.tagInfo[i];
		y = document.getElementById('tag' + i);
		if(y) {
			y.className = 'inactive';
		}
	}

	if(JMetroMap.currentHoodId != '') {
		y = document.getElementById('hood' + JMetroMap.currentHoodId);
		if(y) {
			y.className = 'active';
		}
	}

	if(JMetroMap.currentTag != '') {
		y = document.getElementById('tag' + JMetroMap.currentTag)
		if(y) {
			y.className = 'active';
		}
	}

	for(i in JMetroMap.storeInfo) {
		x = document.getElementById('store' + i);
		if(x) {
			x.style.display = 'none';
			x.style.visibility = 'hidden';
		}
	}

	for(i in stores) {
		x = document.getElementById('store' + stores[i]);
		if(x) {
			x.style.display = 'block';
			x.style.visibility = 'visible';
		}
	}

	x = document.getElementById('storesmapstores');
	x.scrollTop = 0;

	for(i in JMetroMap.storeMarkers) {
		x = JMetroMap.storeMarkers[i].getIcon();
		y = document.getElementById('storeMarker' + i);
		if(y) {
			y.src = x.printImage;
			y.width = 20;
			y.height = 34;
			offset = $('#storeMarker'+i).offset();
			JMetroMap.storeScrollers[i] = offset.top;
		}
	}
};


//This is overall view, with markers at each neighborhood
JMetroMap.viewHoods = 
function(shouldUpdateHash) {
	var bounds = new GLatLngBounds();
	var marker;
	var x;
	var y;
	var z;
	var i;

	JMetroMap.viewState = 'overall';
	JMetroMap.firstFilterType = '';
	JMetroMap.secondFilterType = '';
	JMetroMap.currentTag = '';
	JMetroMap.currentHoodId = 0;
	JMetroMap.currentStoreId = 0;


	JMetroMap.map.clearOverlays();
	JMetroMap.map.setCenter(new GLatLng(0, 0), 0);

	for(i in JMetroMap.hoodInfo) {
		marker = JMetroMap.createHoodMarker(i);
		bounds.extend(marker.getPoint());		
		JMetroMap.map.addOverlay(marker);		
	}

	JMetroMap.map.setZoom(JMetroMap.map.getBoundsZoomLevel(bounds));
	var lat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat())/2;
	var lng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng())/2;
	JMetroMap.map.setCenter(new GLatLng(lat,lng));

	//Begin Window/Document work
	x = document.getElementById('storesmapintro');
	x.style.display = 'block';
	y = document.getElementById('storesmapstores');
	y.style.display = 'none';
	
	for(i in JMetroMap.hoodInfo) {
		x = JMetroMap.hoodInfo[i];
		y = document.getElementById('hood' + i);
		if(y) {
			y.className = 'inactive';
		}
	}

	for(i in JMetroMap.tagInfo) {
		x = JMetroMap.tagInfo[i];
		y = document.getElementById('tag' + i);
		if(y) {
			y.className = 'inactive';
		}
	}

	for(i in JMetroMap.storeInfo) {
		x = JMetroMap.storeInfo[i];
		y = document.getElementById('store' + i);
		z = document.getElementById('storeMarker' + i);
		if(y) {
			y.style.display = 'block';
			y.style.visibility = 'visible';
		}
		if(z) {
			z.src = '/images/maps/marker_blank.gif';
			z.width = 1;
			z.height = 1;
		}
	}

	x = document.getElementById('storesmapnostores');
	y = document.getElementById('storesmapfiltername1');
	z = document.getElementById('storesmapfiltername2');

	x.style.display = 'none';
	x.style.visibility = 'hidden';
	y.innerHTML = '';
	z.innerHTML = '';

	x = document.getElementById('storesmapstores');
	x.scrollTop = 0;

	if(shouldUpdateHash) {
		JMetroMap.updateHash();
	}

	window.scrollTo(0, 0);
};


//This function looks at the current map URL and decides
//which specific map (hood/tag/store) to display
JMetroMap.viewMap = 
function() {
	var hoodDrawn = false;
	var tagDrawn = false;
	var storeDrawn = false;

	//cant get this to work right in safari, anyway I try it
	if(navigator.userAgent.indexOf('Safari') == -1) {
		if(window.location.hash.length > 1) {
			var hash = window.location.hash.slice(1);
			var hashParts = hash.split('&');
			var i;
			for(i = 0; i < hashParts.length && i < 3; i++) {
				hashPart = hashParts[i].split('=');
				if(hashPart.length > 1) {
					if(hashPart[0] == 'h' && (i == 0 || i == 1) && !hoodDrawn) {
						JMetroMap.viewFiltered(hashPart[1], 'hood', false);
						hoodDrawn = true;
					}
					else if(hashPart[0] == 't' && (i == 0 || i == 1) && !tagDrawn) {
						JMetroMap.viewFiltered(hashPart[1], 'tag', false);
						tagDrawn = true;
					}
					else if(hashPart[0] == 's' && (i == 1 || i == 2) && 
						(hoodDrawn || tagDrawn) && !storeDrawn) {
						JMetroMap.viewStore(hashPart[1]);
						storeDrawn = true;
					}
				}
			}
		}
	}

	if(!hoodDrawn && !tagDrawn && !storeDrawn) {
		JMetroMap.viewHoods(false);
	}

	if(navigator.userAgent.indexOf('Safari') == -1) {
		JMetroMap.expectedHash = window.location.hash;
	}
};
