/*
	2009-04-06 OL:
		Added last class on each forth image

*/

function Album(_variableName, _albumType){
  this.variableName = _variableName;
  this.albumType = _albumType;
  this.aItems = new Array();
}

Album.prototype.add = function(_title, _description, _thumb, _medium, _hires, _photographer, _alt, _pixelSize, _format){
  this.aItems.push(new AlbumItem(_title, _description, _thumb, _medium, _hires, _photographer, _alt, _pixelSize, _format));
}

Album.prototype.printMiniBrowser = function(_targetID){
  var objA;
  var objIMG;
  
  for(i = 0; i < this.aItems.length; i++){
		var strClassName = "";

    objA = document.createElement("A");
    objA.href = "#";
    objA.id = this.variableName + "|" + i;
    objA.onclick = function() { eval(this.id.split("|")[0] + ".changeSelectedImage(" + this.id.split("|")[1] + ")"); return false; };
    
    objIMG = document.createElement("IMG");
    if(i == 0){
    	strClassName = "selected";
    }
    if(((i+1) % 4) == 0){
    	strClassName += " last";
   	}

   	objIMG.className = strClassName;
    objIMG.src = this.aItems[i].thumb;
    objIMG.title = this.aItems[i].alt;
    objIMG.alt = this.aItems[i].alt;
    objIMG.border = "0";
    objIMG.id = this.variableName + "" +  i;
    objIMG.onclick = function(){ return false; };

    objA.appendChild(objIMG);
    document.getElementById(_targetID).appendChild(objA);
  }
}

Album.prototype.changeSelectedImage = function(_iArrayPos){
  var theLink = document.getElementById(this.variableName + "bigImgLink");
  if(theLink != null){
    theLink.name = this.variableName + "|" + _iArrayPos;
    theLink.onclick = function() { eval(this.name.split("|")[0] + ".showLayer(" + this.name.split("|")[1] + ")"); return false; };
    var theLink2 = document.getElementById(this.variableName + "enlargeLink");
    theLink2.name = this.variableName + "|" + _iArrayPos;
    theLink2.onclick = theLink.onclick;
    var theImage = document.getElementById(this.variableName + "bigImg");
    theImage.src = this.aItems[_iArrayPos].medium;
    theImage.alt = this.aItems[_iArrayPos].alt;
    theImage.title = this.aItems[_iArrayPos].alt;
    var thePhotographer = document.getElementById(this.variableName + "bigImgPhotographer");
    if (thePhotographer != null)
        thePhotographer.innerHTML = this.aItems[_iArrayPos].photographer;
    var theTitle = document.getElementById(this.variableName + "bigImgTitle");
    if (theTitle != null)
        theTitle.innerHTML = this.aItems[_iArrayPos].title;
    var theDescription = document.getElementById(this.variableName + "bigImgDescr");
    if (theDescription != null)
        theDescription.innerHTML = this.aItems[_iArrayPos].description;

    for (i = 0; i < this.aItems.length; i++)
    {
    	var strClassName = "";
      if(i == _iArrayPos){
        strClassName="selected";
      }
	    if(((i+1) % 4) == 0){
	    	strClassName += " last";
	   	}
      document.getElementById(this.variableName + i).className  = strClassName
    }
  }
}

Album.prototype.showLayer = function(_iArrayPos){
  this.initNavButtons(_iArrayPos);
  showDownloadImage(this.aItems[_iArrayPos].medium, this.aItems[_iArrayPos].alt, this.aItems[_iArrayPos].photographer, this.aItems[_iArrayPos].pixelSize, this.aItems[_iArrayPos].format, this.aItems[_iArrayPos].title, this.aItems[_iArrayPos].description, this.aItems[_iArrayPos].hires);
}

Album.prototype.showVideoLayer = function(_iArrayPos){
  this.initNavButtons(_iArrayPos);
  showStreamingVideo(this.aItems[_iArrayPos].medium, this.aItems[_iArrayPos].alt, this.aItems[_iArrayPos].photographer, this.aItems[_iArrayPos].pixelSize, this.aItems[_iArrayPos].format, this.aItems[_iArrayPos].title, this.aItems[_iArrayPos].description, this.aItems[_iArrayPos].hires);
}

Album.prototype.initNavButtons = function(_iArrayPos){
  var objPrev = document.getElementById("dlPrev");
  if(_iArrayPos > 0){
    objPrev.name = this.variableName + "|" + (_iArrayPos-1);
    if(this.albumType == "Image")
      objPrev.onclick = function(){ eval(this.name.split("|")[0] + ".changeSelectedImage(" + this.name.split("|")[1] + ")"); eval(this.name.split("|")[0] + ".showLayer(" + this.name.split("|")[1] + ")"); return false; };
    if(this.albumType == "Video")
      objPrev.onclick = function(){ eval(this.name.split("|")[0] + ".showVideoLayer(" + this.name.split("|")[1] + ")"); return false; };
    objPrev.style.display = "inline";
  }
  else{
    objPrev.name = "";
    objPrev.onclick = function(){ return false; };
    objPrev.style.display = "none";
  }
  var objNext = document.getElementById("dlNext");
  if(_iArrayPos < this.aItems.length-1){
    objNext.name = this.variableName + "|" + (_iArrayPos+1);
    if(this.albumType == "Image")
      objNext.onclick = function(){ eval(this.name.split("|")[0] + ".changeSelectedImage(" + this.name.split("|")[1] + ")"); eval(this.name.split("|")[0] + ".showLayer(" + this.name.split("|")[1] + ")"); return false; };
    if(this.albumType == "Video")
      objNext.onclick = function(){ eval(this.name.split("|")[0] + ".showVideoLayer(" + this.name.split("|")[1] + ")"); return false; };
    objNext.style.display = "inline";
  }
  else{
    objNext.name = "";
    objNext.onclick = function(){ return false; };
    objNext.style.display = "none";
  }
}

function AlbumItem(_title, _description, _thumb, _medium, _hires, _photographer, _alt, _pixelSize, _format){
  this.title = _title;
  this.description = _description;
  this.thumb = _thumb;
  this.medium = _medium;
  this.hires = _hires;
  this.photographer = _photographer;
  this.alt = _alt;
  this.pixelSize = _pixelSize;
  this.format = _format;
}
