function MenuItem( LayerName, ImageName, Step ) {
	this.Active = false;
	this.LayerName = LayerName;
	this.ImageName = ImageName;
	this.Step = Step;
}

function FolderMenu( LeftOffset, TopOffset, Increment, UnactiveImage, ActiveImage ) {
	this.LeftOffset = LeftOffset;
	this.TopOffset = TopOffset;
	this.Increment = Increment;
	this.UnactiveImage = UnactiveImage;
	this.ActiveImage = ActiveImage;
	
	this.Offset = this.TopOffset;
	this.Count = 0;
	this.Items = new Array();
	
	this.NewItem = NewItem;
	this.Click = Click;
	this.Correct = Correct;
	this.Collapse = Collapse;
	
	function NewItem( LayerName, ImageName, Step ) {
		this.Items[ this.Count ] = new MenuItem( LayerName, ImageName, Step );
		this.Count++;
		return this.Count;
	}

	function Click( ItemNum ) {
		this.Items[ ItemNum ].Active = !this.Items[ ItemNum ].Active;
		if( this.Items[ ItemNum ].ImageName.length > 0 )
			if( this.Items[ ItemNum ].Active )
				ChangeLayerImage( this.Items[ ItemNum ].LayerName, this.Items[ ItemNum ].ImageName, this.ActiveImage );
			else
				ChangeLayerImage( this.Items[ ItemNum ].LayerName, this.Items[ ItemNum ].ImageName, this.UnactiveImage );	
		if ( this.Count - 1 > ItemNum ) {
			SubItems = true;
			if( this.Items[ ItemNum ].Active )
				for( Counter = ItemNum + 1; Counter < this.Count; Counter++ ) {
					if( this.Items[ Counter ].Step <= this.Items[ ItemNum ].Step )
						SubItems = false;
					if( SubItems && ( this.Items[ Counter ].Step == this.Items[ ItemNum ].Step + 1 ) )
						ShowLayer( this.Items[ Counter ].LayerName );
				}
			else
				for( Counter = ItemNum + 1; Counter < this.Count; Counter++ ) {
					if( !( this.Items[ Counter ].Step > this.Items[ ItemNum ].Step ) ) SubItems = false;
					if( SubItems ) {
						if( this.Items[ Counter ].ImageName.length > 0 )
							ChangeLayerImage( this.Items[ Counter ].LayerName, this.Items[ Counter ].ImageName, this.UnactiveImage );
						HideLayer( this.Items[ Counter ].LayerName );
						this.Items[ Counter ].Active = false;
					}
				}
		}
		this.Correct();
	}

	function Correct() {
		this.Offset = this.TopOffset;
		for( Counter = 0; Counter < this.Count; Counter++ ) {
			SetLayerXPos( this.Items[ Counter ].LayerName, this.LeftOffset + this.Increment * this.Items[ Counter ].Step );
			SetLayerYPos( this.Items[ Counter ].LayerName, this.Offset );
			if( LayerIsVisible( this.Items[ Counter ].LayerName ) )
				this.Offset += GetLayerHeight( this.Items[ Counter ].LayerName );
		}
	}
	
	function Collapse() {
		for( Counter = 0; Counter < this.Count; Counter++ ) {
			if( this.Items[ Counter ].ImageName.length > 0 )
				ChangeLayerImage( this.Items[ Counter ].LayerName, this.Items[ Counter ].ImageName, this.UnactiveImage );
			this.Items[ Counter ].Active = false;
			if( this.Items[ Counter ].Step > 0 )
				HideLayer( this.Items[ Counter ].LayerName );
			else
				ShowLayer( this.Items[ Counter ].LayerName );
				this.Offset += GetLayerHeight( this.Items[ Counter ].LayerName );
		}
		this.Correct();
	}
}