ImageController = Class.create();
ImageController.prototype =
{
    initialize: function(imageContainerElement,navInfo,imageList)
    {
        this.container = imageContainerElement;
        this.navInfo = navInfo;
        this.imageList = imageList;
        this.currentImageIdx = 0;
    },
    init: function()
    {
        if(this.container)
        {
          var tmp = document.createElement("center");
          this.img = document.createElement("img");
          tmp.appendChild(this.img);

          this.container.appendChild(tmp);
        }
    },
    refresh: function()
    {
        if(this.container)
        {
          this.img.src = this.imageList[this.currentImageIdx].url;
          this.navInfo.update( (this.currentImageIdx + 1) + '/' + (this.imageList.length));
        }
    },
	getCurrentImageIdentifier: function()
	{
		return this._getIdentifier(this.currentImageIdx);
	},
    setCurrentImage: function(id)
    {
        if(this.container)
        {
          var idx = this._getIdx(id);
  
          if(idx >= 0)
          {
              this.currentImageIdx = idx;
          }
          else
              this.currentImageIdx = 0;
  
          this.refresh();
        }  
    },
    next: function()
    {
        this.currentImageIdx++;

        if(this.currentImageIdx >= this.imageList.length)
            this.currentImageIdx = 0;

        this.refresh();
    },
    previous: function()
    {
        this.currentImageIdx--;

        if(this.currentImageIdx < 0)
            this.currentImageIdx = (imageList.length - 1);

        this.refresh();
    },
    _getIdx: function(id)
    {
        var num = this.imageList.length;
        for(i = 0; i < num; i++)
        {
            if(this.imageList[i].id == id)
                return i;
        }

        return -1;
    },
	_getIdentifier: function(idx)
    {        
    	return this.imageList[idx].id;       
    }
};

