function dhtmlQuickDropdown(name, cssClass) {
	var tmpObj = new Object();

	tmpObj.name = name;
	tmpObj.cssClass = cssClass;
	tmpObj.items = new Array();
	tmpObj.addQuickItem = objAddLinkItem;
	tmpObj.addTextItem = objAddTextItem;
	tmpObj.draw = objDraw;
	tmpObj.separator = "<div class=\"hr\"><img src=\"/common/images/spacer.gif\" width=\"1\" height=\"1\" alt=\"\" border=\"0\"></div>";
	
	return tmpObj;
}

function objAddLinkItem(itemName, itemValue) {
	/*
		set arguments[2] to override the default class name
	*/

	var tmpItem = new Object();
	tmpItem.name = itemName;
	tmpItem.value = itemValue;
	tmpItem.cssClass = this.cssClass + "Item";
	tmpItem.sep = true;
	if (arguments.length > 2) {
		tmpItem.cssClass = arguments[2];
		tmpItem.sep = false;
	}
	this.items[this.items.length] = tmpItem;
}

function objAddTextItem(itemText, itemClass) {
	var tmpItem = new Object();
	tmpItem.name = itemText;
	tmpItem.value = "";
	tmpItem.cssClass = itemClass;
	tmpItem.sep = false;
	this.items[this.items.length] = tmpItem;
}

function objDraw() {
	if (isIE55) {
		document.write("<iframe id=\"" + this.name + "Iframe\" class=\"" + this.cssClass + "Iframe\" frameborder=\"0\" src=\"javascript: void(0);\"></iframe>");
	}
	document.write("<div id=\"" + this.name + "\" class=\"" + this.cssClass + "\"><div class=\"" + this.cssClass + "ScrollBox\" id=\"" + this.name + "ScrollBox\">");
	for (var i = 0; i < this.items.length; i++) {
		if (this.items[i].value != "") {
			document.write("<a href=\"\" onclick=\"document.location='" + this.items[i].value + "'; return false;\" class=\"" + this.items[i].cssClass + "\">" + this.items[i].name + "</a>");
		} else {
			document.write("<span class=\"" + this.items[i].cssClass + "\">" + this.items[i].name + "</span>");
		}
		if (this.separator != "" && this.items[i].sep && i < (this.items.length - 1)) {
			document.write(this.separator);
		}
	}
	document.write("</div></div>");
}

function showDropdown(dropdownId) {
	if (pageLoaded) {
		hideCurrentDropdown();
		currentDropdown = dropdownId;
		
		findPosition(dropdownId);
		showLayer(dropdownId);
		if (isIE55) {
			setIframe(dropdownId);
			showLayer(dropdownId + "Iframe");
		}
		
		showLayer("hideDropdown");
	}
}

function hideCurrentDropdown() {
	if (currentDropdown != "") {

		/*
			Safari crashes when you try to rescroll an invisible element.
			Scrolling while visible has small visual impact on everyone else.
			Instead, i only scroll visible on safari and scroll invisible for
			everyone else.
		*/
		if (navigator.userAgent.indexOf("Safari") == -1) {
			hideLayer(currentDropdown);
			document.getElementById(currentDropdown + "ScrollBox").scrollTop = 0;
		} else {
			document.getElementById(currentDropdown + "ScrollBox").scrollTop = 0;
			hideLayer(currentDropdown);
		}

		if (isIE55) {
			hideLayer(currentDropdown + "Iframe");
		}
	}
}

function findPosition(dropdownId) {
	obj = document.getElementById(dropdownId);

	triggerTop = document.getElementById(dropdownId + "TriggerImg").offsetTop;
	triggerHeight = document.getElementById(dropdownId + "TriggerImg").offsetHeight;

	obj.style.top = triggerTop + triggerHeight;
	obj.style.display = "block";

	dropdownHeight = obj.offsetHeight;
	dropdownTop = obj.offsetTop;
	windowHeight = document.body.clientHeight;
	if (window.innerHeight) {
		windowHeight = window.innerHeight;
	}
	scrollPosition = document.body.scrollTop;
	
	if (triggerTop > dropdownHeight) {
		if (triggerTop - dropdownHeight > scrollPosition && dropdownHeight + dropdownTop - scrollPosition > windowHeight) {
			obj.style.top = (triggerTop - dropdownHeight) + "px";
		}
	}

	
}

function resizeHideDropdown() {
	document.getElementById("hideDropdown").style.width = document.body.scrollWidth;
	document.getElementById("hideDropdown").style.height = document.body.scrollHeight;
}


currentDropdown = "";

document.write("<div id=\"hideDropdown\" onmousedown=\"hideLayer('hideDropdown'); hideCurrentDropdown(); return false;\"><img src=\"/common/images/spacer.gif\" width=\"99%\" height=\"99%\" border=\"0\" alt=\"\" galleryimg=\"no\"></div>");

addOnLoad(resizeHideDropdown);
