/*************************************************************************

  Extends the PopupElement class to provide the BC map popups.

  Original Author:  Brian Stucky, January 23, 2007

  Tested and works with:
	Firefox 2.0.0.1, WinXP
	SeaMonkey 1.0.7, WinXP
	MS IE 7.0, WinXP
	Opera 9.1, WinXP
	Opera 8.52 and 7.54, WinXP, no opacity
	Safari 1.3.1
	Mozilla 1.7.8, WinXP, blinks
	Netscape 8.1 and 7.2, WinXP, blinks

  Tested and does not work with:
	Netscape 6.2.3, WinXP
	MS IE 5.0 and 5.1, MacOS 9.2

  Needs to be tested:
	Mozilla 1.2, MacOS 9.2
	MS IE 6.0, 5.5 and 5.0 WinXP
	MS IE 5.5 and 5.0, Win98
	Firefox 1.0.7/MacOS 10.3
	Konquerer 3.3.2

  Copyright(c) Bethel College, 2007

**************************************************************************/

// a subclass of the PopupElement Class
function MapPopup(delay, finalOpacity, increment, offset)
{
	var self = this;
	this.constructor(delay, finalOpacity, increment, offset);

	this.element.className = "popupdropshadow";

	// create the img element
	this.img = document.createElement("img");
	this.content.appendChild(this.img);

	// create the inner text element
	this.text = document.createElement("div");
	this.content.appendChild(this.text);
}

// create the prototype object for the subclass
MapPopup.prototype = new PopupElement(0, 0);
delete MapPopup.prototype.revealClosure;
delete MapPopup.prototype.delay;
delete MapPopup.prototype.opacity;
delete MapPopup.prototype.finalOpacity;

// set the constructor property for the subclass
MapPopup.prototype.constructor = PopupElement;

MapPopup.prototype.show = function(area)
{
	var self = this;

	if (area.alt)
		this.setContent("images-small/" + area.alt + ".jpg", area.alt);
	else
		this.setContent("none", "undefined");

	PopupElement.prototype.show.call(this);
}

MapPopup.prototype.setContent = function(img, text)
{
	this.img.src = img;
	this.text.innerHTML = text;
}

MapPopup.prototype.setEventHandlers = function()
{
	var areas = document.getElementsByTagName("area");

	for (var cnt = 0; cnt < areas.length; cnt++)
	{
		areas[cnt].onmouseover = show;
		areas[cnt].onmouseout = hide;
		areas[cnt].onmousemove = updatePos;

		// prefetch the image for the popup
		(new Image()).src = areas[cnt].alt + ".jpg";
	}
}

// create the mappopup object
var mappopup = new MapPopup(0, 100, 10, 8);

// create the (non-closure) event handler wrapper functions for the map
function show(mEvent)
{
	// get event for IE, if necessary
	if (!mEvent) mEvent = window.event;

	mappopup.updatePos(mEvent);
	mappopup.show(this);
}

function hide()
{
	mappopup.hide();
}

function updatePos(mEvent)
{
	// get event for IE, if necessary
	if (!mEvent) mEvent = window.event;

	mappopup.updatePos(mEvent);
}

