/*  CONTACT PAGE RANDOM IMAGE GENERATOR */

/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

// image file names go in these arrays
randImgObj.set1 = new Array(
// from oxford/Others/small 15apr06
"../small/15apr06_012_sm.jpg",
"../small/15apr06_016_sm.jpg",
"../small/15apr06_018_sm.jpg",
"../small/15apr06_021_sm.jpg",
"../small/15apr06_028_sm.jpg",
"../small/15apr06_030_sm.jpg",
"../small/15apr06_035b_sm.jpg",
"../small/15apr06_035_sm.jpg",
"../small/15apr06_039_sm.jpg",
"../small/15apr06_048_sm.jpg",
"../small/15apr06_062_sm.jpg",
"../small/15apr06_069_sm.jpg",
"../small/15apr06_072_sm.jpg",
"../small/15apr06_084_sm.jpg",
"../small/15apr06_087_sm.jpg",
"../small/15apr06_091_sm.jpg",
"../small/15apr06_092_sm.jpg",
"../small/15apr06_119_sm.jpg",
"../small/15apr06_127b_sm.jpg",
// from oxford/Others/small 12apr06
"../small/12apr06_002_sm.jpg",
"../small/12apr06_006_sm.jpg",
"../small/12apr06_027_sm.jpg",
"../small/12apr06_028_sm.jpg",
"../small/12apr06_035_sm.jpg",
"../small/12apr06_036_sm.jpg",
// from oxford/Others/small 25mar06
"../small/fr-market8_032506_sm.jpg",
"../small/fr-market4_032506_sm.jpg",
"../small/crown4_sm.jpg",
"../small/fr-market3_032506_sm.jpg",
"../small/cake1_032506_sm.jpg",
"../small/balliol_door4_sm.jpg",
"../small/ashmolean_cafe1_sm.jpg",
"../small/balliol_door2_sm.jpg",
"../small/ashmolean_cafe3_sm.jpg",
"../small/cake4_032506_sm.jpg",
"../small/cake2_032506_sm.jpg",
"../small/woodstock_rd_sm.jpg",
"../small/trinity2_032506_sm.jpg",
"../small/spices4_sm.jpg",
// "../small/spices2_sm.jpg",
"../small/beaumont_st_sm.jpg",
"../small/port_meadow4_sm.jpg",
"../small/nuffield1_sm.jpg",
"../small/masks1_032506_sm.jpg",
"../small/group_032506_sm.jpg",
"../small/fr-market1_032506_sm.jpg",
"../small/fr-market5_032506_sm.jpg",
"../small/canal7_032506_sm.jpg",
"../small/crown2_sm.jpg",
"../small/crown1_sm.jpg",
"../small/canal6_032506_sm.jpg",
"../small/canal10_032506_sm.jpg",
"../small/canal3_032506_sm.jpg",
// from oxford/Others/myOxford
"../small/54_kettle_sm.jpg",        
"../small/alice_ms_sm.jpg",         
"../small/alice_sm.jpg",            
"../small/all_souls_sm.jpg",
"../small/Blackfriars2_sm.jpg",     
"../small/black-swan_sm.jpg",       
"../small/bm_horse_sm.jpg",         
"../small/Boudicca3_sm.jpg",        
"../small/brasenose_sm.jpg",
"../small/buck_palace_sm.jpg",
"../small/buryknowle_sm.jpg",
"../small/cake_shop_sm.jpg",
"../small/ch-ch_sm.jpg",
"../small/christmas-robin_sm.jpg",  
"../small/cm_davidjohn_sm.jpg",         
"../small/cm_feller3_sm.jpg",         
"../small/cm-feller2_sm.jpg",         
"../small/coal_tit_sm.jpg",         
"../small/coveredmarket_sm.jpg",
"../small/donkey_sm.jpg",
"../small/elephant2_sm.jpg",        
"../small/exeter_sm.jpg",
"../small/fishers_sm.jpg",
"../small/florist_sm.jpg",
"../small/folly_bridge_sm.jpg",
"../small/ghwilliams_shop_sm.jpg",
"../small/grand_cafe_sm.jpg",       
"../small/Guards_sm.jpg",             
"../small/h_high_st_b-2_sm.jpg",      
"../small/h_james5_b_sm.jpg",         
"../small/h_poppies_b_sm.jpg",        
"../small/hhhall_bridge_2003_sm.jpg",
"../small/high_st2_sm.jpg", 
"../small/high_st3_sm.jpg",            
"../small/iffley_road_sm.jpg",        
"../small/lion_sq_sm.jpg",            
"../small/London_cityhall_sm.jpg",
"../small/london_eye_sm.jpg",
"../small/maudlin_sm.jpg",             
"../small/merton_sm.jpg",             
"../small/millennium_bridge_sm.jpg",
"../small/nathistory-arches-1_sm.jpg",
"../small/nathistory-roof_sm.jpg",
"../small/nuffield_sm.jpg",           
"../small/observ_green_college_sm.jpg",
"../small/parktown_postbox2_sm.jpg",  
"../small/pc-owen8_sm.jpg",           
"../small/peter_pan_sm.jpg",
"../small/peter_pan2_sm.jpg",
"../small/postbox2_sm.jpg",           
"../small/postboxE2_sm.jpg",          
"../small/postbox_E7_sm.jpg",          
"../small/postbox_owen_sm.jpg",
"../small/punts_sm.jpg",
"../small/quarterboys_sm.jpg",
"../small/rad_camera_sm.jpg",
"../small/rad_camera2_sm.jpg",
"../small/rainbow_bridge_sm.jpg",
"../small/rowing_sm.jpg",
"../small/Sheldonian_sm.jpg",
"../small/shopfront_sm.jpg",
"../small/st_ebbes_sm.jpg",
"../small/st_ebbes2_sm.jpg",
"../small/st_martin_sm.jpg",
"../small/stnicholas_church_sm.jpg",
"../small/stpauls1_sm.jpg",
"../small/stpauls7_sm.jpg",
"../small/sugar_mice_sm.jpg",
"../small/TateMod_box4_sm.jpg",
"../small/the_grapes_sm.jpg",
"../small/turl_pubs_sm.jpg",
//	14feb06 visit to South Kensington
"../small/albert_memorial_sm.jpg",
"../small/albert_memorial2_sm.jpg",
"../small/albert_memorial2_sm2.jpg",
"../small/marble_arch_sm.jpg",
"../small/natural_history2_sm.jpg",
"../small/peter_pan_statue3_sm.jpg",
"../small/peter_pan_statue_sm.jpg",
"../small/royal_albert_hall_sm.jpg",
"../small/science_museum3_sm.jpg",
"../small/science_museum8_sm.jpg",
"../small/science_museum9_sm.jpg",
"../small/south_kensington4_sm.jpg",
"../small/victoria_station3_sm.jpg",
//      added 16feb2006 -->
"../small/britmuseum_webbed.jpg",
"../small/britmuseum_roof.jpg",
"../small/coachpub.jpg",
"../small/blackfriars2.jpg",
//      from HOME <!-- Added 4Jan06 from "wes_olc1.htm" -->
"../../../HOME/adidcot.jpg",
"../../../HOME/odidcot.jpg",
"../../../HOME/armor.jpg",
"../../../HOME/celtw.jpg",
"../../../HOME/ch-chgarden2.jpg",
"../../../HOME/ch-chgarden.jpg",
"../../../HOME/odidcot2.jpg",
"../../../HOME/wdidcot.jpg",
"../../../HOME/ch-ch.jpg",
"../../../HOME/oghost.jpg",
"../../../HOME/throne.jpg",
"../../../HOME/whitetower2.jpg",
"../../../HOME/sheep.jpg",
"../../../HOME/ohood.jpg",
"../../../HOME/towerbear.jpg",
"../../../HOME/whitetower.jpg",
"../../../HOME/cogges.jpg",
"../../../HOME/oknight.jpg",
"../../../HOME/towerbridge.jpg",
"../../../HOME/woodhorses.jpg",
"../../../HOME/kingw.jpg",
"../../../HOME/opirate.jpg",
"../../../HOME/opirate2.jpg",
"../../../HOME/towergate.jpg",
"../../../HOME/wpirate.jpg",
"../../../HOME/oarmor.jpg",
"../../../HOME/tower-new.jpg",
"../../../HOME/wtowerbridge.jpg",
"../../../HOME/obunny.jpg",
"../../../HOME/otower.jpg",
"../../../HOME/violet.jpg",
"../../../HOME/violet2.jpg",
"../../../HOME/ocogges.jpg",
"../../../HOME/pumpkin.jpg",
"../../../HOME/wdidcot2.jpg",
"../../../HOME/ocogges2.jpg",
"../blackwells.gif",
"../tourBod1.jpg");

// If all the images are in the same location, you can specify the path here
randImgObj.imagesPath = "http://kcrimson.sdsu.edu/mmyers/oxford/Others/myOxford/";
// randImgObj.imagesPath = "http://kcrimson.sdsu.edu/mmyers/";


// No need to edit code below this line

Array.prototype.shuffle = function() {
  var i, temp, i1, i2;
  for (i=0; i<this.length; i++) {
    i1 = Math.floor( Math.random() * this.length );
    i2 = Math.floor( Math.random() * this.length );
    temp = this[i1];
    this[i1] = this[i2];
    this[i2] = temp;
  }
}

randImgObjs = []; // holds all random rotating image objects defined
// constructor
function randImgObj(s) {
  this.speed=s; this.ctr=0; this.timer=0;
  this.index = randImgObjs.length; randImgObjs[this.index] = this;
  this.animString = "randImgObjs[" + this.index + "]";
}

randImgObj.prototype = {
  addImages: function(ar) { // preloads images
    this.imgObj.imgs = [];
    for (var i=0; ar[i]; i++) {
      this.imgObj.imgs[i] = new Image();
      this.imgObj.imgs[i].src = randImgObj.imagesPath + ar[i];
    }
  },

  rotate: function() { // controls rotation
    var ctr = Math.floor( Math.random() * this.imgObj.imgs.length );
    if (ctr == this.ctr) ctr = (ctr > 0)? --ctr: ++ctr;
    this.ctr = ctr;
    if ( typeof this.imgObj.filters != "undefined" ) {
                this.imgObj.style.filter = 'blendTrans(duration=1)';
      if (this.imgObj.filters.blendTrans) this.imgObj.filters.blendTrans.Apply();
    }
    this.imgObj.src = this.imgObj.imgs[this.ctr].src;
    if ( typeof this.imgObj.filters != "undefined" && this.imgObj.filters.blendTrans )
      this.imgObj.filters.blendTrans.Play();
  }
}

// sets up rotation for all defined randImgObjs
randImgObj.start = function() {
  for (var i=0; i<randImgObjs.length; i++)
    randImgObjs[i].timer = setInterval(randImgObjs[i].animString + ".rotate()", randImgObjs[i].speed);
}

randImgObj.setUpImg = function(imgAr, sp, w, h) {
  var rotator, img, imgStr = "";
  rotator = new randImgObj(sp);
  randImgObjs[randImgObjs.length-1].imgAr = imgAr;
  imgAr.shuffle();
  img = imgAr[ Math.floor( Math.random() * imgAr.length ) ];
  imgStr += '<img src="' + randImgObj.imagesPath + img + '" alt="" ';
  imgStr += 'name="img' + (randImgObjs.length-1) + '" width="' + w + '" height="' + h + '">';
  document.write(imgStr);
}

function initRandRotation() {
  for (var i=0; randImgObjs[i]; i++) {
    var rotator = randImgObjs[i];
    rotator.imgObj = document.images["img" + i]; // get reference to the image object
    rotator.addImages(rotator.imgAr);
    rotator.rotate();
  }
  randImgObj.start();
}

