var klydoDropdown = Class.create({

	DEFAULT_WAIT:	1.5,
	showing:		false,
	timeout:		'',
	theElement:		'',
	parentName:		'',
	
	initialize: function( params ) {

		var elementName = params.element;
		
		if( params.wait ) {
		
			var wait	 = params.wait;
		
		} else {
			
			var wait	= this.DEFAULT_WAIT;
		
		}

		var el	= $( elementName );

		if( el ) {
					
			this.theElement	= el.select( '.BUTTON-square-dd-actual' )[0];
			this.parentName	= el.id;
			
			el.observe( 'click', function( i ) {
				
				var element = Event.element( i );
					
				if( this.showing && element != this.theElement && !element.isChildOf( this.theElement ) ) {
					
					this.showing = false;
					this.theElement.hide();
				
				} else {
					
					this.theElement.show();
					this.showing = true;
									
				}

				clearTimeout( this.timeout );
			
			}.bind(this));
			
			el.observe( 'mouseover', function( i ) {

				if( !this.showing ) {
					
					this.timeout	= setTimeout( function() {
					
						this.show();
					
					}.bind(this), ( wait * 1000 ) );
				
				}
							
			}.bind( this ).bind(wait));
			
			/**
			el.observe( 'mouseout', function( i ) {
			
				if( i.target.id != this.parentName && i.target.isChildOf( this.parentName ) === false ) {
					
					if( this.showing ) {
						
						this.showing = false;
						this.theElement.hide();
					
					}
	
					clearTimeout( this.timeout );
				
				}
							
			}.bind( this ));
			**/
			
			document.getElementsByTagName('body')[0].observe( 'mouseover', function( i ) {
				
				if( i.target.isChildOf( this.parentName ) === false ) {
						
					if( this.showing ) {
						
						this.showing = false;
						this.theElement.hide();
					
					}
	
					clearTimeout( this.timeout );
					
				}
											
			}.bind(this));
		
		} else {
			
			throw( 'Invalid element provided.' );
		
		}
	
	},
	
	show: function() {
	
		//if( this.showing ) {
		
			this.showing	= true;
			$( this.theElement ).show();
		
		//}
	
	}

});