// This file is generated by JPhotoAlbum. 
// Any changes will be overwritten by Export/Framed Thumbnails command.
//
// Script Copyright 2004 Jari Karjala <www.jpkware.com>
// @version $Id: jphoto.js,v 1.1.1.1 2004/05/21 18:24:59 jkarjala Exp $

function setPhoto(photo) {
  if (photo==null)
    return false;

  var doc = parent.ImageWindow.document;
  var tdoc = parent.Thumbs.document;

  img = "pictures/" + photo;
  onprev = 'return parent.prevPhoto("' + photo + '")';
  onnext = 'return parent.nextPhoto("' + photo + '")';

  doc.open();
  pics = tdoc.location.href;
  pics = pics.substring(0, pics.lastIndexOf('/'))+"/pictures/";
  img = pics + photo;
  onprev = 'return parent.prevPhoto("' + photo + '")';
  onnext = 'return parent.nextPhoto("' + photo + '")';

  doc.open();
  doc.write("<center>");
  doc.write("<table border=0 cellpadding=1 cellspacing=0><tr><td>");
  if (findPrev(photo)!=null && getPreviousLink()!=null)
    doc.write("<a href="+pics+findPrev(photo)+"' onclick='"+onprev+"'>"+getPreviousLink()+"</a>");
  else
    doc.write("&nbsp;");
  doc.write("</td><td>");
  doc.write(getPhotoHeading(photo));
  doc.write("</td><td>");
  if (findNext(photo)!=null && getNextLink()!=null)
    doc.write("<a href="+pics+findNext(photo)+"' onclick='"+onnext+"'>"+getNextLink()+"</a>");
  else
    doc.write("&nbsp;");
  doc.write("</td></tr></table>");
  doc.write("<img src='" + img + "'/>")
  doc.write("</center>");
  copyColors(tdoc, doc);
  doc.close();

  return false;
}

function copyColors(org, doc) {
  doc.bgColor = org.bgColor;
  doc.fgColor = org.fgColor;
  doc.alinkColor = org.alinkColor;
  doc.linkColor = org.linkColor;
  doc.vlinkColor = org.vlinkColor;
}

function makeVisible(photoname) {
  var ref = parent.Thumbs.location.href;
  hashIndex = ref.indexOf("#");
  if (hashIndex>0)
    ref = ref.substring(0,hashIndex);
  parent.Thumbs.location.href=ref+"#"+photoname;
}

function nextPhoto(photoname) {
  var next = findNext(photoname);
  if (next==null)
    alert("No next for "+photoname);
  else
    makeVisible(next);
  return setPhoto(next);
}

function findNext(photoname) {
    var links = parent.Thumbs.document.anchors;
    found = false;
    for (i=0; i<links.length; i++) {
      if (found && links[i].name!=null 
          && links[i].name.toLowerCase().indexOf(".jpg")>0)
        return links[i].name;

      if (photoname==links[i].name)
        found = true;
    }
    return null;
}

function prevPhoto(photoname) {
  var next = findPrev(photoname);
  if (next==null)
    alert("No previous for "+photoname);
  else
    makeVisible(next);
  return setPhoto(next);
}

function findPrev(photoname) {
    var links = parent.Thumbs.document.anchors;
    var prev = null;
    for (i=0; i<links.length; i++) {
      if (photoname==links[i].name)
        return prev;

      if (links[i].name!=null 
          && links[i].name.toLowerCase().indexOf(".jpg")>0)
        prev = links[i].name;
    }
    return null;
}

function selectFirst() {
  if (parent==null || parent.Thumbs==null)
    return;
  if (parent.window.location.hash!=null && parent.window.location.hash!="") {
    parent.setPhoto(parent.window.location.hash.substring(1));
    parent.makeVisible(parent.window.location.hash.substring(1));
    return;
  }
  var links = parent.Thumbs.document.anchors;
  for (i=0; i<links.length; i++) {
     if (links[i].name!=null 
	  && links[i].name.toLowerCase().indexOf(".jpg")>0) {
	     parent.setPhoto(links[i].name);
	     return;
     }
  }
}

