var map;
var icon30;
var icon31;
var newpoints = new Array();

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function'){
      window.onload = func
  } else {
      window.onload = function() {
          oldonload();
          func();
      }
  }
}
addLoadEvent(loadMap);
addLoadEvent(addPoints);

function loadMap() {
  map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(54.97028, -2.45866), 15);

icon30 = new GIcon();
icon30.image = "http://www.myplacene.co.uk/downloads/30_icon.png";
icon30.shadow = "http://www.myplacene.co.uk/downloads/30_shadow.png";
icon30.iconSize = new GSize(15, 25);
icon30.shadowSize = new GSize(18, 28);
icon30.iconAnchor = new GPoint(8, 25);
icon30.infoWindowAnchor = new GPoint(8, 1);
icon30.infoShadowAnchor = new GPoint(18, 25);

icon31 = new GIcon();
icon31.image = "http://www.myplacene.co.uk/downloads/31_icon.png";
icon31.shadow = "http://www.myplacene.co.uk/downloads/31_shadow.png";
icon31.iconSize = new GSize(15, 25);
icon31.shadowSize = new GSize(18, 28);
icon31.iconAnchor = new GPoint(8, 25);
icon31.infoWindowAnchor = new GPoint(8, 1);
icon31.infoShadowAnchor = new GPoint(18, 25);
}

function addPoints() {
newpoints[0] = new Array(54.97009, -2.46483, icon30, 'Haltwhistle Health Centre','<strong>Haltwhistle Health Centre</strong><br />Greencroft Avenue, Haltwhistle  ,  NE49 9AP<br />T: 01434 320077<br /> <a href="http://www.myplacene.co.uk/redirect.aspx?type=web&point=247&url=http://www.nhs.uk/ServiceDirectories/Pages/GP.aspx?pid=8037DB63-25EF-496B-B96E-FFFC69ABC10B" target="_blank">Visit Website</a><br />');

newpoints[1] = new Array(54.97019, -2.46072, icon31, 'Haltwhistle Library','<strong>Haltwhistle Library</strong><br />Mechanics Institute, West Gate,  NE49 0AX <br />T: (01434) 320462<br /> <a href="http://www.myplacene.co.uk/redirect.aspx?type=web&point=254&url=http://www2.northumberland.gov.uk/PSCM/PSCMList_libraries.asp" target="_blank">Visit Website</a><br /> <br />See website for opening hours<br />');

newpoints[2] = new Array(54.97167, -2.46131, icon31, 'Haltwhistle Police Station','<strong>Haltwhistle Police Station</strong><br />Aesica Road, Haltwhistle,  NE49 9DJ<br />T: 03456 043 043<br />');

newpoints[3] = new Array(54.97193, -2.46609, icon31, 'Haltwhistle Swimming and Leisure Centre','<strong>Haltwhistle Swimming and Leisure Centre</strong><br />Woodhead Lane, Haltwhistle,  NE49 9DP<br />T: 01434 320727<br />');

newpoints[4] = new Array(54.9698, -2.46195, icon30, 'Haltwhistle War Memorial Hospital','<strong>Haltwhistle War Memorial Hospital</strong><br />Westgate, Haltwhistle NE49 9AJ<br />T: 01434 320 225<br /> <a href="http://www.myplacene.co.uk/redirect.aspx?type=web&point=246&url=http://www.northumbria.nhs.uk/menu.asp?id=232713" target="_blank">Visit Website</a><br />');

newpoints[5] = new Array(54.97569, -2.25004, icon30, 'Haydon & Allen Valleys Medical Practice','<strong>Haydon & Allen Valleys Medical Practice</strong><br />North Bank, Haydon Bridge, Hexham,  NE47 6LA<br />T: 01434 684216<br /> <a href="http://www.myplacene.co.uk/redirect.aspx?type=web&point=248&url=http://www.nhs.uk/ServiceDirectories/Pages/GP.aspx?pid=0FF7488A-3145-4E54-855A-5559B1046409" target="_blank">Visit Website</a><br />');

newpoints[6] = new Array(54.97374, -2.24709, icon31, 'Haydon Bridge Library','<strong>Haydon Bridge Library</strong><br />Church Street, Haydon Bridge  , Hexham,  NE47 6JQ  <br />T: (01434) 688857<br /> <a href="http://www.myplacene.co.uk/redirect.aspx?type=web&point=255&url=http://www2.northumberland.gov.uk/PSCM/PSCMList_libraries.asp" target="_blank">Visit Website</a><br /> <br />See website for opening hours<br />');

newpoints[7] = new Array(54.97285, -2.24869, icon31, 'Post Office','<strong>Post Office</strong><br />North Eastern & Cumbrian Co-op, 4 Ratcliffe Road, Haydon Bridge,  NE47 6ET<br />');

newpoints[8] = new Array(54.97055, -2.45948, icon31, 'Post Office','<strong>Post Office</strong><br />Belford House, Main Street, Haltwhistle,  NE49 0AZ<br />');

newpoints[9] = new Array(54.92183, -2.54583, icon31, 'Post Office','<strong>Post Office</strong><br />43 Leaside, Halton Lea Gate,  CA8 7LA<br />');

for(var i = 0 ; i < newpoints.length ; i++){
  var point = new GPoint(newpoints[i][1],newpoints[i][0]);
  var popuphtml = newpoints[i][4] ;
  var gtitle = newpoints[i][3] ;
  var marker = createMarker(point,newpoints[i][2], gtitle, popuphtml);
  map.addOverlay(marker);
  }
}

function createMarker(point, gicon, gtitle, popuphtml) {
  var popuphtml = "<div id=\"nepopup\">" + popuphtml + "<\/div>";
  var marker = new GMarker(point, {icon:gicon, title:gtitle });
  GEvent.addListener(marker, "click", function() {
  marker.openInfoWindowHtml(popuphtml);
  });
  return marker;
}
