var WebsAlbum = {title:"",pics:[],thumbs:[],titles:[],widths:[],heights:[],captions:[],TOTAL_PICS:0,
  constrainDimensions : function(index,maxW,maxHeight) {
    var w = this.widths[index]*1;
    var h = this.heights[index]*1;
    var ratio = w/h;
    var maxH = maxHeight||maxW;
    if(w<=maxW && h<=maxH) {
      return [w,h];
    }

    h = Math.round(maxW/ratio);
    if(h>maxH) {
      return [Math.round(maxH*ratio),maxH];
    }

    return [maxW,h];
  },
  thumbWidth : function(index,maxW,maxH) {
    if(maxH) {
      if(this.thumbHeight(index,maxW)<=maxH) {
        return this.thumbWidth(index,maxW);
      } else {
        return maxH*this.widths[index]/this.heights[index];
        return this.thumbWidth(index,maxH);
      }
    } else {
    var maxSize = maxW;
    if(this.widths[index]*1 > this.heights[index]*1) {
      return Math.round(maxSize);
    } else {
      return Math.round(maxSize*(this.widths[index]/this.heights[index]));
    }
    }
  },
  thumbHeight : function(index,maxW,maxH) {
    if(maxH) {
      if(this.thumbHeight(index,maxW)<=maxH) {
        return this.thumbHeight(index,maxW);
      } else {
        return maxH;
      }
    } else {
    var maxSize = maxW;
    if(this.heights[index]*1 > this.widths[index]*1) {
      return Math.round(maxSize);
    } else {
      return Math.round(maxSize*((this.heights[index]*1)/(this.widths[index]*1)));
    }
    }
  },
  deletePic : function(index) {
    this.TOTAL_PICS--;
    for(i=index;i<this.TOTAL_PICS;i++) {
      this.pics[i]=this.pics[i+1];
      this.thumbs[i]=this.thumbs[i+1];
      this.titles[i]=this.titles[i+1];
      this.captions[i]=this.captions[i+1];
      this.widths[i]=this.widths[i+1];
      this.heights[i]=this.heights[i+1];
    }
  },
  swap : function(i,j) {
    t1=this.pics[i];
    t2=this.thumbs[i];
    t3=this.titles[i];
    t4=this.captions[i];
    t5=this.widths[i];
    t6=this.heights[i];
    this.pics[i]=this.pics[j];
    this.thumbs[i]=this.thumbs[j];
    this.titles[i]=this.titles[j];
    this.captions[i]=this.captions[j];
    this.pics[j]=t1;
    this.thumbs[j]=t2;
    this.titles[j]=t3;
    this.captions[j]=t4;
    this.widths[j]=t5;
    this.heights[j]=t6;
  },
  addEntry : function(p,th,t,c,w,h) {
    this.pics[this.TOTAL_PICS]=p;
    this.thumbs[this.TOTAL_PICS]=th;
    this.titles[this.TOTAL_PICS]=t;
    this.captions[this.TOTAL_PICS]=c;
    this.widths[this.TOTAL_PICS]=w;
    this.heights[this.TOTAL_PICS]=h;
    this.TOTAL_PICS++;
  }
};
