function ImageDecoration(orientation, imageUrls)
{
	switch(orientation)
	{
		case ImageDecoration.VERTICAL:
		case ImageDecoration.HORIZONTAL:
			break;
		default:
			throw new Error("Invalid orientation");
	}
	
	if(imageUrls.length != 3)
	{
		throw new Error("Expected left, middle and right image");
	}
	
	this.orientation = orientation;
	this.imageUrls = imageUrls;
};

// ImageDecoration.prototype = new Decoration()..

ImageDecoration.prototype.install = function(widget)
{
	var doUpdate = false;
	
	widget.decoratorImages = new Array(3);
	for(var i = 0; i < this.imageUrls.length; i++)
	{
		doUpdate |= Toolkit.getImage(this.imageUrls[i], getMethodPointer(this, function(path, image, async, index) {
			widget.decoratorImages[index] = image;
			widget.domContainer.appendChild(image);
			
			if(async)
			{
                this.update(widget);
			}
		}), i);
	}
	
	if(doUpdate)
	{
		this.update(widget);
	}
};

ImageDecoration.prototype.uninstall = function(widget)
{
	if(widget.decoratorImages)
	{	
		for(var i = 0; i < 3; i++)
		{
			widget.decoratorImages[i].removeNode();
		}
		
		delete widget.decoratorImages;
	}
}

ImageDecoration.prototype.update = function(widget)
{
	var proceed = true;
	
	if(!widget.updateSuspended && widget.container)
	{
		for(var i = 0; i < widget.decoratorImages.length && proceed; i++)
		{
		    if(!widget.decoratorImages[i])
		    {
		        proceed = false;
		    }
		}
		
		if(proceed)
		{
			// if(widget.temp) alert("OK");
			var widgetPadding = widget.getPadding();
			
			switch(this.orientation)
			{
				case ImageDecoration.VERTICAL:
					var offsetTop = parseInt(widget.decoratorImages[ImageDecoration.LEFT].style.height) + widgetPadding.top;
					
					with(widget.decoratorImages[ImageDecoration.LEFT].style)
					{
						top = widgetPadding.top;
					}
					
					with(widget.decoratorImages[ImageDecoration.MIDDLE].style)
					{
						top = offsetTop;
						height = Math.max(widget.getHeight() - offsetTop - parseInt(widget.decoratorImages[ImageDecoration.RIGHT].style.height) - widgetPadding.bottom, 0);
					}
					
					with(widget.decoratorImages[ImageDecoration.RIGHT].style)
					{
						top = widget.getHeight() - parseInt(height) - widgetPadding.bottom;
					}
					
					break;
				case ImageDecoration.HORIZONTAL:
					var offsetLeft = parseInt(widget.decoratorImages[ImageDecoration.LEFT].style.width) + widgetPadding.left;
			
					with(widget.decoratorImages[ImageDecoration.LEFT].style)
					{
						left = widgetPadding.left;
					}
					
					with(widget.decoratorImages[ImageDecoration.MIDDLE].style)
					{			    
						left	= offsetLeft;
						width	= Math.max(widget.getWidth() - offsetLeft - parseInt(widget.decoratorImages[ImageDecoration.RIGHT].style.width) - widgetPadding.right, 0);
						top		= 0;
					}
					
					with(widget.decoratorImages[ImageDecoration.RIGHT].style)
					{
						left = widget.getWidth() - parseInt(width) - widgetPadding.right;
					}
					
					break;
				default:
			}
		}
	}
};

ImageDecoration.prototype.getMinimumSize = function(widget)
{
	var dimension = { width:-1, height:-1 };
	
	if(widget.decoratorImages)
	{
		for(var i = 0; i < 3; i++)
		{
			dimensions.width += parseInt(widget.decoratorImages[i].style.width);
			dimensions.height = Math.max(parseInt(widget.decoratorImages[i].style.height), dimensions.height);
		}

	}
	
	return dimensions;
};

ImageDecoration.prototype.toString = function()
{
	return "ImageDecoration [orientation = " + this.orientation + ", imageUrls = " + this.imageUrls + "]";
}

ImageDecoration.LEFT	= 0;
ImageDecoration.MIDDLE	= 1;
ImageDecoration.RIGHT	= 2;

ImageDecoration.VERTICAL	= 1;
ImageDecoration.HORIZONTAL	= 2;
