// script to randomly shuffle  pictures for page  
// find page name without suffix .php or .php
function shuffle(){
var DEFAULT_WIDTH = 575; 
if  (shuffle.arguments.length == 0){
  width = DEFAULT_WIDTH;
  var pattern = /(\w+\.)/;
  pattern.test(location.pathname);  
  var page    = RegExp.$1;
  page = page.substring(0,page.length-1);
}  
else if (shuffle.arguments.length == 1){
  width = shuffle.arguments[0];
  var pattern = /(\w+\.)/;
  pattern.test(location.pathname);  
  var page    = RegExp.$1;
  page = page.substring(0,page.length-1);
}  
else if (shuffle.arguments.length == 2) {
  width = shuffle.arguments[0];
  if (width == 0){
    width = DEFAULT_WIDTH;
  }
  page  = shuffle.arguments[1];     
}
// define array for photos
var aPhoto      = new Array();
var photoString = new String();
// build string containing all existing img names for the page
   
existingPhotos  = document.getElementsByTagName('img');
for (var i=0; i < existingPhotos.length; i++){
  photoString += existingPhotos[i].src.toString() + ",";
} 

var j = 0;
// select photo that doesn't already appear on page 
// i.e. select photo that hasn't been selected before in case we invoke script multiple times on page
do {
// get photos depending on 
switch (page)
{
// tom's edit starts here
// index photos
//header
case 'index':
aPhoto[aPhoto.length]='images/index/1.jpg';
aPhoto[aPhoto.length]='images/index/2.jpg';
aPhoto[aPhoto.length]='images/index/3.jpg';
aPhoto[aPhoto.length]='images/index/4.jpg';
aPhoto[aPhoto.length]='images/index/5.jpg';
aPhoto[aPhoto.length]='images/index/6.jpg';
break;
// about us photos
// header
case 'about_us':
aPhoto[aPhoto.length]='images/about_us/1.jpg';
aPhoto[aPhoto.length]='images/about_us/2.jpg';
aPhoto[aPhoto.length]='images/about_us/3.jpg';
aPhoto[aPhoto.length]='images/about_us/4.jpg';
aPhoto[aPhoto.length]='images/about_us/5.jpg';
break;
//content
// lee
case '#lee':
aPhoto[aPhoto.length]='images/about_us/lee/1.jpg';
aPhoto[aPhoto.length]='images/about_us/lee/2.jpg';
break;
// darren
case '#darren':
aPhoto[aPhoto.length]='images/about_us/darren/1.jpg';
aPhoto[aPhoto.length]='images/about_us/darren/2.jpg';
break;
//ben
case '#ben':
aPhoto[aPhoto.length]='images/about_us/ben/1.jpg';
aPhoto[aPhoto.length]='images/about_us/ben/2.jpg';
break;
// testimonials photos
//header
case 'testimonials':
aPhoto[aPhoto.length]='images/testimonials/1.jpg';
aPhoto[aPhoto.length]='images/testimonials/2.jpg';
aPhoto[aPhoto.length]='images/testimonials/3.jpg';
break;
// the waves photos
// header
case 'the_surf':
aPhoto[aPhoto.length]='images/the_surf/1.jpg';
aPhoto[aPhoto.length]='images/the_surf/2.jpg';
aPhoto[aPhoto.length]='images/the_surf/3.jpg';
aPhoto[aPhoto.length]='images/the_surf/4.jpg';
break;
// content
// second photo
case '#location':
aPhoto[aPhoto.length]='images/the_surf/location/1.jpg';
aPhoto[aPhoto.length]='images/the_surf/location/2.jpg';
aPhoto[aPhoto.length]='images/the_surf/location/3.jpg';
break;
// third photo
case '#the_surf':
aPhoto[aPhoto.length]='images/the_surf/content/1.jpg';
aPhoto[aPhoto.length]='images/the_surf/content/2.jpg';
aPhoto[aPhoto.length]='images/the_surf/content/3.jpg';
aPhoto[aPhoto.length]='images/the_surf/content/4.jpg';
aPhoto[aPhoto.length]='images/the_surf/content/5.jpg';
break;
// north sumatra photos
// header
case 'north_sumatra':
aPhoto[aPhoto.length]='images/north_sumatra/1.jpg';
aPhoto[aPhoto.length]='images/north_sumatra/2.jpg';
break;
// content
case '#north_sumatra':
aPhoto[aPhoto.length]='images/north_sumatra/content/1.jpg';
aPhoto[aPhoto.length]='images/north_sumatra/content/2.jpg';
aPhoto[aPhoto.length]='images/north_sumatra/content/3.jpg';
aPhoto[aPhoto.length]='images/north_sumatra/content/4.jpg';
break;
//our boats photos
//header
case 'our_boats':
aPhoto[aPhoto.length]='images/our_boats/1.jpg';
break;
// freedom 1 photos
//header
case 'freedom1':
aPhoto[aPhoto.length]='images/freedom1/1.jpg';
aPhoto[aPhoto.length]='images/freedom1/2.jpg';
break;
//content
case '#freedom1':
aPhoto[aPhoto.length]='images/freedom1/content/1.jpg';
aPhoto[aPhoto.length]='images/freedom1/content/2.jpg';
break;
//freedom 1 specs photos
case 'freedom1_specs':
aPhoto[aPhoto.length]='images/freedom1_specs/1.jpg';
break;
case 'freedom2':
aPhoto[aPhoto.length]='images/freedom2/1.jpg';
break;
case '#freedom2':
aPhoto[aPhoto.length]='images/freedom2/content/1.jpg';
aPhoto[aPhoto.length]='images/freedom2/content/2.jpg';
aPhoto[aPhoto.length]='images/freedom2/content/3.jpg';
break;
case 'freedom2_specs':
aPhoto[aPhoto.length]='images/freedom2_specs/1.jpg';
break;
case 'freedom3':
aPhoto[aPhoto.length]='images/freedom3/1.jpg';
break;
case '#freedom3':
aPhoto[aPhoto.length]='images/freedom3/content/1.jpg';
aPhoto[aPhoto.length]='images/freedom3/content/2.jpg';
aPhoto[aPhoto.length]='images/freedom3/content/3.jpg';
break;
case 'freedom3_specs':
aPhoto[aPhoto.length]='images/freedom3_specs/1.gif';
break;
// the experience photos
// header
case 'the_experience':
aPhoto[aPhoto.length]='images/the_experience/1.jpg';
aPhoto[aPhoto.length]='images/the_experience/2.jpg';
aPhoto[aPhoto.length]='images/the_experience/3.jpg';
aPhoto[aPhoto.length]='images/the_experience/4.jpg';
break;
//content
case '#the_experience':
aPhoto[aPhoto.length]='images/the_experience/content/1.jpg';
aPhoto[aPhoto.length]='images/the_experience/content/2.jpg';
aPhoto[aPhoto.length]='images/the_experience/content/3.jpg';
aPhoto[aPhoto.length]='images/the_experience/content/4.jpg';
aPhoto[aPhoto.length]='images/the_experience/content/5.jpg';
aPhoto[aPhoto.length]='images/the_experience/content/6.jpg';
aPhoto[aPhoto.length]='images/the_experience/content/7.jpg';
aPhoto[aPhoto.length]='images/the_experience/content/8.jpg';
break;
// useful info photos
// header
case 'useful_info':
aPhoto[aPhoto.length]='images/useful_info/1.jpg';
aPhoto[aPhoto.length]='images/useful_info/2.jpg';
break;
//content
case '#useful_info':
aPhoto[aPhoto.length]='images/useful_info/content/1.jpg';
aPhoto[aPhoto.length]='images/useful_info/content/2.jpg';
aPhoto[aPhoto.length]='images/useful_info/content/3.jpg';
aPhoto[aPhoto.length]='images/useful_info/content/4.jpg';
aPhoto[aPhoto.length]='images/useful_info/content/5.jpg';
aPhoto[aPhoto.length]='images/useful_info/content/6.jpg';
aPhoto[aPhoto.length]='images/useful_info/content/7.jpg';
aPhoto[aPhoto.length]='images/useful_info/content/8.jpg';
break;
// reservation photos
// header
case 'reservation':
aPhoto[aPhoto.length]='images/reservation/1.jpg';
aPhoto[aPhoto.length]='images/reservation/2.jpg';
aPhoto[aPhoto.length]='images/reservation/3.jpg';
break;
// news photos
// header
case 'news':
aPhoto[aPhoto.length]='images/news/1.jpg';
aPhoto[aPhoto.length]='images/news/2.jpg';
aPhoto[aPhoto.length]='images/news/3.jpg';
break;
// gallery photos
// header
case 'gallery':
aPhoto[aPhoto.length]='images/gallery/1.jpg';
aPhoto[aPhoto.length]='images/gallery/2.jpg';
aPhoto[aPhoto.length]='images/gallery/3.jpg';
aPhoto[aPhoto.length]='images/gallery/4.jpg';
aPhoto[aPhoto.length]='images/gallery/5.jpg';
break;
// surf_map 
case 'surf_map':
aPhoto[aPhoto.length]='images/mentawai3.jpg';
break;
// surf_forecast 
case 'surf_forecast':
aPhoto[aPhoto.length]='http://polar.ncep.noaa.gov/waves/latest_run/nww3_in.anim.gif';
break;
// >>>>>>>>>>>>> ADD PHOTOS FOR NEW PAGES HERE <<<<<<<<<<<<<<<
// repeat pattern above (case, photos, break) here to add photos for new page  
default:
aPhoto[aPhoto.length]='images/gallery/1.jpg';
aPhoto[aPhoto.length]='images/gallery/2.jpg';
aPhoto[aPhoto.length]='images/gallery/3.jpg';
aPhoto[aPhoto.length]='images/gallery/4.jpg';
aPhoto[aPhoto.length]='images/gallery/5.jpg';
break;
}
// randomly choose photo 
j=Math.floor(Math.random()*aPhoto.length);
j=(isNaN(j))?0:j;
}
while (photoString.indexOf(aPhoto[j]) != -1); // if new photo choosen (doesn't exist on page already) can exit loop
//  
 
document.write("<img src='" +aPhoto[j]+ "' width='" + width + "'  border='1'>");
}
