function hoverevent_setupevent( listener, eventtype )
{
	Event.observe( listener.element, eventtype, function(event) { listener.handleEvent(event); } );
}

function hoverevent_handleevent( event )
{
	switch( event.type ) {
		
		case "mouseover":
			this.timer = window.setTimeout( this.action, this.duration );
			hoverevent_setupevent( this, "mouseout" );
			break;
			
		case "mouseout":
			if (this.timer != null) window.clearTimeout(this.timer);
			this.timer = null;
			break;
			
	}
}

function HoverEvent( element, duration, action )
{
	this.element = $(element);
	this.duration = duration;
	this.action = action;
	
	this.handleEvent = hoverevent_handleevent;
	
	this.timer = null;
	
	hoverevent_setupevent( this, "mouseover" );
}
