//////////////////////////////////////////////////////
//Written by Jayden Sibert - Spring 2008
//Description: Displays a random thumbnail on the frontpage as a link
//to the larger version
//////////////////////////////////////////////////////

//////////////////////////////////////////////////////
//Modifications:

//July 15, 2008 1:48 PM - by KG
//1. Fixed an error in generating a random array index. It was still assuming the index started at 1 and 
//went out of bounds on occasion

//July 14, 2008 10:37 AM - by KG
//1. Added semicolons to line endings for compatibility
//2. Added comments
//3. Revamped array building for smaller file size
//4. Changed the caption array to be 0-based

//////////////////////////////////////////////////////

var images = new Array;
var thumbs = new Array;
var captions = new Array;

//used to shorten the script length and make
//modification and additions easier
var image_folder = "images";
var thumbnail_suffix = "_small";
var file_type = "jpg";

//this is the list of image numbers. moving a number here, means you
//must also move its caption to the right index!
var image_list = [38,33,39,40,25,26,34,28,29,30,31,32,35,36,37,41,42];

captions[0] = "The Amver vessel Sonangol Kassanje next to the Vende Globe participant Jean Le Cam after his boat capsized off Cape Horn in January, 2009.  Photo credit: MRCC Chile";
captions[1] = "Survivors from the trimaran Siesta Key climb aboard the M/V Milan Express February 3, 2008 80 nautical miles off the coast of Costa Rica."
captions[2] = "Pictured are Leo Sherman and Captain Kim of the M/V Auto Banner.  The Auto Banner rescued Mr. Sherman after his catamaran capsized near Madagascar January 22, 2009. Photo credit: M/V Auto Banner"
captions[3] = "The M/V Vecchio Bridge rescued a 23-year-old Florida man as the sailor’s boat was sinking 700 miles off the coast of San Diego, Calif., Friday October 10, 2008. Photo credit: M/V Vecchio Bridge";
captions[4] = "Jerry Lomax poses with the master and crew of the M/T Tambourin after being rescued from his disabled 26 foot sailboat 330 nautical miles north east of French Guyana.";
captions[5] = "Chinese crewmembers of the M/V UNICORN ACE, rescued by the M/V PRABHU YUVIKA, wave thanks as they disembark in Manila to waiting Philippine Coast Guard officials.  The UNICORN ACE sank in bad weather 400 nautical miles north of Manila on March 19, 2007.";
captions[6] = "Survivors and crew pose on the deck of the Milan Express.  The Milan Express rescued the two sailors February 2, 2008 after their trimaran became disabled 80 nautical miles west of Costa Rica.";
captions[7] = "The crew of the M/V MIGHTY SERVANT I assists Mr. Maximiliano Rodriquez as he abandons the sailing vessel Alize III on May 25, 2007.  The MIGHT SERVANT I discovered the sail boat disabled and adrift 350 miles south east of Bermuda."
captions[8] = "Survivors from the trans-island ferry Katrina are helped aboard the M/V Federal Rhine.  The Katrina survivors were rescued on July 24, 2007 after their ferry caught fire on a voyage from Sanga Sanga Island to Bongao, Philippines."
captions[9] = "Survivors from the Orchid Sun are hoisted aboard the M/V Megah Cement.  The Orchid Sun sank on July 12, 2007 in the Persian Gulf.  The Megah Cement, under the command of Captain Floro Alpuerto, rescued 5 crewmembers of the Orchid Sun and transferred them to United States Navy personnel for immediate medical evacuation."
captions[10] = "The five survivors of the disabled sailboat Epiphany pose with crewmembers of the Amver participating tanker Atlantic Prosperity.  The Atlantic Prosperity rescued the five on October 26, 2007 approximately 195 nautical miles north of Saint Thomas after they suffered a rudder casualty on their sailboat."
captions[11] = "A crewman from the M/V Ioannis K pulls a Philippine survivor aboard after their boat capsized in the Sulu Sea."
captions[12] = "Ambassador Johan Verbeke, Permanent Representative of Belgium to the United Nations, (left) receives special recognition for Belgium’s participation in the Amver search and rescue system from Mr. Benjamin Strong (right) Director of Amver Maritime Relations in a ceremony onboard the United States Coast Guard Cutter Katherine Walker June 11, 2008 in New York Harbor."
captions[13] = "The crew of the commercial vessel Hyundai Japan receive a pennant from representatives of the Automated Mutual Assistance Vessel Rescue System for assisting a family of four whose vessel was beset by heavy weather during a sailing trip on the Atlantic Ocean June 9, 2008.  The Hyundai Japan has been an active member of the AMVER program since 1995."
captions[14] = "The M/V Vecchio Bridge braved 30 knot winds and 25 foot seas to rescue a sailor adrift and taking on water 700 miles off the coast of San Diego on October 9, 2008."
captions[15] = "Mr. Benjamin Strong, Amver Director, receives the Professional Mariner Plimsoll Safety Award for an organization at the Connecticut Maritime Association Shipping 2009 conference in Stamford, CT. Photo Credit: USCG Beverly Howard"
captions[16] = "Gianfranco Tortolani being hoisted aboard the Amver participating container ship Maersk Missouri June 21, 2009 after his sailboat capsized and was demasted over 300 nautical miles off the coast of Halifax, Canada."


//generate a random number between 1 and the size of the array
var randomnumber = Math.random() ;
var rand1 = Math.round( (image_list.length-1) * randomnumber) ;//+ 1;

//build the image address, link, and caption
var image = image_folder+"/image"+image_list[rand1]+"."+file_type;
var thumb = image_folder+"/image"+image_list[rand1]+thumbnail_suffix+"."+file_type;
var caption = captions[rand1];

//save html to this variable, which can be written somewhere in the document
var display_image = '<A HREF=\"' +image+ '\" title=\"'+caption+'\"><IMG id=\"imgLeft\" ALT = \"' + caption + '\" SRC=\"' + thumb + '\" BORDER=\"0\"></A>';
