var My;
if ( !My ) My = {};

My.Riegger_ServiceNav = Class.create();

My.Riegger_ServiceNav.prototype =
{
	initialize: function( id, opts ) 
	{
		this.options = 
		{
			duration: 0.2,
			flyingY: false,
			flyingX: false
		}
		
		Object.extend( this.options, opts || {});
		
		this.id = id;
		this.isOpening = false;
		this.isClosing = false;
		
		this.runningEffect = null;
		
		$( this.id ).observe( 'mouseover', this._moveDown.bindAsEventListener( this ) );
		$( this.id ).observe( 'mouseout', this._moveUp.bindAsEventListener( this ) );
	},
	
	_moveDown: function ( event )
	{
		var node = Event.findElement( event, 'a' );
		if( node )
		{
			if( !this.isOpening )
			{
				this.isOpening = true;
				this.runningEffect = new Effect.Move( this.id, { x: 0, y: 5, mode: 'relative', duration: this.options.duration } );
			}
		}
	},
	
	_moveUp: function ( event )
	{
		var node = Event.findElement( event, 'a' );
		if( node )
		{
			if ( !this.isClosing && this.runningEffect != null )
			{
				this.isClosing = true;
				this.runningEffect.cancel();
				var newY = 0, newX = 0;
				if( this.options.flyingY == true || this.options.flyingX == true )
				{
					if ( window.innerWidth )
					{
						newY = window.pageYOffset;
						newX = window.pageXOffset;
					}
					else if ( document.documentElement && document.documentElement.clientWidth )
					{
						newY = document.documentElement.scrollTop;
						newX = document.documentElement.scrollLeft;
					}
					else if ( document.body && document.body.clientWidth )
					{
						newY = document.body.scrollTop;
						newX = document.body.scrollLeft;
					}
				}
				
				if( this.options.flyingX == false )
					newX = 0;
				if( this.options.flyingY == false )
					newY = 0;
					
				new Effect.Move( this.id, { x: newX, y: newY, mode: 'absolute', duration: this.options.duration, afterFinish: this._afterMoveUp.bindAsEventListener( this ) } );
			}
		}
	},
	
	_afterMoveUp: function ()
	{
		this.isOpening = false;
		this.isClosing = false;
		this.runningEffect = null;
	}
}