
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// MapSet code by Dell Sala
// Based on tooltips code created by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 06/13/04 ---------------------------------------------------------

window.maps = []; // global map array

function MapSet(mapId) {
   this.mapId = mapId;
   window.maps[MapSet.mapIndex] = this;
   this.mapIndex = MapSet.mapIndex;
   this.messageBox = new MapMessage(this.mapId + '_message');
   MapSet.mapIndex++;
}

MapSet.mapIndex = 0;

MapSet.prototype.setPoints = function (points) {
   this.points = points;
};

MapSet.prototype.init = function () {

	if (!document.getElementById) return;
	
	if (this.messageBox.div) {
      document.onmousemove = function (evt) {
         for (var i=0; i<window.maps.length; i++) {
            window.maps[i].messageBox.move (evt)
         }
      };
	}

	document.body.appendChild (this.messageBox.div);
	
   var map = document.getElementById(this.mapId);
   map.style.position = "relative";
	for (var i=0; i < this.points.length; i++) {
      point = this.points[i];
      var a = document.createElement("A");
      /*a.setAttribute('href', '#');*/
      a.pointIndex = i;
      a.innerHTML = point.label;
      a.mapIndex = this.mapIndex;
      a.onmouseover = function () {
         var point = window.maps[this.mapIndex].points[this.pointIndex];
         window.maps[this.mapIndex].messageBox.show(point);
      };
      a.onmouseout = function () { window.maps[this.mapIndex].messageBox.hide() };
      a.className = this.mapId+"_point";
      a.style.position = "absolute";
      a.style.display = "block";
      a.style.left = point.x + "px";
      a.style.top = point.y + "px";
      map.appendChild(a);
	}
	
};

function MapMessage (mapMessageId) {
   this.id = mapMessageId;
	this.offsetX = 20;
	this.offsetY = -10;
	this.div = document.createElement ("div");
	this.div.setAttribute ("id", this.id);
	this.div.style.position = "absolute";
	this.div.style.left = "0";
	this.div.style.top = "0";
	this.div.style.zIndex = "1000";
	this.div.style.display = "none";
}

MapMessage.prototype.move = function (evt) {
	var x=0, y=0;
	if (document.all) {// Explorer
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
	} else {// Mozilla
		x = evt.pageX;
		y = evt.pageY;
	}
	this.div.style.left = (x + this.offsetX) + "px";
	this.div.style.top = (y + this.offsetY) + "px";
};

MapMessage.prototype.show = function (point) {
	if (!this.div) return;
	var text = '<b>' + point.name + '</b>';
	for (var i=0; i < point.notes.length; i++) {
	  text += '<br>' + point.notes[i];
	}
	this.div.innerHTML = text;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.div.style.visibility = "visible";
	this.div.style.display = "block";
};

MapMessage.prototype.hide = function () {
	if (!this.div) return;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.div.style.visibility = "hidden";
	this.div.style.display = "none";
	this.div.innerHTML = "";
};




