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)
        {
          this.img = document.createElement("img");

          this.container.appendChild(this.img);
        }
    },
    refresh: function()
    {
        if(this.container)
        {
			if (this.imageList.length > 0)
			{
          		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;       
    }
};

showMoreImages=function(desc1,type,site,selectedImage,area,adress,lang,mapsource,cat)
{	
	var src = '';
	var opentab = '';
	
    if(typeof(selectedImage) != 'undefined')
    {
        var si = parseInt(selectedImage);
        if(si > 0)
            src = src + '&selectImage=' + si;
    }

    if(typeof(area) != 'undefined')
        src = src + '&area=' + area;

    if(typeof(adress) != 'undefined')
        src = src + '&address=' + adress;
	
    if(typeof(mapsource))
	src = src + '&mapsource=' + escape(mapsource);
	
    if(typeof(cat) != 'undefined')
    {
	switch(cat)
	{
	    case "0":
		opentab = "";
		break;
	    case "2":
		opentab = 3;
		break;
	    case "5":
		opentab = 4;
		break;
	    case "vr":
		opentab = 2;
		break;
	    default:
		opentab = 1;
		break;		
	}

    }
	src = '/app/projects/common/templates/appimage/imlib.php?KeepThis=true&bLang='+lang+'&bSite='+site+'&id=' + desc1 +'&type='+type+'&opentab=' + opentab + src;
	
	var myWidth = $jq(window).width();
	myWidth  = Math.round( (myWidth * 0.9) );
	
	var myHeight = $jq(window).height();
	myHeight  = Math.round( (myHeight * 0.9) );
	if (myHeight < 738)
		myHeight = 738;
	
    IP_show('',src + '&TB_iframe=true&height=' + myHeight + '&width=' + myWidth);
}



