//Key: ABQIAAAA4OddcXHzC21kDIJ6NZlWMBS0z-ewmy48GcgmUMTOtsgFZ5hVHhQYH7RWSjb1XPAgp1cFaV1bsnLoTg
//Script URL: http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA4OddcXHzC21kDIJ6NZlWMBS0z-ewmy48GcgmUMTOtsgFZ5hVHhQYH7RWSjb1XPAgp1cFaV1bsnLoTg

ATI.GoogleMaps = {};

ATI.GoogleMaps.LatLon = new GLatLng(41.86887, -88.209566);
ATI.GoogleMaps.DirectionsLatLon = '41.8663484, -88.2076246';
ATI.GoogleMaps.Directions = null;

ATI.GoogleMaps.Icon = new GIcon(G_DEFAULT_ICON, 'images/favicon.png');
ATI.GoogleMaps.Icon.iconSize = new GSize(16, 16);
ATI.GoogleMaps.Icon.iconAnchor = new GPoint(8, 8);
ATI.GoogleMaps.Icon.shadow = 'images/favicon-shadow.png';
ATI.GoogleMaps.Icon.shadowSize = new GSize(18, 18);

ATI.GoogleMaps.LoadMap = function()
{
	if (GBrowserIsCompatible())
	{
		// ATI Marker
		var atiMarker = new GMarker(ATI.GoogleMaps.LatLon, { icon: ATI.GoogleMaps.Icon });
		
		// Initialization
		var localMap = new GMap2(document.getElementById('map-local'));
		localMap.setMapType(G_HYBRID_MAP);
		localMap.addControl(new GMapTypeControl());
		localMap.addControl(new GSmallZoomControl());
        localMap.setCenter(ATI.GoogleMaps.LatLon, 14);
        localMap.addOverlay(atiMarker);
        
        // Events
        GEvent.addListener(atiMarker, 'click', function() { this.openInfoWindow('<span style="color: #660000;"><strong>AssemTech, Inc.</strong><br />245 W. Roosevelt Rd.<br />Building 8, Unit 54<br />West Chicago, IL 60185</span>'); });
	}
};

ATI.GoogleMaps.LoadDirections = function()
{
	if (GBrowserIsCompatible())
	{
		// ATI Marker
		var atiMarker = new GMarker(ATI.GoogleMaps.LatLon, { icon: ATI.GoogleMaps.Icon });
		
		// Initialization
		var directMap = new GMap2(document.getElementById('map-directions'));
		ATI.GoogleMaps.Directions = new GDirections(directMap, document.getElementById('directions'));
		directMap.setMapType(G_HYBRID_MAP);
		directMap.addControl(new GMapTypeControl());
		directMap.addControl(new GSmallZoomControl());
		directMap.setCenter(ATI.GoogleMaps.LatLon, 3);
        directMap.addOverlay(atiMarker);
		
		// Events
		GEvent.addListener(atiMarker, 'click', function() { this.openInfoWindow('<span style="color: #660000;"><strong>AssemTech, Inc.</strong><br />245 W. Roosevelt Rd.<br />Building 8, Unit 54<br />West Chicago, IL 60185</span>'); });
		GEvent.addListener(ATI.GoogleMaps.Directions, 'load', ATI.GoogleMaps.DirectionsLoadTimeout);
		GEvent.addListener(ATI.GoogleMaps.Directions, 'error', ATI.GoogleMaps.DirectionsError);
	}
};

ATI.GoogleMaps.SetDirections = function(from, to)
{
	$('directions').hide();
	
	if (ATI.GoogleMaps.Directions != null)
		ATI.GoogleMaps.Directions.load('from: ' + from + ' to: ' + to);
};

ATI.GoogleMaps.DirectionsLoadTimeout = function()
{
	setTimeout('ATI.GoogleMaps.DirectionsLoad();', 2000);
};

ATI.GoogleMaps.DirectionsLoad = function()
{
	var points = $('directions').getElements('[jsselect=Placemark]').each(function(item, index)
	{
		item.getFirst().setStyle('background-color', '#AAAAAA');
		item.getFirst().setStyle('border-color', '#FFFFFF');
	});
	
	$('directions').show();
	ATI.UI.Layout();
};

ATI.GoogleMaps.DirectionsError = function()
{
	if (ATI.GoogleMaps.Directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert('No corresponding geographic location could be found for the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: ' + ATI.GoogleMaps.Directions.getStatus().code);
	else if (ATI.GoogleMaps.Directions.getStatus().code == G_GEO_SERVER_ERROR)
		alert('A geocoding or ATI.GoogleMaps.Directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: ' + ATI.GoogleMaps.Directions.getStatus().code);
	else if (ATI.GoogleMaps.Directions.getStatus().code == G_GEO_MISSING_QUERY)
		alert('The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For ATI.GoogleMaps.Directions requests, this means that no query was specified in the input.\n Error code: ' + ATI.GoogleMaps.Directions.getStatus().code);
	else if (ATI.GoogleMaps.Directions.getStatus().code == G_GEO_BAD_KEY)
		alert('The given key is either invalid or does not match the domain for which it was given. \n Error code: ' + ATI.GoogleMaps.Directions.getStatus().code);
	else if (ATI.GoogleMaps.Directions.getStatus().code == G_GEO_BAD_REQUEST)
		alert('A directions request could not be successfully parsed.\n Error code: ' + ATI.GoogleMaps.Directions.getStatus().code);
	else alert('An unknown error occurred.');
};

ATI.GoogleMaps.Unload = function()
{
	GUnload();
};