
  // declare some variables in global scope to Internet Exploder doesnt choke -.-
  var map = Object;
  var loc = new Array();
  
  /**
    * Loads the normal map on the map page, and adds overlays to it.
    */
  function loadMap() {
    if (GBrowserIsCompatible()) {
      // make a new map 
      map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(-34.28, 145.86), 5); // set center of map 
      //map.addControl(new GLargeMapControl());   // add a pan/zoom control
      map.addControl(new GSmallMapControl());   // add a pan/zoom control
      setAllMarkers(loc); // add all of our markers
      GEvent.addDomListener(document.getElementById("map"),"DOMMouseScroll", wheelZoom);
      GEvent.addDomListener(document.getElementById("map"), "mousewheel", wheelZoom);
      map.enableContinuousZoom();
    }
  }
  
  /** 
    * Mouse wheel zoom functionality
    */
  function wheelZoom(event) { 
    if (event.cancelable) {
      event.preventDefault();
    }
    if (event.detail < 0 || -event.wheelDelta < 0) {
      increaseZoomLevel();
    }
    else {
      decreaseZoomLevel();
    }
  }
  
// All of our locations
loc = [
  {town:"Batemans Bay",latitude:"-35.710957",longitude:"150.176846",address:"34D Orient St",postcode:"2536",sitecode:"BTPZ",regioncode:"BTPZ"},
  {town:"Moruya",latitude:"-35.908965",longitude:"150.081362",address:"44 Vulcan St",postcode:"2537",sitecode:"BTQZ",regioncode:"BTQZ"},
  {town:"Narooma",latitude:"-36.22237841890217",longitude:"150.12690782546997",address:"Shop M15 Narooma Plaza",postcode:"2546",sitecode:"HH00",regioncode:"HH00"},
  {town:"Port Macquarie",latitude:"-31.430012",longitude:"152.906394",address:"Level 1, 9 Short Street",postcode:"2444",sitecode:"BSWZ",regioncode:"BSWZ"},
  {town:"Ballina",latitude:"-28.86875",longitude:"153.560564",address:"92 Tamar Street",postcode:"2478",sitecode:"BTGZ",regioncode:"BTGZ"},
  {town:"Lismore",latitude:"-28.806756",longitude:"153.276779",address:"Suite 4, Level 1, 29 Molesworth Street",postcode:"2480",sitecode:"BTHZ",regioncode:"BTHZ"},
  {town:"Taree",latitude:"-31.914483",longitude:"152.460598",address:"Level 1, 1 Pulteney St",postcode:"2430",sitecode:"BSTZ",regioncode:"BSTZ"},
  {town:"Tuncurry",latitude:"-32.177172",longitude:"152.501158",address:"Bridgepoint, Level 2, Suite 7, 1 Manning Street",postcode:"2428",sitecode:"BSSZ",regioncode:"BSSZ"},
  {town:"Wauchope",latitude:"-31.45819",longitude:"152.729619",address:"Shop 1 / 80 High Street",postcode:"2446",sitecode:"BSXZ",regioncode:"BSXZ"},
  {town:"Kadina",latitude:"-33.965168",longitude:"137.717167",address:"3 Gawler Terrace",postcode:"5554",sitecode:"HG70",regioncode:"HG70"},
  {town:"Clare",latitude:"-33.833667",longitude:"138.611276",address:"Shop 5, 266 Main North Road",postcode:"5453",sitecode:"HG40",regioncode:"HG40"},
  {town:"Minlaton",latitude:"-34.774703",longitude:"137.592274",address:"Community Health Service, 9 South Terrace",postcode:"5575",sitecode:"HG90",regioncode:"HG90"},

];

  /**
    * put all markers on the map based on our array of locations
    */ 
  function setAllMarkers(loc){
    for (i=0;i<loc.length;i++) {
     l = loc[i];
     pt = new GLatLng(l.latitude, l.longitude);
     l.marker = createMarker(pt,i);                  
     map.addOverlay(l.marker);                       
    }
  }

  /**
    * Create a marker
    */
  function createMarker(point, num) {
    opts = new Object();
    opts.title = loc[num].town;
    var marker = new GMarker(point, opts);
    GEvent.addListener(marker, "click", function() {
        showInfoWindow(num);
    });
    return marker;
  }
  /** 
    * Show the info window for a marker
    */
  function showInfoWindow(num) {
    loc[num].marker.openInfoWindowHtml('<span class="iwstyle"><span class="town">'+loc[num].town+'</span><br/><address>'+loc[num].address.replace(",","<br/>").replace(",","<br/>")+'</address><br/><span class="iwstyle_links"><a href="javascript:zoomIn('+num+');">Zoom to streetlevel</a><br/><a href="site.asp?sitecode='+loc[num].sitecode+'">More details about this location</a></span></span>');
  }
  /** 
    * Close the info window
    */
  function hideInfoWindow(num) {
    map.closeInfoWindow();
  }
  
  /** 
    * Hide all markers
    */
  function hideAllMarkers() {
    for (i=0;i<loc.length;i++) {
      loc[i].marker.hide();
    }
  }
  /** 
    * Show marker for given index in Locations array
    */
  function showMarkerForIndex(num) {
    loc[num].marker.show();
  }  
  /**
    * Show / Unhide all markers
    */
  function showAllMarkers() {
    for (i=0;i<loc.length;i++) {
      loc[i].marker.show();
    }
  }
  /**
    * Zoom to street level for index number (of locations array)
    */
  function zoomIn(num) {
    zoomToLocation(loc[num].latitude,loc[num].longitude,13);
  }
  /** 
    * Zoom out to state view for index number (of locations array);
    */
  function zoomOut(num) {
    zoomToLocation(loc[num].latitude,loc[num].longitude,6);
  }
  /**
    * Zoom to a particulat Latitude/Longitude with given zoomlevel
    */
  function zoomToLocation(lat, lon, zoomLevel){
      map.setCenter(new GLatLng(lat,lon),zoomLevel);
      document.getElementById('map').focus();
  }    
  /**
    * Set a marker on the map based on latitude and longitude
    */
  function setMarker(lat,lon) {
    point = new GLatLng(lat,lon);
    var marker = new GMarker(point);

    map.addOverlay(marker);
    return marker;
  }
	/** 
    * Increase zoom level by 1
    */
  function increaseZoomLevel() {
    var maxZoomLevel = 15; 
    var curZoomLevel = map.getZoom();
    if (curZoomLevel < maxZoomLevel) {
      map.setZoom(curZoomLevel+1);
    }
  }
  /** 
    * Decrease zoom level by 1
    */
  function decreaseZoomLevel() {
    var minZoomLevel = 1; 
    var curZoomLevel = map.getZoom();
    if (curZoomLevel > minZoomLevel) {
      map.setZoom(curZoomLevel-1);
    }
  }

/**
  * Loader method to blur from the menu to the map, this
  * prevents the menu from "sticking" open.
  */  
var sfBlur = function(targetid) {
  if (document.getElementById(targetid)) {
  	var sfEls = document.getElementById(targetid).getElementsByTagName('a');
  	for (var i=0; i<sfEls.length; i++) {
      var el = sfEls[i];
  		sfEls[i].onclick=function() {
        el.blur();
  			document.getElementById('map').focus();
  		}
  	}
  }
}
function sfInitBlur() {
  sfBlur('mapnav');
}
function initMapNav() {
	  sfHover("mapnav");
  	mcAccessible("mapnav");
}

