//##############################################################################
//------------------------------------------------------------------------------
function ImageItem(url)
{
    Item.apply(this);
    
    this.url = url;
    this.bigURL = '';
    this.tile = null;
    this.bigTile = null;
    this.attached = false;
    this.link = null;
    this.bigLink = null;
    this.highlight = false;
}

ImageItem.prototype = new Item();

//------------------------------------------------------------------------------
ImageItem.prototype.isLoaded = function()
{
    return (this.tile ? true : false);
}

//------------------------------------------------------------------------------
ImageItem.prototype.getIdentifier = function()
{
    return this.url;
}

//------------------------------------------------------------------------------
ImageItem.prototype.addToWorld = function()
{   
    if(this.attached)
        return;
        
    var baseElement = document.getElementById('content');

    if(this.tile)
    {
        this.tile.style.visibility = 'hidden';
        
        if(this.link)
            baseElement.appendChild(this.link);
        else
            baseElement.appendChild(this.tile);
    }

    if(this.bigTile)
    {
        this.bigTile.style.visibility = 'hidden';

        if(this.bigLink)
            baseElement.appendChild(this.bigLink);
        else
            baseElement.appendChild(this.bigTile);
    }
    
    this.attached = true;
}
    
//------------------------------------------------------------------------------
ImageItem.prototype.removeFromWorld = function()
{
    if(!this.attached)
        return;
        
    var baseElement = document.getElementById('content');

    if(this.link)
        baseElement.removeChild(this.link);
    else if(this.tile)
        baseElement.removeChild(this.tile);
    
    if(this.bigLink)
        baseElement.removeChild(this.bigLink);    
    else if(this.bigTile)
        baseElement.removeChild(this.bigTile);    
     
    this.attached = false;
}
    
//------------------------------------------------------------------------------
ImageItem.prototype.setTile = function(img, link)
{
    this.tile = img;
    this.link = link;
    
    if(this.size)
    {
        if(img.naturalWidth > img.naturalHeight)
        {
            this.sizeX = this.size;
            this.sizeY =  img.naturalHeight * (this.size / img.naturalWidth);
        }
        else
        {
            this.sizeY = this.size;
            this.sizeX =  img.naturalWidth * (this.size / img.naturalHeight);
        }
    }
    
    this.attached = true;
}

//------------------------------------------------------------------------------
ImageItem.prototype.setBigTile = function(img, link)
{
    this.bigTile = img;
    this.bigLink = link;
}

//------------------------------------------------------------------------------
ImageItem.prototype.setHighlight = function(value)
{
	this.highlight = value;
}