function MapHandler(layers, map) {
  this.layers = layers;
  this.map = map;
  this.layerImagesByName = new Array();
  this.layerLabelsByName = new Array();
  this.layerCapitalsByName = new Array();
  this.activedLayer = null;
  for (var i=0; i<layers.childNodes.length; i++) {
    var item = layers.childNodes[i];
    if (item.className == "map-layer") {
      this.layerImagesByName[item.name] = item;
    }
    if (item.className == "map-layer-label") {
      this.layerLabelsByName[item.id] = item;
    }
    if (item.className == "map-layer-capital") {
      this.layerCapitalsByName[item.id] = item;
    }
  }
  for (var i=0; i<map.childNodes.length; i++) {
    var item = map.childNodes[i];
    item.handler = this;
    item.onmouseover = this.onMapAreaMouseOver;
    item.onmouseout = this.onMapAreaMouseOut;
    if (item.className == "map-layer") {
      this.layerImagesByName[item.name] = item;
      i++;
    }
  }
}
MapHandler.prototype.setActivedLayer = function(name, actived) {
  var layer = this.layerImagesByName[name];
  var layerLabel = this.layerLabelsByName[name + "NameLabel"];
  var layerCapital = this.layerCapitalsByName[name + "CapitalLabel"];
  if (this.activedLayer != null) this.activedLayer.className = "map-layer";
  if (layer != null) {
    this.activedLayer = layer;
    layer.className = actived ? "map-layer-actived" : "map-layer";
    layerLabel.className = actived ? "map-layer-label-actived" : "map-layer-label";
    layerCapital.className = actived ? "map-layer-capital-actived" : "map-layer-capital";
  }
}
//handlers
MapHandler.prototype.onMapAreaMouseOver = function() {
  this.handler.setActivedLayer(this.className, true);
}
MapHandler.prototype.onMapAreaMouseOut = function() {
  this.handler.setActivedLayer(this.className, false);
}

