
/*** create custom county markers **********************/

	var markers = [];
	var mgr;
	var icons = {};
	var allmarkers = [];

   function getIcon(images) {
      var icon = null;
      if (images) {
        if (icons[images[0]]) {
          icon = icons[images[0]];
        } else {
          icon = new GIcon();
          icon.image = "/img/buttons/"
              + images[0] + ".png";
          var size = iconData[images[0]];
          icon.iconSize = new GSize(size.width, size.height);
          icon.iconAnchor = new GPoint(size.width >> 1, size.height >> 1);
		  icon.infoWindowAnchor = new GPoint(12,2);
          size = iconData[images[1]];
          icons[images[0]] = icon;
        }
      }
      return icon;
    }

    function setupCountyMarkers() {
      allmarkers.length = 0;
      for (var i in counties) {
        var layer = counties[i];
        var countymarkers = [];
        for (var j in layer["places"]) {
          var place = layer["places"][j];
          var icon = getIcon(place["icon"]);
          var title = place["name"];
	  var reload = place["reload"];
          var posn = new GLatLng(place["posn"][0], place["posn"][1]);
          var townmarker = createMarker(posn,title,icon,reload);
          countymarkers.push(townmarker);
          allmarkers.push(townmarker);
        }

        mgr.addMarkers(countymarkers, layer["zoom"][0], layer["zoom"][1]);
      }
      mgr.refresh();
    }

    function createMarker(posn, title, icon, reload) {
      var marker = new GMarker(posn, {title: title, icon: icon });
      GEvent.addListener(marker, 'click', function() { location.href = reload; });
      return marker;
    }

/*** hide markers and restore them (if needed) **********************/


//GMarker.prototype.hide = function() {
//  if (this.getPoint().lat() < 90) {
//    try {
//        this.savePoint = this.getPoint();
//        this.setPoint(new GLatLng(90, 0));
//    } catch (e) { }
//  }
//}

//GMarker.prototype.show = function() {
//  if (this.getPoint().lat() == 90) {
//    if (this.savePoint) {
//      try {
//        this.setPoint(this.savePoint);
//        this.savePoint = null;
//      } catch (e) { }
//    }
//  }
//}



