


 $(document).ready(function() {


    $('a.thickbox').each(function(){
        var url = $(this).attr('href') + '?TB_iframe=false&height=600&width=750';

        $(this).attr('href', url);
    });

	$("ul.subnav li a:first").addClass('first');
	$("ul.subnav li a:last").addClass('last');


			var count = 1;		
			$(".map").each(function (i) {
				var mapId = "map"+count;
				$(this).attr("id", mapId);
				updateMap(mapId);
				count++;
			});

			$("td").each(function (i) {
				if($(this).text().length < 1)
					$(this).text('  ');
			});


});



$(window).unload( function () { 

	if(typeof GUnload == 'function') {
		GUnload();
	} 

});



function updateMap (mapId)
{

	var coords = $("#"+mapId).text().split(',');

	if (GBrowserIsCompatible()) {

		var map = new GMap2(document.getElementById(mapId));

		if(coords.length == 2) {
			var map_lat = coords[0];
			var map_long =  coords[1];
		}
		else {
			var map_lat = 54.65774;
			var map_long =  -5.79640;
		}

		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(map_lat, map_long), 14);

		// Create our "tiny" marker icon
		var icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);

		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();
		var point = new GLatLng(map_lat,map_long);
		map.addOverlay(new GMarker(point, icon));


	}

}
