/*
 Disclosure:

 The follwing scripts were written by Joshaven Potter in Febuary 2003
 permission to use these functions is granted as long as this 
 introduction is left in tact.    
*/
/*
 Instructions:

 Save this text as DropDownThumb.js and keep it with the web page
 Place the following line in between the <HEAD></HEAD> tages:
 <SCRIPT SRC="DropDownThumb.js"></SCRIPT>
 Put the call to this script in between the <BODY></BODY> tags, see example below. 

 The image used is named Image_Thumb.jpg 
 if you do not give any extra attributes you are forced to use the defaults which means
 it will show three options in the drop-down window (Small, Medium and Large).
 The images have to be named in the following format:
 (imagename_Thumb.ext, imagename_SM.ext, imagename_Med.ext and imagename_LG.ext
 Note: 'imagename' and 'ext' are examples you will replace these with your image info)
 Note: Your server may be case sensitive so watch yourself.

 The image names in the following examples are
 (mypic_Thumb.jpg, mypic_SM.jpg, mypic_Med.jpg mypic_LG.jp)

 Example 1: 
  <BODY>
    <SCRIPT TYPE="text/javascript">
      Display(new PicBook('mypic')); <!-- the image name is everything before the "_Thumb.jpg" -->		
    </SCRIPT>  
  </BODY>
 Example 2: 
  <BODY>
    <SCRIPT TYPE="text/javascript">
      Display(new PicBook('imagename,1'));		
    </SCRIPT>  
  </BODY>
*/
/*
 Deffination of object attribute:

 name		// This is required as it is the root name of the image
 number		// This needs to be set if there are fewer then three enlargement sizes
 path		// The path to the file (ie. "../pics/", "./pics/" or possably "")
 ext		// The extention of the image file ie. ".gif"
 openScript	// The javascript syntax to open the CreatePage function
 closeScript	// The javascript syntax to close the CreatePage function
 index		// Don't worry about this one, the default is to use a random number

 The word null can be used to keep the default setting for an attribute
 Display(new PicBook('imagename,null,"",".gif"'));		
*/

///////////////////////////////////////////////////////////////////////////////////////////

/*
 Function DisplayThumb(imageName,numberOfImages)
 Displays Thumbnail image and creates a form under the image with a
 drop-down menu allowing the user to select the image size and then
 click a button labled "Enlarge" to display the larg image in a new window
*/
function PicBook(imageName, numberOfImages, path, ext, openScript, closeScript, imageIndex){
  this.name=imageName;
  this.number=numberOfImages;
  this.path=path;
  this.ext=ext;
  this.openScript=openScript;
  this.closeScript=closeScript;
  this.index=imageIndex;
}

/*
 function Display(currentPicBook)

 This function is responcible for calling all the functions
 nessassory for this program to compleate.  This function is 
 an equivilante to a "main"
*/
function Display(currentPicBook){
  SetDefaultsNow(currentPicBook);	// Set any attribute to a default if it is null
  PrintThumb(currentPicBook);		// Places the thumbnail on the page
  PrintBeginForm(currentPicBook);	// Begins the HTML code for the form used to select size
  PrintOptions(currentPicBook);		// Prints the enlagement options
  PrintEndForm(currentPicBook);		// Compleates the HTML code for the form
}

/*
 function SetDefaults(currentPicBook)

 Sets the attributes of all options that are not set by the call
 to this program.
*/
function SetDefaultsNow(currentPicBook){
  if(currentPicBook.name==null)
    alert("You must enter the name of the image to be displayed");
  if(currentPicBook.number==null)
    currentPicBook.number=3;
  if(currentPicBook.path==null)
    currentPicBook.path="../pics/";
  if(currentPicBook.ext==null)
    currentPicBook.ext=".jpg";
  if(currentPicBook.openScript==null)
    currentPicBook.openScript=	"javascript:CreatePage(new image('";
  if(currentPicBook.closeScript==null)
    currentPicBook.closeScript="'))";
  if(currentPicBook.index==null)
    currentPicBook.index=Math.floor(Math.random()*1000000000)

}

/*
 function PrintThumb(currentPicBook)

 This function places the thumbnail picture on the page
*/
function PrintThumb(currentPicBook){
  document.write("    <IMG SRC='../pics/"+currentPicBook.name+"_Thumb.jpg'>\n");
}

/*
 function PrintBeginForm(currentPicBook)

 This function writes the HTML <FORM> beginning tags
*/
function PrintBeginForm(currentPicBook){
  document.writeln("    <FORM NAME=form" + currentPicBook.index + ">");
  document.writeln("      <SELECT NAME='element" + currentPicBook.index + "' ONCHANGE='put("+currentPicBook.index+")'>");
}

/*
 function PrintOptions(currentPicBook)

 This function adds an option for each image.  If the number of
 images is not defined the default is three and the default names
 are "image_SM.ext", "image_Med.ext" & "image_LG.ext"
*/
function PrintOptions(currentPicBook){
  document.writeln("        <OPTION SELECTED='SELECTED'>Select Size</OPTION>");
  if(currentPicBook.number>0)
    document.writeln("        <OPTION VALUE=\"" + currentPicBook.openScript+ currentPicBook.path + currentPicBook.name  + "_SM" + currentPicBook.ext + currentPicBook.closeScript + "\">Small" + "</OPTION>");
  if(currentPicBook.number>1)
    document.writeln("        <OPTION VALUE=\"" + currentPicBook.openScript + currentPicBook.path + currentPicBook.name  + "_Med" + currentPicBook.ext + currentPicBook.closeScript + "\">Medium" + "</OPTION>");
  if(currentPicBook.number>2)
    document.writeln("        <OPTION VALUE=\"" + currentPicBook.openScript + currentPicBook.path + currentPicBook.name + "_LG" + currentPicBook.ext + currentPicBook.closeScript + "\">Large" + "</OPTION>");
}

/*
 function PrintEndForm(currentPicBook)

 This function compleates the <FORM> tag on the document created
*/
function PrintEndForm(currentPicBook){
  document.write("      </SELECT>\n    </FORM>\n");
}

/*
 function put(index)

 This function is responcible for taking the action when an
 option is selected from the the dropdown menu
*/
function put(index){
  var form = "form"+index;
  var element = "element"+index;
  var number=document.forms[form].elements[element].selectedIndex;
  if(number>0){
    location.href = document.forms[form].elements[element].options[number].value;
    document.forms[form].elements[element].selectedIndex=0
  }
}