// JavaScript Document

function DropdownMenu(delay)
{
	this.layers = new Array()
	this.delay	= (typeof(delay) == 'undefined')? 1 : delay;
	this.timeoutId = null;
	this.onDropdownClose = null;
	this.onDropdownOpen = null;
	this.lastSelected	= null;

	this.open = function(depth, currentId, relativeId, hAlign, vAlign) {
		var x, y;
		var div, relObj;
		var divOffset, relObjOffset;

		this.clearTimeout();

		div = this.$(currentId);
		relObj = this.$(relativeId);
		if (div && relObj) {
			divOffset = this.getOffset(div);
			relObjOffset = this.getOffset(relObj);

			if (isNaN(vAlign)) {
				switch (String(vAlign).toLowerCase()) {
					case 'top':
						y = relObjOffset.y - divOffset.height;
						break;
					case 'bottom':
						y = relObjOffset.y + relObjOffset.height;
						break;
					default:
						y = relObjOffset.y;
				}
			}
			else {
				y = relObjOffset.y + vAlign;
			}

			if (isNaN(hAlign)) {
				switch (String(hAlign).toLowerCase()) {
					case 'left':
						x = relObjOffset.x - divOffset.offsetWidth;
						break;
					case 'right':
						x = relObjOffset.x + relObjOffset.width;
						break;
					default:
						x = relObjOffset.x;
				}
			}
			else {
				x = relObjOffset.x + hAlign;
			}

			this.setDepth(depth, currentId);
			div.style.left = x + 'px';
			div.style.top = y + 'px';
			div.style.display = 'block';
			if (this.onDropdownOpen != null) {
				this.onDropdownOpen(currentId, relativeId);
			}
		}
		if (isIE6())
			hideSelectMenus();
		if (realZoomDivsPresent())
			emptyRealZoomDivs();
	}
	
	this.setDepth = function(depth, currentId)
	{
		if(typeof(this.layers[depth]) == 'undefined')
		{
			this.layers[depth] = new Array();
		}
		this.layers[depth][this.layers[depth].length] = currentId;
	}
	
	this.close = function(event)
	{
		var currentTarget, relatedTarget;
		var self = this;
		var timeoutFunction;
		
		event = (event)? event : window.event;
		
		currentTarget	= (window.event)? event.srcElement: event.target;
		relatedTarget	= (event.toElement)? event.toElement: event.relatedTarget;

		switch(event.type)
		{
			case 'mouseout':
				this.clearTimeout();
				timeoutFunction = function()
				{
					self.closeInactiveDepths(self.lastSelected);
					self.lastSelected = null;
				}
				this.lastSelected	= relatedTarget;
				this.timeoutId		= window.setTimeout(timeoutFunction, this.delay * 1000);
				break;
			case 'mouseover':
				this.closeInactiveDepths(currentTarget);
				break;
		}
	}

	this.closeInactiveDepths = function (object) {
		var i, j;
		var value = false;

		this.clearTimeout();
		for (i = this.layers.length - 1; i >= 0; i--) {
			if (typeof (this.layers[i]) !== 'undefined') {
				for (j = 0; j < this.layers[i].length; j++) {
					if (this.inContainer(object, this.$(this.layers[i][j]))) {
						return true;
					}
				}
				this.closeDepth(i);
			}
		}
		this.layers.length = 0;
		if (isIE6()) {
		setRealZoomDivs();
		if (realZOOMImageOuter.css('display') != 'block')
			showSelectMenus();
		}
		if (realZoomDivsPresent())
			fillRealZoomDivs();
		return value;
	}
	
	this.inContainer = function(object, container)
	{
		var tempObject = object;
		
		while(tempObject)
		{
			tempObject = tempObject.offsetParent;
			if(tempObject == container) {
				return true;
			}
		}
		return false;
	}
	
	this.closeDepth = function(depth)
	{
		var obj, i;
		
		if(typeof(this.layers[depth]) !== 'undefined')
		{
			for(i = 0; i < this.layers[depth].length; i++)
			{
				obj = this.$(this.layers[depth][i]);
				if(obj)
				{
					obj.style.display = 'none';
					if(this.onDropdownClose != null)
					{
						this.onDropdownClose(obj.id);
					}
				}
			}
			this.layers[depth].length = 0;
		}
	}
	
	this.$ = function(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=this.$(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	this.getOffset = function(obj) {
		var offset;
		var tempOffset;
		
		offset = {x:0, y:0, width:0, height:0};
	
		if(obj) {
			offset.x		+= obj.offsetLeft;
			offset.y		+= obj.offsetTop;
			offset.width	+= obj.offsetWidth;
			offset.height	+= obj.offsetHeight;
			
			if(obj.offsetParent) {
				tempOffset = this.getOffset(obj.offsetParent);
				offset.x		+= tempOffset.x;
				offset.y		+= tempOffset.y;
			}
		}
		
		return offset;
	}
	
	this.clearTimeout = function()
	{
		if(this.timeoutId !== null)
		{
			window.clearTimeout(this.timeoutId);
			this.timeoutId = null;
		}
	}
}

var dropdown = new DropdownMenu(.25);