/*
This program is part of the Riley-Davey Inventory System.
Copyright (C) 2007 Jonathan Morgan

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/gpl.txt. 
 */

var centerLatitude = 42.40571364738738;
var centerLongitude = -83.04582595825195;
var description = "<b>Detroit Process Machinery Warehouse</b><br />6000 Caniff Ave.<br />Detroit, MI 48212 USA<br />(586) 469-0323 | Fax: (586) 469-3393<br />Email: sales@detroitprocessmachinery.com";
var startZoom = 11;
var createMapManager = false;
var mapManager = null;
var map = null;

function addMarker( latitude, longitude, description ) {
	createMarker( latitude, longitude, description, null );
}

function createMarker( latitude_IN, longitude_IN, description_IN, icon_IN )
{
    // return reference
    var marker_OUT = null;
    
    if ( ( icon_IN != null ) && ( icon_IN != "" ) )
	{
		// look up the icon in the iconHash
		var icon = iconHash[ icon_IN ]
		//alert ( "icon_IN = " + icon_IN + ", icon URL = " + icon.image );
	   	marker_OUT = new GMarker( new GLatLng( latitude_IN, longitude_IN ), icon );
    }
	else
	{
    	marker_OUT = new GMarker(new GLatLng(latitude_IN, longitude_IN));
    }

    GEvent.addListener(marker_OUT, 'click',
        function() {
            marker_OUT.openInfoWindowHtml(description_IN);
        }
    );

	if ( mapManager != null )
	{
		mapManager.addMarker( marker_OUT, 1 );
	}
	else
	{
		map.addOverlay( marker_OUT );
	}
    
    return marker_OUT;
} //-- end function createMarker() --//

function loadMapManager() {}

function load()
{
    if (GBrowserIsCompatible()) {	
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

		if ( createMapManager == true )
		{
			mapManager = new GMarkerManager( map );
			loadMapManager();
			
		    GEvent.addListener( map, 'moveend',
		        function() {
		            mapManager.refresh();
		        }
		    );
		    
		    GEvent.addListener( map, 'zoomend',
		        function( oldLevel_IN, newLevel_IN ) {
		            mapManager.refresh();
		        }
		    );
		}

        if ( ( description != null ) && ( description != "" ) )
        {
        	addMarker(centerLatitude, centerLongitude, description);
       	}
    }
}

addLoadEvent( load );
