// JavaScript Document
/* PicPics.js - G McMurdo, 19 Mar 01, last-edit 22 Mar 01, 
   to randomly select from a set of images and write an
   HTML IMG tag, also demonstrating 'record handling' */

/* I've set the Path variable so this script will work from
   anywhere on our server.  If you put the PicsPics.js in the
   same directory as your image files, you don't need Path,
   and you could comment-out/remove it below, and in the
   'document.write()' lines.  OR, just swap the commenting
   of the two lines below to comment-IN the line which sets
   Path to 'null' ... */ 

//var Path = "";
var Path = "http://www.sfu.ca/~marshall/graphics/images/";

// Image record is: Filename|Height|Width|Alt-text
Images = new Array(
"image1.jpg|113|90|", "image2.jpg|120|90|", "image3.jpg|115|90|", "image4.jpg|99|90|", "image5.jpg|113|90|", "image6.jpg|129|90|"
);

/* Choose one of the Images array, this time making use 
   of the 'Images.length' object-property to save us 
   keeping a count of the number of records we have */

chImg   = Math.round(Math.random() * (Images.length -1));	

/* Next 'split' the record into 4 elements of the array
   IMGfields, so that IMGfields[0] will contain the SRC
   field, IMGfields[1] the HEIGHT field, etc  ...  */

IMGfields = Images[chImg].split("|");

// Now write the SRC, HEIGHT, WIDTH, ALT of the IMG tag 
document.write("<img src=\"" + Path + IMGfields[0] + "\"\n");
//document.write("<img src=\"" + IMGfields[0] + "\"\n");
document.write("height=\"" + IMGfields[1] + "\"\n");
document.write("width=\"" + IMGfields[2] + "\"\n");
document.write("alt=\"" + IMGfields[3] + "\">\n");
// end
