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 widthw = photo_widthw + 30;
var heightw = photo_heightw + 70;

var thumb_l = 227;
var thumb_s = 150;
var thumb_p = 150;
var thumb_w = 475;
var thumb_window = 490;

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;

var startPicG = 0;
var endPicG = 0;

// Main window functions

function JF_newPiccy(piccy) {
  currentPiccy = piccy;
  currentShape = galleryList[piccy][1];
  if (!photoWindow.location || photoWindow.closed) {
    lastShape = currentShape;
	if (is.ns6) photoWindow = window.open('gallery_subwindow_'+subSuffix+'.htm', 'photoWin',
                     "width="+widthl+",height="+heightp+",resizable=yes");
    else {
    switch (currentShape) {
      case "l":
        photoWindow = window.open('gallery_subwindow_'+subSuffix+'.htm', 'photoWin',
                     "width="+widthl+",height="+heightl+",resizable=yes");
        break;
      case "p":
        photoWindow = window.open('gallery_subwindow_'+subSuffix+'.htm', 'photoWin',
                     "width="+widthp+",height="+heightp+",resizable=yes");
        break;
      case "w":
        photoWindow = window.open('gallery_subwindow_'+subSuffix+'.htm', 'photoWin',
                     "width="+widthw+",height="+heightw+",resizable=yes");
        break;
      case "s":
        photoWindow = window.open('gallery_subwindow_'+subSuffix+'.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 "w":
          photoWindow.resizeTo(widthw,heightw);
          break;
        case "s":
          photoWindow.resizeTo(widths,heights);
      }
      lastShape = currentShape;
    }
    photoWindow.location.reload();
    photoWindow.focus();
  }
}  

function JF_Thumbnails (startPic,endPic,skipPic) {
  if (startPic == null) startPic = 0;
  if (endPic == null) endPic = totalPiccys;
  if (endPic > totalPiccys) endPic = totalPiccys;
  if (skipPic == null) skipPic = startPic;
  
  startPicG = startPic;
  endPicG = endPic;
  
  var thumbWidth = 0;
  var thumbWidthLastRow = 0;
  var textWidth = (totalWidth - ((colPad + thumbWidth) * thumbCols)) / thumbCols;
  if (document.images) {

    for (count=skipPic ; count <= endPic ; count++) {
	
	  var thumbWidthLastRow = thumbWidth;

      switch (galleryList[count][1]) {
        case "l":
          thumbWidth = thumbWidth + thumb_l;
          break;
        case "p":
          thumbWidth = thumbWidth + thumb_p;
          break;
        case "w":
          thumbWidth = thumbWidth + thumb_w;
          break;
        case "s":
          thumbWidth = thumbWidth + thumb_s;
        }

      if (thumbWidth > thumb_window) {
	    thumbWidth = thumbWidth - thumbWidthLastRow;
        document.write ("<br clear='all'>");
      }
		   
      document.write
        ("<table width='50' border='0' cellspacing='0' cellpadding='0' align='left'>");

      document.write ("<tr><td>");

      document.write
        ("<a href='javascript:JF_newPiccy("+count+")'>" +
         "<img src='"+thumbDirectory+galleryList[count][0]+picFormat + "'");

      document.write ("alt='" + galleryList[count][2] + "' border='1'><\/a></td>");

      document.write ("<td rowspan='2'><img src='images/transparent.gif' width='5' height='50'></td>");
	  
	  document.write ("</tr><tr><td class='smallText'>" + galleryList[count][2] + "<br>&nbsp;</td></tr></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] + picFormat;
  if (!is.ns6) dLoading.show ();
  document.galleryPiccy.src=currentPiccySrc;
  dImgNo.setBody ("<p>Image ",(opener.window.currentPiccy-opener.window.startPicG+1)+" of "+
                   (opener.window.endPicG-opener.window.startPicG+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 "w":
        document.galleryPiccy.width=photo_widthw;
        document.galleryPiccy.height=photo_heightw;
        self.resizeTo(widthw,heightw);
        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.endPicG) {
     opener.window.currentPiccy++;
  } else opener.window.currentPiccy = opener.window.startPicG;

  JF_changePiccy();
}  

function JF_prevPiccy() {
  if (document.images && opener.window.currentPiccy > opener.window.startPicG) {
     opener.window.currentPiccy--;
  } else opener.window.currentPiccy = opener.window.endPicG;
  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"; }

}


