var floatingElement = Class.create();
floatingElement.prototype = {
	initialize: function( elm, parent, offTop, offLeft){
		this.elm_name = elm;
		this.elm = $(elm);
		this.parent_name = parent;
		this.parent_elm = $(parent);
		this.to = null;
		this.elm.hide();
		this.offTop = offTop;
		this.offLeft = offLeft;
		this.setPosition();
		this.parent_elm.observe('mouseover', this.showElement.bindAsEventListener(this), false);
		this.parent_elm.observe('mouseout', this.hideElement.bindAsEventListener(this), false);
		this.elm.observe('mouseover', this.showElement.bindAsEventListener(this), false);
		this.elm.observe('mouseout', this.hideElement.bindAsEventListener(this), false);
	},
	
	setPosition: function(){
		var p = Position.cumulativeOffset(this.parent_elm);
		var h = this.parent_elm.getHeight();
		this.top = p[1] + h + this.offTop;
		this.left = p[0] + this.offLeft;
		this.elm.setStyle({top: this.top + 'px', left: this.left + 'px', zIndex: 666});
	},
	
	showElement: function(){
		if( this.to ){
			clearTimeout(this.to);
			this.to = null;
		}
		this.elm.show();
	},
	
	hideElement: function(e){
		//Event.stop(e);
		var selm = Event.element(e);
		//alert(selm.tagName + ', ' + selm.descendantOf(this.elm));
		if( !$(selm).descendantOf(this.elm) ){
			if( this.to ){
				clearTimeout(this.to);
				this.to = null;
			}
			this.to = setTimeout('_floatingElementHideElement("' + this.elm_name + '")', 200);
		}
	}
}

function _floatingElementHideElement(elm){
	$(elm).hide();
}

