function debug(o)
{
   var msg = "debug:\n";
   for(i in o)
      {
      msg += i+"; ";
      }
   alert( msg );
}

function Gallery( title, name )
{
   this.title = title
   this.name = name;
   this.pics = new Array()
   this.labels = new Array()
   this.cache = new Array()
   this.current = 0
   this.length = 0
   this.header = "<h5 onClick='"+name+".prev();return false;' onmouseover=\"this.style.cursor='pointer';\">&lt Prev &gt</h5>"+
          	 "<h4>"+title+"</h4>"+
          	 "<h5 onClick='"+name+".next();return false;' onmouseover=\"this.style.cursor='pointer';\">&lt Next &gt</h5>";
}

function Gallery_writeGallery( )
{
   document.write( "<a href='gallery/"+this.pics[0]+".jpg' id='"+this.name+"_link' target='gallery'>"+
   		   "<img src='thumbs/"+this.pics[0]+"_t.jpg' name='"+this.name+"_frame'></a>" );
   eval( "this.link = document.getElementById('"+this.name+"_link')" );
   eval( "this.frame = document.images."+this.name+"_frame" );
   document.write( "<p id='"+this.name+"_caption'>"+this.labels[0]+"</p>" );
   eval( "this.caption = document.getElementById('"+this.name+"_caption')" );
}
Gallery.prototype.writeGallery = Gallery_writeGallery

function Gallery_writeHeader( )
{
   document.write( this.header );
}
Gallery.prototype.writeHeader = Gallery_writeHeader

function Gallery_cachePics( )
{
   for( i=0; i< this.length; i++ )
   {
      this.cache[i] = new Image()
      this.cache[i].src = "thumbs/"+this.pics[i]+"_t.jpg"
   }
}
Gallery.prototype.cachePics = Gallery_cachePics

function Gallery_add( name )
{
   this.pics[this.length] = name
   this.labels[this.length] = (name.replace(/.jpg$|^gallery\//gi, "")).replace(/_/g, " " )
   this.length++
}
Gallery.prototype.add = Gallery_add

function Gallery_show()
{
   this.link.href = "gallery/"+this.pics[this.current]+".jpg"
   this.frame.src = "thumbs/"+this.pics[this.current]+"_t.jpg"
   this.caption.innerHTML = this.labels[this.current]
}
Gallery.prototype.show = Gallery_show

function Gallery_prev( )
{
   if( this.current > 0 )
      this.current--
   else
      this.current = this.length-1
   this.show()
}
Gallery.prototype.prev = Gallery_prev

function Gallery_next( )
{
   if( this.current < this.length-1 )
      this.current++
   else
      this.current = 0
   this.show()
}
Gallery.prototype.next = Gallery_next

