var centreLatitude = -37.803935;
var centreLongitude = 144.98065;
var startZoom = 16;

// http://maps.google.com.au/maps?f=q&hl=en&geocode=&q=131+george+st+fitzroy&sll=-37.804906,144.980779&sspn=0.002149,0.004275&ie=UTF8&ll=-37.803935,144.98065&spn=0.008596,0.017102&z=16&iwloc=addrvar
markers = [
  {
    'latitude': -37.805834,
    'longitude': 144.9805,
    'mname': 'The Compound Interest',
    'icon': 'tci-pin.png',
    'h':200,
    'w':152,
    'anchorH':200,
    'anchorW':60,
    'windowH':50,
    'windowW':100,
    'desc': '<div id="blurb"><h2>The Compound Interest:<br />Centre for The Applied Arts</h2><h3>89 George St<br />Fitzroy 3065<br /> +61 3 8060 9745</h3>Comprising <a href="http://www.asmallpress.com">A Small Press</a>, <a href="http://www.barkingsparrows.com">Barking Sparrows</a>, <a href="http://www.chaseandgalley.com">Chase &amp; Galley</a>, <a href="http://www.jackywinter.com">The Jacky Winter Group</a>, <a href="http://www.lamingtondrive.com">Lamington Drive</a>,<br />and a Secret Tunnel to Shebangabang.<br /></div>'
  }
];

var sparrowTabs = [
  new GInfoWindowTab("About us", 
        '')
];


var imagePath = 'images/';

var map;

function init() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    map.setMapType(G_NORMAL_MAP);
    map.addControl(new GSmallMapControl());
    var location = new GLatLng(centreLatitude,centreLongitude);
    map.setCenter(location, startZoom);

    for(i=markers.length-1; i>-1; i--) { 
      addMarker(markers[i]); 
    }  
  }
}

function addMarker(marker) {
  
  var pin;
  
  if(marker.icon!='') {
    var latlng = new GLatLng(marker.latitude,marker.longitude);
    
    var icon = new GIcon();
    icon.image = imagePath + marker.icon;
    icon.iconSize = new GSize(marker.w,marker.h);
    icon.iconAnchor = new GPoint(marker.anchorW,marker.anchorH);
    icon.infoWindowAnchor = new GPoint(marker.windowW,marker.windowH);
    pin = new GMarker(latlng, icon);
  } else {
    pin = new GMarker(latlng);
  }
  
  GEvent.addListener(pin, 'click',
    function() {
      if (marker.mname == 'Barking Sparrows HQ') {
        pin.openInfoWindowTabsHtml(sparrowTabs, {
          selectedTab:0,
          minWidth:500
        });
      } else {
        pin.openInfoWindowHtml(marker.desc, {
          maxWidth:300
        });
      }
    }
  );
  
  map.addOverlay(pin);
}

window.onload = init;
window.onunload = GUnload;