/**
 * SetaContainer
 * -------------------------
 * Copyright 2005 - Setasign - Jan Slabon
 * http://www.setasign.de
 */
function getX(o) {
	var l = 0;
	while (o.offsetParent) {
		l += o.offsetLeft;
		o = o.offsetParent;
	}
	
	return l;
}

function getY(o) {
	var t = 0;
	while (o.offsetParent && o.tagName != 'body') {
		t += o.offsetTop;
		o = o.offsetParent;
	}
	
	return t;
}


var currentContainer = null;
function SetaContainer(c) {
	
	this.c = c;
	this.show = function() {
		this.c.style.visibility = 'visible';
		this.x = getX(this.b) - (this.b.getAttribute('SetaAlign') == "left" ? (this.c.offsetWidth - this.b.offsetWidth) : 0);
		this.c.style.left = this.x+'px';
		this.y = (getY(this.b) + this.b.offsetHeight)
		this.c.style.top = this.y+'px';
		this.w = this.c.offsetWidth;
		this.h = this.c.offsetHeight;
		
		currentContainer = this;
	}
	
	this.hide = function() {
		this.c.style.visibility = 'hidden';
		currentContainer = null;
	}
	
	this.b = document.getElementById(this.c.getAttribute('button'));
	this.b.c = this;
	if (typeof this.b.onclick == 'function')
	    this.b._onclick = this.b.onclick;
	this.b.onclick = function() {
		if (currentContainer != null && currentContainer == this.c) 
			this.c.hide();
		else
			this.c.show();
			
	    if (typeof this._onclick == 'function')
	        this._onclick(); 
			
		if (this.tagName == "href")
		    return false;
		else
		    return true;
	}
	
	this.b.onmouseover = function() {
		if (currentContainer != null && currentContainer != this.c) {
			currentContainer.hide();
			this.c.show();
		}
	}
	
	this.isOver = function(e) {
		if (e == this.c)
			return true;
		if (e.parentNode)
			return this.isOver(e.parentNode);
		else
			return false;
	}
}


var _onmousedown = function(e) {
	var e = e || event;
	var srcE = e.srcElement || e.target;
	var cC = currentContainer;
	
	if (typeof(cC) != 'undefined' && cC != null && srcE.c != cC && !cC.isOver(srcE)) {
		currentContainer.hide();	
	}
}

if (window.attachEvent) {
	document.attachEvent('onmousedown', _onmousedown);
} else if (window.addEventListener) {
	document.addEventListener("mousedown", _onmousedown, false);
}

