function vpobbmenu(menuid, leftAlign) {
	this.menucontainer = document.getElementById(menuid);
	this.menuobj = false;
	if (typeof(leftAlign) == 'undefined') this.leftAlign = false;
	else this.leftAlign = leftAlign;
}

vpobbmenu.prototype.show = function(html, keep) {
	if (typeof(keep) == 'undefined') keep = false;
	if (this.menucontainer.className.indexOf('active') == -1)
		this.menucontainer.className += ' active';
	if (! this.menuobj) {
		this.menuobj = document.createElement('DIV');
		this.menuobj.className = 'bbmenu';
		this.menuobj.style.top = 0;
		this.menuobj.style.left = 0;
		this.menuobj.style.visibility = 'hidden';
		this.menuobj.zIndex = 999999;
		document.body.appendChild(this.menuobj);
		this.menuobj.container = this.menucontainer;
	}
	if (this.menuobj.innerHTML != html) {
		this.menuobj.innerHTML = html;
		this.initMenu(keep);
	}
}

vpobbmenu.prototype.hide = function() {
	if (this.keepfunc)
		this.removeEventListener(this.menuobj, 'click', this.keepfunc, false);
	document.body.removeChild(this.menuobj);
	delete this.menuobj;
	this.menucontainer.className = this.menucontainer.className.replace(new RegExp('\\s*active', 'g'), '');
	if (this.clickfunc)
		this.removeEventListener(document.body, 'click', this.clickfunc, false);
}

vpobbmenu.prototype.initMenu = function(keep) {
	var x = 0, y = 0;
	var obj = this.menucontainer;
	while (obj.tagName != 'BODY') {
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	y += this.menucontainer.offsetHeight;
	if (! this.leftAlign) x += (this.menucontainer.offsetWidth - this.menuobj.offsetWidth);
	this.menuobj.style.top = y + 'px';
	this.menuobj.style.left = x + 'px';
	if (typeof(Animator) == 'function') {
		var height = this.menuobj.clientHeight;
		this.menuobj.style.height = 0;
		new Animator({ duration: 500, interval: 50 }).addSubject(new NumericalStyleSubject(this.menuobj, 'height', 0, height)).seekFromTo(0,1);
	}
	this.menuobj.style.visibility = 'visible';
	if (keep)
		this.clickfunc = function (obj) { return function (e) { if (! e) e = window.event; if (! obj.checkKeep(e)) obj.hide(); } }(this);
	else
		this.clickfunc = function (obj) { return function () { obj.hide() } }(this);
	this.addEventListener(document.body, 'click', this.clickfunc, false);
}

vpobbmenu.prototype.checkKeep = function(e) {
	var target = e.srcElement ? e.srcElement : e.target;
	var stop = false;
	while (target.tagName != 'BODY' && !( stop = (target == this.menuobj))) {
		target = target.parentNode;
	}
	return stop;
}

vpobbmenu.prototype.addEventListener = function(el, ev, func) {
	if (el.attachEvent) el.attachEvent('on' + ev, func);
	else el.addEventListener(ev, func, true);
}

vpobbmenu.prototype.removeEventListener = function(el, ev, func) {
	if (el.detachEvent) el.detachEvent('on' + ev, func);
	else el.removeEventListener(ev, func, true);
}
