
(function($) {
	loc = {
		init : function()
		{
			var map;
			if (GBrowserIsCompatible()) {
				map = new GMap2(document.getElementById("map_canvas"));
				map.setCenter(new GLatLng(locationInfo.lat,locationInfo.lng), 13);
				map.setUIToDefault();
				var geocoder = new GClientGeocoder();
				var startIcon = new GIcon(G_DEFAULT_ICON);
				startIcon.image = "http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=glyphish_walk|fe7569";
				startIcon.size = new GSize(21,34);
				point = new GLatLng(locationInfo.lat, locationInfo.lng);
				var marker = new GMarker(point,{icon:startIcon});
				map.clearOverlays();
				map.addOverlay(marker);
				var html = ''+ locationInfo.address +'<br \/>'+ locationInfo.city +', '+ locationInfo.state +' '+ locationInfo.zip +', '+ locationInfo.country +'<br \/><a href="http://maps.google.com/maps?q='+ locationInfo.address +','+ locationInfo.city +','+ locationInfo.state +','+locationInfo.zip +'&oe=utf-8&um=1&ie=UTF-8&hq=&hnear='+ locationInfo.address +','+ locationInfo.city +','+ locationInfo.state +','+locationInfo.zip +'&gl=us&daddr='+ locationInfo.address +','+ locationInfo.city +','+ locationInfo.state +','+locationInfo.zip +'%2034677&ei=8-X6S9W6G4P58AafvoX9Cg&sa=X&oi=geocode_result&ct=directions-to&resnum=1&ved=0CBkQwwUwAA" target="_blank">Get Directions<\/a>';
				marker.openInfoWindowHtml(html);
				GEvent.addListener(marker, 'click', function(){ marker.openInfoWindowHtml(html); });
				if( locationInfo.stops.length > 0 ) {					
					var directions = new GDirections(map), path = locationInfo.stops.split(';');
					directions.loadFromWaypoints(path, {getPolyline:true,preserveViewport:true});
					GEvent.addListener(directions, 'addoverlay', function() {
						var num = directions.getNumGeocodes();
						var blueIcon = new GIcon(G_DEFAULT_ICON);
						blueIcon.image = "http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=glyphish_group|5b86ff";
						blueIcon.iconSize = new GSize(21, 34);
								
						var endmarker = directions.getMarker((num-1));
						var endpoint = endmarker.getPoint();
						var mrkr = new GMarker(endpoint,{icon:blueIcon});
						map.addOverlay(mrkr);
						
						for( var i = 0; i < num; i++ ) {
							var marker = directions.getMarker(i);
							if( marker ) map.removeOverlay(marker);
						}
						
					});
				}
			}
			
		}
	}
})(jQuery);
jQuery(document).ready(function(){ loc.init(); });
