/*This file creates a constructor function for a Google Maps object and adds a drawMap method that uses the properties of the object to add a Google map to the page.  The properties of the object are:*/
/*elementContaining-the containing element for the map*/
/*before-the element to insert the map before*/
/*elementId-id of the scripted element to contain the map*/
/*lat-Latitude of the point for the map to be centred on*/
/*lng-longitude of the point for the map to be centred on*/
/*magnify-zoom level of the map*/
/*markerText-text to be displayed in a marker at the map centre.  To not add this set the property of this to be ''.*/
/*style-if this property is specified inline styles are added to the scripted div containing the map*/

function map (elementContaining, before, elementId, lat, lng, zoom, markerText, style) {
    this.elementContaining = elementContaining;
    this.before = before;
    this.elementId = elementId;
    this.lat = lat;
    this.lng = lng;
    this.zoom = zoom;
    this.markerText = markerText;
    this.style = style;
} 

map.prototype.drawMap = function() {
    if (!GBrowserIsCompatible()) {return}
    var div = document.createElement('div');
    div.setAttribute('id', this.elementId);
    div.className = 'map';
    if (this.style) {
        div.setAttribute('style', this.style);
    }
    var parent = document.getElementById(this.elementContaining);
    var before = document.getElementById(this.before);
    parent.insertBefore(div, before);
    var gmap = new GMap2(document.getElementById(this.elementId));
    var centre = new GLatLng(this.lat, this.lng);
    var markerHTML = "<address>" + this.markerText + "</address>";
    gmap.setCenter(centre, this.zoom);
    var marker = new GMarker(centre);
    gmap.addControl(new GLargeMapControl);
    gmap.addControl(new GMapTypeControl);
    gmap.addControl(new GOverviewMapControl);
    gmap.addOverlay(marker);
    if (this.markerText){
        gmap.openInfoWindowHtml(centre, markerHTML);
        GEvent.addListener(marker, "click", function(){
            gmap.setCenter(centre, this.zoom);
            gmap.openInfoWindowHtml(centre, markerHTML);
        });    
    }                
}

window.onload = function() {
   var map2 = new map('content', 'afterMap', 'map', 44.136915437957285, -81.12789630889893, 13, 'Emke Schaab Climate Care Inc., <br />RR2 Box 109, 1583 Bruce Rd 4,<br /> Walkerton ON N0G 2V0');
map2.drawMap();
}
window.onunload = GUnload();

