/////////////////////////////////////////////////////
//	Purple Monkey
//
//  Drop Down Functions
//
//  For use w/ BrotherCake's Ultimate Drop Down Menu
//  in popup mode.
//
//	Created By: Brandon Tibbetts
//  Created On: ?
//
//	Last Modified On: 11/24/2005
//	Last Modified By: Ray Schauer
//
//
/////////////////////////////////////////////////////

// Add Recievers
um.addReceiver(selectMenu,'060');
um.addReceiver(deselectMenu,'070');

// Create Global Hashtable
var ht = new hashtable();

function openMenu(id,trigger,x,y) {
	//if the menu is ready
	if(um.ready) {

		//open and position the menu
		um.activateMenu(
			id,
			(um.getRealPosition(trigger.parentNode,'x')+x)+'px',
			(um.getRealPosition(trigger.parentNode,'y')+trigger.parentNode.offsetHeight+y)+'px'
		);

		// Add to hashtable - Don't worry about collisions.
		ht.add(id,trigger);
	}
}
function closeMenu(id,trigger) {
	//if the menu is ready
	if(um.ready) {
		//close menu
		um.deactivateMenu(id);
	}
}
function selectMenu(trigger) {
	var key = trigger.parentNode.getAttribute("id");
	menuItem = ht.get(key);
	if(menuItem != null) {
		menuItem.parentNode.className='selected';
	}
}
function deselectMenu(trigger) {
	var key = trigger.parentNode.getAttribute("id");
	menuItem = ht.get(key);
	if(menuItem != null) {
		menuItem.parentNode.className='';
	}
}
/////////////////////////////////////////////////////
// HASH TABLE
/////////////////////////////////////////////////////
function hashtable() {
	// Storage
	this.data = new Array();
	// Clear
	this.clear = function() {
		this.data = new Array();
	};
	// Get
	this.get = function(key) {
		return this.data[key];
	};
	// Add
	this.add = function(key, value) {
		if(key == null || value == null) {
			throw "NullKeyOrValueException [key: " + key + "; value: " + value + "]";
		} else {
			this.data[key] = value;
		}
	};
	// Size
	this.size = function() {
		return this.data.length;
	};
	// isEmpty
	this.isEmpty = function() {
		return (parseInt(this.size()) == 0) ? true: false;
	};
	// Has Key
	this.hasKey = function(key) {
		for (var i in this.data) {
			if(i == key && this.data[i] != null) {
				return true;
			} else {
				return false;
			}
		}
	};
	// Has Value
	this.hasValue = function(value) {
		for (var i in this.data) {
			if(i == value && this.data[i] != null) {
				return true;
			} else {
				return false;
			}
		}
	};

}