//----------------------------------------------------------------------------------
// ALBUM.JS
// Copyright 2001, Burk Prael
// All rights reserved.
//----------------------------------------------------------------------------------


function AlbumDimObj (dimX, dimY)
{
  this.dimX = dimX;
  this.dimY = dimY;
}

//----------------------------------------------------------------------------------

function AlbumSetObj (prefix, maxDimX, maxDimY, displayMode, borderWidth, borderColor, captionStyle)
{
  this.prefix      = prefix;
  this.maxDimX     = maxDimX;
  this.maxDimY     = maxDimY;
  this.displayMode = displayMode;
  this.borderWidth = borderWidth;
  this.borderColor = borderColor;
  this.captionStyle= captionStyle;
}

//----------------------------------------------------------------------------------

function AlbumTitleObj (titleStr, separatorPos, separatorColor, separatorWidth, showIndexLink, justification)
{
  this.titleStr       = titleStr;
  this.separatorPos   = separatorPos;
  this.separatorColor = separatorColor;
  this.separatorWidth = separatorWidth;
  this.showIndexLink  = showIndexLink;
  this.justification  = justification;
}

//----------------------------------------------------------------------------------

function AlbumPicObj (picName, caption, capAlignment, pageIndex, titleIndex)
{
  this.picName        = picName;
  this.caption        = caption;
  this.capAlignment   = capAlignment;
  this.pageIndex      = pageIndex;      // including index values here to make stepping from one picture to the next easier
  this.titleIndex     = titleIndex;
}
//----------------------------------------------------------------------------------

function AlbumHtmlBlockObj (htmlBlock, layoutStyle, titleIndex, pageIndex)
{
  this.htmlBlock = htmlBlock;
  this.layoutStyle = layoutStyle;
  this.pageIndex  = pageIndex;
  this.titleIndex = titleIndex;
}

//----------------------------------------------------------------------------------

function AlbumLayoutObj (itemStr, itemIndex)
{
  this.itemDescr  = itemStr;
  this.itemIndex  = itemIndex;
}

//----------------------------------------------------------------------------------


function AlbumAddDim (albumSet, dimX, dimY)
{
  var N = this.dims[albumSet].length;
  this.dims[albumSet].length = N + 1;
  this.dims[albumSet][N] = new AlbumDimObj (dimX,dimY);
}

//----------------------------------------------------------------------------------
// parent.Al.addSet ('set1/', 500, 500, 1, 1, '#333333', 1 );

function AlbumAddSet (prefix, maxDimX, maxDimY, displayMode, borderWidth, borderColor, captionStyle)
{
  var N = this.sets.length;
  this.sets.length = N + 1;
  this.sets[N] = new AlbumSetObj (prefix, maxDimX, maxDimY, displayMode, borderWidth, borderColor, captionStyle);
  this.dims[N] = new Array ();
}

//----------------------------------------------------------------------------------

function AlbumAddPic (picName, caption, capAlignment) // ... =  dimX1, dimY1, dimX2, dimY2, dimX3, dimY3)
{
  var N = this.pics.length;
  this.pics.length = N + 1;
  this.pics[N] = new AlbumPicObj (picName, caption, capAlignment, this.pageIdx, this.titleIdx);

  s=0, l=3;
  while (l < arguments.length && s < this.sets.length)
  {
    // alert ('adding to set ' + s + ', l = ' + l + ',  x,y = ' + arguments[l] + ',' + arguments[l+1] );
    this.addDim (s, arguments[l], arguments[l+1]);
    l = l + 2;
    s++;
  }

  // alert ('adding to layout item');

  this.addLayoutItem ('pic', N);
}

//----------------------------------------------------------------------------------

function AlbumAddTitle (titleStr, separatorPos, separatorColor, separatorWidth, showIndexLink, justification)
{
  var N = this.titles.length;
  this.titles.length = N + 1;
  this.titles[N] = new  AlbumTitleObj (titleStr, separatorPos, separatorColor, separatorWidth, showIndexLink, justification);

  this.addLayoutItem ('title', N);

  this.titleIdx = N;
}

//----------------------------------------------------------------------------------

function AlbumAddSepLine ()  // oberved in mode 0 and 1 only (tile/enlargement // standalone)
{
  this.addLayoutItem ('sepLine', -1);
}

//----------------------------------------------------------------------------------

function AlbumAddHtmlBlock (htmlBlock, layoutStyle)  // first option only important in tile mode
{
  var N = this.htmlBlocks.length;
  this.htmlBlocks.length = N + 1;
  this.htmlBlocks[N] = new AlbumHtmlBlockObj (htmlBlock, layoutStyle, this.titleIdx, this.pageIdx);
  this.addLayoutItem ('htmlBlock', N);

}

//----------------------------------------------------------------------------------

function AlbumAddPageBreak ()  // only dealt with in tile mode
{
  // note the current layoutIndex in new node of pagebreak chain.

  var L = this.pageIndexes.length;
  this.pageIndexes.length = L + 1;
  this.pageIndexes[L] = this.layoutItems.length;

  this.addLayoutItem ('pageBreak', -1);

  this.pageIdx = L;
}

//----------------------------------------------------------------------------------

function AlbumAddLayoutItem (itemStr, itemIndex)
{
  var N = this.layoutItems.length;
  this.layoutItems.length = N + 1;

  // alert ('adding layout object - layoutItem, itemStr, itemIndex, this.titleIdx, this.pageIdx = ' + N + ') ' + itemStr + ':' + itemIndex + ', ' + this.titleIdx + ',' + this.pageIdx);

  this.layoutItems[N] = new AlbumLayoutObj (itemStr, itemIndex);

  this.layoutCount = N + 1;
}

//----------------------------------------------------------------------------------

function AlbumInit (albumPath, albumFile)
{
  this.albumPath   = albumPath;
  this.albumFile   = albumFile;

  // delete objects out of: sets array, dims array, pics array, htmlBlocks array
  this.titleIdx    = -1;
  this.pageIdx     = -1;
  this.layoutCount = -1;

  // arrays made of single datatypes can be simply set to 0
  this.sepLines.length  = 0;
  this.pageIndexes.length = 0;

  // reset array index for: layoutItems, titles, headerbars
  for (l=1; l< this.sets.length; l++)
  {
    delete this.sets[l];
    for (l2 = 1; l2 < this.dims[l].length; l2++)
    {
      delete this.dims[l][l2];
      this.dims[l].length = 0;
    }
  }
  this.dims.length = 0;
  this.sets.length = 0;

  for (l=1; l< this.titles.length; l++)
    delete this.titles[l];
  this.titles.length      = 0;

  for (l=1; l< this.layoutItems.length; l++)
    delete this.layoutItems[l];
  this.layoutItems.length = 0;

  for (l=1; l< this.htmlBlocks.length; l++)
    delete this.htmlBlocks[l];
  this.htmlBlocks.length = 0;

  for (l=1; l< this.pics.length; l++)
    delete this.pics[l];
  this.pics.length = 0;
}

//----------------------------------------------------------------------------------

function Album ()
{
  // -----    properties     -------

  this.sets        = new Array ();
  this.dims        = new Array (); // sub array declared setIndex, picIndex
  this.layoutItems = new Array (); // 'title', 'pageBreak', 'sepLine', 'htmlBlock','pic',
  this.titles      = new Array ();
  this.pageIndexes = new Array (); // array holding layoutItems indexes specificaly marking page breaks to speed up nav.
  this.sepLines    = new Array ();
  this.htmlBlocks  = new Array ();
  this.pics        = new Array ();

  this.titleIdx      = -1;
  this.pageIdx       = -1;
  this.layoutCount   = -1;

  this.albumPath   = "";
  this.albumFile   = "";

  // ----- linking in methods ------

  this.init         = AlbumInit;

  this.addSet       = AlbumAddSet;
  this.addDim       = AlbumAddDim;
  this.addLayoutItem= AlbumAddLayoutItem;
  this.addTitle     = AlbumAddTitle;
  this.addPageBreak = AlbumAddPageBreak;
  this.addSepLine   = AlbumAddSepLine;
  this.addHtmlBlock = AlbumAddHtmlBlock;
  this.addPic       = AlbumAddPic;
}

// alert ('object');


