function Is() {
    agent  = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns    = ((agent.indexOf('mozilla')   !=   -1) && 
                 ((agent.indexOf('spoofer')   ==   -1) && 
                 (agent.indexOf('compatible') ==   -1)));
    this.ns4   = (this.ns && (this.major      ==    4));
    this.ns6   = (this.ns && (this.major      >=    5));
    this.ie    = (agent.indexOf("msie")       !=   -1);
    this.ie3   = (this.ie && (this.major      < 4));
    this.ie4   = (this.ie && (this.major      ==    4) && 
                 (agent.indexOf("msie 5.0")   ==   -1));
    this.ie5   = (this.ie && (this.major      ==    4) && 
                 (agent.indexOf("msie 5.0")   !=   -1));
    this.ie55  = (this.ie && (this.major      ==    4) && 
                 (agent.indexOf("msie 5.5")   !=   -1));
    this.ie6   = (this.ie && (agent.indexOf("msie 6.0")!=-1) );
}

var is = new Is();

var undefined;

var widthl = photo_widthl + 30;
var heightl = photo_heightl + 70;
var widthp = photo_widthp + 20;
var heightp = photo_heightp + 70;
var widths = photo_widths + 50;
var heights = photo_heights + 70;

var currentPiccy = 0;
var currentText = "<p>&nbsp;Test<\/p>";
var currentShape = galleryList[0][1];
var lastShape = currentShape;
var totalPiccys = galleryList.length - 1;
var photoWindow = 0;

// Main window functions

function JF_newPiccy(piccy) {
  currentPiccy = piccy;
  currentShape = galleryList[piccy][1];
  if (!photoWindow.location || photoWindow.closed) {
    lastShape = currentShape;
    switch (currentShape) {
      case "l":
        photoWindow = window.open('gallery_subwindow.htm', 'photoWin',
                     "width="+widthl+",height="+heightl+",resizable=yes");
        break;
      case "p":
        photoWindow = window.open('gallery_subwindow.htm', 'photoWin',
                     "width="+widthp+",height="+heightp+",resizable=yes");
        break;
      case "s":
        photoWindow = window.open('gallery_subwindow.htm', 'photoWin',
                     "width="+widths+",height="+heights+",resizable=yes");
    }}
  else {
    if (lastShape != currentShape) {
      switch (currentShape) {
        case "l":
          photoWindow.resizeTo(widthl,heightl);
          break;
        case "p":
          photoWindow.resizeTo(widthp,heightp);
          break;
        case "s":
          photoWindow.resizeTo(widths,heights);
      }
      lastShape = currentShape;
    }
    photoWindow.location.reload();
    photoWindow.focus();
  }
}  

function JF_Thumbnails () {
  var colCount = 1;
  var textWidth = (totalWidth - ((colPad + thumbWidth) * thumbCols)) / thumbCols;
  if (document.images) {

    if (thumbTable == true) document.write ("<table align='center' border='0' cellspacing='5'><tr>");
    for (count=0 ; count <= totalPiccys ; count++) {


      if (thumbTable == true) {
        if (colCount == 1) document.write("<tr>");
        document.write ("<td>&nbsp;<\/td><td width='"+thumbWidth+"'>");
        }

      document.write
        ("<a href='javascript:JF_newPiccy("+count+")'>" +
         "<img src="+srcDirectory+galleryList[count][0]+"_thumb.jpg");

      if (thumbTable == false)  document.write (" vspace='5' hspace='5'");
        
      document.write (" border='1'><\/a>");

      if (thumbTable == true) {
        if (galleryList[count][2] === undefined) galleryList[count][2] = " ";
        if (galleryList[count][3] === undefined) galleryList[count][3] = " ";

        document.write("<\/td><td width='50%' valign='top'>");
        document.write("<p><b>"+galleryList[count][2]+"<\/b><br>");
        document.write(galleryList[count][3]+"<\/p>");
        document.write("<\/td>");

        if (colCount == thumbCols) {
          document.write("<\/tr>");
          colCount = 1;
        } else colCount++;
      }
    }
    if (thumbTable == true) {
      if (colCount /= thumbCols) {
        document.write("<td>&nbsp;<\/td><\/tr>");
        }
      document.write("<tr>");

      for (colCount=0 ; colCount <= thumbCols ; colCount++) {
        document.write
          ("<td width='"+colPad+"' height='1'><img src='"+srcDirectory+"transparent.gif'"+
           " width='"+colPad+"' height='1'></td>"); 
        document.write
          ("<td width='"+thumbWidth+"' height='1'><img src='"+srcDirectory+"transparent.gif'"+
           " width='"+thumbWidth+"' height='1'></td>"); 
        document.write
          ("<td width='"+textWidth+"' height='1'><img src='"+srcDirectory+"transparent.gif'"+
           " width='"+textWidth+"' height='1'></td>"); 
        }
      document.write("<\/tr>");
      document.write("<\/table>");
      }
  }
}

function loadEvent () {
  if (!is.ns6) dLoading.hide ();
  }

function JF_initSubwindow () {
  document.galleryPiccy.onload = loadEvent;
  }

function JF_changePiccy () {
  opener.window.currentShape = opener.window.galleryList[opener.window.currentPiccy][1];
  currentPiccySrc = srcDirectory +
    opener.window.galleryList[opener.window.currentPiccy][0] + ".jpg";
  if (!is.ns6) dLoading.show ();
  document.galleryPiccy.src=currentPiccySrc;
  dImgNo.setBody ("<p>Image ",(opener.window.currentPiccy+1)+" of "+
                   (opener.window.totalPiccys+1)+"</p>");

  if (opener.window.lastShape != opener.window.currentShape) {
    switch (opener.window.currentShape) {
      case "l":
        document.galleryPiccy.width=photo_widthl;
        document.galleryPiccy.height=photo_heightl;
        self.resizeTo(widthl,heightl);
        break;
      case "p":
        document.galleryPiccy.width=photo_widthp;
        document.galleryPiccy.height=photo_heightp;
        self.resizeTo(widthp,heightp);
        break;
      case "s":
        document.galleryPiccy.width=photo_widths;
        document.galleryPiccy.height=photo_heights;
        self.resizeTo(widths,heights);
    }
    opener.window.lastShape = opener.window.currentShape;
    if (is.ns4||is.ns6) location.reload();
    }
}


//Subwindow functions

function JF_nextPiccy() {
  if (document.images && opener.window.currentPiccy < opener.window.totalPiccys) {
     opener.window.currentPiccy++;
  } else opener.window.currentPiccy = 0;

  JF_changePiccy();
}  

function JF_prevPiccy() {
  if (document.images && opener.window.currentPiccy > 0) {
     opener.window.currentPiccy--;
  } else opener.window.currentPiccy = opener.window.totalPiccys;
  JF_changePiccy();
}  

function JF_closeWindow () {
  self.close();
}

function dynamicLayer(window, id, body) {
    this.window = window;
    this.id = id;
    this.body = body;
}

// First, define the Navigator methods.
if (is.ns4 || is.ns6) {

    /*
     * This function outputs the dynamic element itself into the document.
     * It must be called before any other methods of the dynamicLayer object can
     * be used.
     */  
    dynamicLayer.prototype.output = function() {
        var d = this.window.document;  // Shortcut variable: saves typing

        // Output the element within a <DIV> tag.  Specify the element id.
        d.writeln('<DIV ID="' + this.id + '">');
        d.writeln(this.body);
        d.writeln("</DIV>");

        // Now, for convenience, save a reference to the Layer object
        // created by this dynamic element.
        this.layer = d[this.id];
    }


    /* 
     * This method allows us to dynamically change the contents of
     * the dynamic element. The argument or arguments should be HTML
     * strings which become the new body of the element.
     */
    dynamicLayer.prototype.setBody = function() {
        for(var i = 0; i < arguments.length; i++)
            this.layer.document.writeln(arguments[i]);

        /* This "moveTo" gets around a bug with Netscape 4.7 which seems to 
         * reset the x,y coordinates of the layer to 0,0 when it's contents
         * are changed. JF 17/5/01
         */
        //this.layer.moveTo(this.left,this.top);

        this.layer.document.close();
    }

    dynamicLayer.prototype.moveTo = function(x,y) { this.layer.moveTo(x,y); }
    dynamicLayer.prototype.show = function() { this.layer.visibility = "show"; }
    dynamicLayer.prototype.hide = function() { this.layer.visibility = "hide"; }

}

if (navigator.appName.indexOf("Microsoft") != -1) {

    // The all-important output() method
    dynamicLayer.prototype.output = function() {
        var d = this.window.document;  // Shortcut variable: saves typing

        // Output the element within a <DIV> tag.  Specify the element id.
        d.writeln('<DIV ID="' + this.id + '">');
        d.writeln(this.body);
        d.writeln("</DIV>");

        // Now, for convenience, save references to the <DIV> element
        // we've created, and to its associated Style element.
        // These will be used throughout the methods that follow.
        this.element = d.all[this.id];
        this.style = this.element.style;
    }

    // Change the contents of the dynamic element.
    dynamicLayer.prototype.setBody = function() {
        var body = "";
        for(var i = 0; i < arguments.length; i++) {
            body += arguments[i] + "\n";
        }
        this.element.innerHTML = body;
    }

    dynamicLayer.prototype.moveTo = function(x,y) {
        this.style.pixelLeft = x;
        this.style.pixelTop = y;
    }
    dynamicLayer.prototype.show = function() { this.style.visibility = "visible"; }
    dynamicLayer.prototype.hide = function() { this.style.visibility = "hidden"; }

}


