﻿﻿var map 		= null;
var geocoder 	= null;
var ie 			= 0;

function initialise(address,type,html)
{
    if (GBrowserIsCompatible())
    {
        //check if internet explorer
        if (document.all)
            ie = 1;
          
       	geocoder = new GClientGeocoder();
    	if (geocoder) 
    	{
    		geocoder.getLatLng (
          		address,
          		function(point) 
    			{
            		if (!point) 
    				{
              			//errorMsg("Load Map", "Address not found");
            		}
            		else
            		{
            			loadMap(point,15);
            			loadMarker(point,type,html);
            		}
          		}
        	);
      	}
    }
    else
    {
        errorMsg("Incompatible","Sorry, the Google Maps API is not compatible with this browser");
    }
}

function loadMap(centrePoint,zoomLevel)
{

    try
    {   
		if(document.getElementById("map_canvasShort"))
			map = new GMap2(document.getElementById("map_canvasShort"));
		else
			map = new GMap2(document.getElementById("map_canvas"));
				
        map.addControl(new GSmallMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(20,40)));
        //map.addControl(new GOverviewMapControl());
        //map.addControl(new GMapTypeControl());
        //map.addControl(new GScaleControl());
        map.setCenter(centrePoint, zoomLevel);
       
    }
    catch(e)
    {
        //errorMsg("Load Map", e.message);
    }
}      
 
function loadMarker(point,type,html)
{       
    try
    {          
        var icon = new GIcon();
        icon.iconSize = new GSize(30, 30);
        icon.shadowSize = new GSize(22, 20);
        icon.iconAnchor = new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(5, 1);
            
        switch (type)
        {
//            case "1": icon.image  = "http://google-maps-icons.googlecode.com/files/bar.png"; break;
			  case "1": icon.image  = "http://www.barsandnightclubs.com.au/img/fnicon.png"; break;

        }
       
        var marker = new GMarker(point, icon);
        
        //add event handler for clicking on marker
        GEvent.addListener(marker, "click", 
            function() 
            {
                marker.openInfoWindowHtml(html);
            }
        );
        
        map.addOverlay(marker);    
    }
    catch(e)
    {
        //errorMsg("Load Markers", e.message);
    }
}  
    
function errorMsg(title, description)
{
    var txt = title + ": There was a script error on this page\n\n";
    txt += "Error description: " + description + "\n\n";
    GLog.write(txt);
}
