var MenuTab = function( target ) {
	this.target = target;
	this.enabled = ( this.target.src.lastIndexOf( '_off.' ) != -1 );

  this.onTabOver = function( e ) {
		if ( this.enabled ) {
				var oRegExp = new RegExp( '_off\.' );
				if ( oRegExp.test( this.target.getAttribute( 'src' ) ) )
					this.target.setAttribute( 'src', this.target.getAttribute( 'src' ).replace( oRegExp, '_hover.' ) );
		}
  }
  this.onTabOut = function( e ) {
		if ( this.enabled ) {
				var oRegExp = new RegExp( '_hover\.' );
				if ( oRegExp.test( this.target.getAttribute( 'src' ) ) )
					this.target.setAttribute( 'src', this.target.getAttribute( 'src' ).replace( oRegExp, '_off.' ) );
		}
  }

  addListener( this.target, 'mouseover', Delegate.create( this, 'onTabOver' ) );
  addListener( this.target, 'mouseout', Delegate.create( this, 'onTabOut' ) );
}

function applyMenuBehaviour() {
	var menu = document.getElementById( 'menu' );
	if ( isSet( menu ) ) {
		var LIs = menu.getElementsByTagName( 'li' );
		if ( !isNull( LIs ) )
  		for( var i=0; i<LIs.length; i++ ) {
  			var images = LIs[ i ].getElementsByTagName( 'img' );
  			for( var j=0; j<images.length; j++ ) {
  				new MenuTab( images[ j ] );
  			}
  		}
	}
}

addListener( window, 'load', applyMenuBehaviour );