var Dropdown = Class.create({
	initialize: function (el) {
		this.el = el;
		this.id = this.el.id;
		this.ul = el.select('li ul').first() || false;
		this.flag = true;
		this.visible = false;
		if (!this.ul) return;
		this.el.observe('click', this.show.bindAsEventListener(this));
		this.el.observe('mouseover', this.forceHide.bindAsEventListener(this));
		document.observe('click', this.hide.bindAsEventListener(this));
	},
	show: function () {
		this.ul.setStyle({'left': '0px'});
		this.visible = true;
	},
	hide: function (e) {
		if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;
		var dChild = false;
		tg.ancestors().each(function (node) {
			console.log("ancestor "+node.id);
			if (node.id == this.id && this.visible) {
				dChild = true;
				throw $break;
			}
		});
		if (!dChild) {
			this.ul.setStyle({'left': '-999em'});
			this.flag = true;
			this.visible = false;
		}
	},
	forceHide: function () {
		if (this.flag) {
			this.ul.setStyle({'left': '-999em'});
			this.flag = false;
		}
	}
});