/**
 * Drop Me (needs Prototype)
 *
 * by Matthias Kunze
 * Copyright (c) 2008
 */

var dropClass = 'dropme';
var showClass = 'dropmeOpen';

var timer = 0;

function initDropMe() {

		var dropArray = $$('.' + dropClass);
		dropArray.each(function (elem) {

				// trigger events
				var trigger = elem.previous();
				trigger.onmouseover = function () {
						clearTimeout(timer);
						showDrop(elem);
				}
				trigger.onmouseout = function () {
						timer = setTimeout(function () { hideDrop(elem); }, 200);
				}

				// list events
				elem.onmouseover = function () { clearTimeout(timer); timer = 0; }
				elem.onmouseout = function () { timer = setTimeout(function () { hideDrop(elem); }, 200); }
		});
}

function showDrop(dropElem) {

		// close open drops
		var openDrops = $$('.' + showClass);
		if (openDrops.length) {
				openDrops.each(function (elem) {
						hideDrop(elem);
				});
		}
		dropElem.className = showClass;
}

function hideDrop(dropElem) {
		dropElem.className = dropClass;
}

addLoadEvent(initDropMe);