/*

<html><head>

<title>CreateAlbum - Example</title>

<script type="text/javascript" src="./CreateAlbum.js"></script>

</head><body onUnload="javascript:newWin.close()">

<script type="text/javascript">
<!-- // hide from old browsers...
  self.document.writeln('<h4>HERE, you mouse over image to view it under HERE</h4>');

  CreateAlbum("http://webdeveloper.earthweb.com/repository/javascripts/2001/10/62881/", 
    "ghost", ".gif", 2, 6);
// for images in the webdeveloper directory +++ optional "open in a new window"

// -OR-

//  CreateAlbum("", "", ".jpg", 2, 6, 'newWin or anyText_beside_blank');
// for images (0001.jpg-9999.jpg) in the same directory +++ open in a new window

// Call (parmLocation, parmName, parmType, parmImages, parmImgPerRow [, parmNewWin] )...
// NOTE - do NOT use an image named anything"0".anything
// (example "ghost1.gif", "ghost92.gif", but NO "ghost0.gif" images, please.)

  self.document.write('<br><a href="CreateAlbum.js">Grab this script source with built in example!</a>');

// done hiding from old browsers...-->
</script>

<h4>This script example relies on the<br>
 halloween ghost images...  thank you ghost rider!</h4>

</body></html>

******************************************************************************************
   Copy above this into the BODY an HTML file (if this file isn't in the same directory as
   your HTML file, change the location reference of "CreateAlbum.js") to reflect the
   appropriate directory. This file is "CreateAlbum.js", be sure to place it in an
   appropriate directory.
******************************************************************************************

*/

<!-- // hide from old browsers...

var imagesarr = new Array;
var newWinSwitch, perRow, imgnum, index, Num, i = Number;
var imgtype, NxtPic, NumVal, newWin, imgloc, imgnam, myimg, qNam, img = String;

function CreateAlbum(imgloc, qNam, imgtype, imgnum, perRow, newWin)
{
  if (imgtype == null || imgtype == "")
  {
    return self.document.writeln("Image type is needed...");
  }

  if (imgnum == null || imgnum == 0)
  {
    return self.document.writeln("# of images is needed...");
  }

  if (perRow == null || perRow == 0)
  {
    return self.document.writeln("# of images per row is needed...");
  }

  if (CreateAlbum.arguments.length < 4)
  {
    return self.document.writeln("# of parms passed are not valid...");
  }

  self.document.writeln('<table>');
  self.document.writeln('<tr><td VALIGN="TOP">');
  self.document.writeln('<P>');
  self.document.writeln('<CENTER>');
  self.document.writeln('<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="12">');
  self.document.writeln('  <TR>');
  for (i = 1; i < imgnum + 1; i++)
  {
    var Num = "000" + i;
    var NumVal = Num.substr(Num.length - 4, Num.length);
    var imgnam = NumVal + imgtype;
    var myimg = imgloc + imgnam;

    if (qNam != null && qNam != "")
    {
      var Num = i;
      var NumVal = i;
      var imgnam = qNam + i + imgtype;
      var myimg = imgloc + imgnam;
    }

    var img = new Image(40,40);
    img.src = myimg;
    imagesarr[i - 1] = myimg;

    var NxtPic = '<TD WIDTH="25" HEIGHT="5" VALIGN="TOP">'
    NxtPic += '<A style="cursor: hand" '
    NxtPic += 'onclick="javascript:window.focus()" '
    NxtPic += 'onMouseOver="javascript:SwapImg('
    NxtPic += i
    NxtPic += ')">'
    NxtPic += '<IMG SRC="'
    NxtPic += imagesarr[i - 1]
    NxtPic += '" '
      NxtPic += 'onAbort="escapeErr()"'
      NxtPic += ' '
      NxtPic += 'onError="escapeErr()"'
      NxtPic += ' '
    NxtPic += 'WIDTH="106" HEIGHT="80" '
    NxtPic += 'ALIGN="BOTTOM"'
    NxtPic += imgnam
    NxtPic += '" BORDER="0" NAME="'
    NxtPic += imgnam
    NxtPic += '">'
    NxtPic += '</A></TD>'
    self.document.writeln(NxtPic);
    if (i % perRow == 0)
    {
      self.document.writeln('  </TR>');
      self.document.writeln('  <TR>');
    }
  }
  self.document.writeln('  </TR>');
  self.document.writeln('</TABLE>');
  self.document.writeln('</CENTER>');
  self.document.writeln('</P>');
  self.document.writeln('</td><td VALIGN="TOP">');

   if (newWin == null || newWin == "")
  {
    newWinSwitch = -1
    var ans = confirm("Create a seperate window for my display?")
    if (ans == true)
    {
      newWinSwitch = 1
    } else {
      CrtDumbWin();
    }
  }

  if (newWinSwitch > 0)
  {
    CrtNewWin(index);
  } else {
    self.document.writeln('<P>');
    self.document.writeln('<CENTER>');
    self.document.writeln('  <br><br>');
    self.document.writeln('    <IMG SRC="');
    self.document.writeln(     imagesarr[0]     );
    self.document.writeln('" ');
      self.document.writeln('onAbort="javascript:escapeErr()"');
      self.document.writeln(' ');
      self.document.writeln('onError="javascript:escapeErr()"');
      self.document.writeln(' ');
    self.document.writeln('ALIGN="TOP" BORDER="0" NAME="Photos">');
    self.document.writeln('  <br><br>');
    self.document.writeln('</CENTER>');
  }

  self.document.writeln('</P>');
  self.document.writeln('</td>');
  self.document.writeln('</tr>');
  self.document.writeln('</table>');
  if (newWinSwitch > 0)
  {
    self.document.writeln('<a href="javascript:self.close()">Close Both Windows</a>');
  } else {
    self.document.writeln('<a href="javascript:self.close()"></a>');
  }

  return false;
}


function CrtDumbWin()
{
  newWin = window.open("", "newWin", "height=140, width=140, resize=no, "
    + "scrollbars=no, top=0, left="
    + (screen.availWidth + 1)
    + "\"");
  newWin.location.reload(LoadDummyWin());
  newWin.focus();
  self.window.focus();
}

function LoadDummyWin()
{
  newWin.document.writeln('<html><head>');
  newWin.document.writeln('<a href="javascript:self.close()">Close This Window...</a>');
  newWin.document.writeln('<title>Temporary Picture Window</title>');
  newWin.document.writeln('</head><body>');
  newWin.document.writeln('</body></html>');
  return false;
}

function escapeErr()
{
  return self.document.writeln("There was an error loading " + imagesarr[i - 1] + " ...");
}

function CrtNewWin(index)
{
  var newWinWidth = screen.availWidth / 2;
  var newWinHeight = screen.availHeight;
  newWin = window.open("", "newWin", "height="
    + newWinHeight + ", width="
    + newWinWidth + ", resize=yes, scrollbars=yes, top=0, left="
    + newWinWidth + "\"");
  return newWin.location.reload(LoadNewWin(index));

}

function LoadNewWin(index)
{
  newWin.document.writeln('<html><head>');
  newWin.document.writeln('<title>Temporary Picture Window</title>');
  newWin.document.writeln('</head><body>');
  newWin.document.writeln('<CENTER>');
  newWin.document.writeln('<a href="javascript:self.close()">Close This Window</a>');
  newWin.document.writeln('  <br><br>');
  newWin.document.writeln('    <IMG SRC="');
  if (index > 0)
  {
    newWin.document.writeln(     imagesarr[index - 1]     );
  } else {
    newWin.document.writeln(     imagesarr[0]     );
  }
  newWin.document.writeln('" ');
    newWin.document.writeln('onAbort="javascript:escapeErr()"');
    newWin.document.writeln(' ');
    newWin.document.writeln('onError="javascript:escapeErr()"');
    newWin.document.writeln(' ');
  newWin.document.writeln('ALIGN="TOP" ALT="ChgInImg" BORDER="0" NAME="Photos">');
  newWin.document.writeln('  <br><br>');
  newWin.document.writeln('</CENTER>');
  newWin.document.writeln('</body></html>');
  return false;
}

function SwapImg(index)
{
  if (newWinSwitch > 0)
  {
    window.onError = CrtNewWin(index);
    newWin.document.Photos.src = imagesarr[index - 1];
    newWin.focus();
    return false;
  } else {
    return self.document.Photos.src = imagesarr[index - 1];
  }
}

// done hiding from old browsers... -->

