var headerAr = ['assets/images/07Fall19_small.jpg',
                  'assets/images/Administration004_small.jpg',
                  'assets/images/Fall11_1211_small.jpg',
                  'assets/images/07Fall37_small.jpg',
                  'assets/images/campus4_kirkland.jpg',
                  'assets/images/Fall11_1220_small.jpg',
                  'assets/images/07Fall45_small.jpg',
                  'assets/images/campus7_magnolia.jpg',
                  'assets/images/Acorn7_small.jpg',
                  'assets/images/cs0121A_small.jpg'];

var sidebarAr = ['assets/images/alt1.jpg',
                  'assets/images/alt2.jpg',
                  'assets/images/alt3.jpg',
                  'assets/images/alt4.jpg',
                  'assets/images/alt5.jpg'];

var links = [['Driving directions to Vanderbilt University','http://www.vanderbilt.edu/map/vicinity.html'],
             ['Vanderbilt Color Campus Map (PDF)','http://cpc-fis.vanderbilt.edu/pdf/ColorCampusMap.pdf'],
             ['Campus Visitor Parking Map (PDF)','http://cpc-fis.vanderbilt.edu/pdf/VisitorCampusMap.pdf'],
             ['Campus Construction Map (PDF)','http://cpc-fis.vanderbilt.edu/pdf/CampusConstructionMap.pdf'],
             ['Supplier Delivery Parking Map (PDF)','http://cpc-fis.vanderbilt.edu/pdf/VendorPkgSymbolsfinal.pdf'],
             ['Campus Office of Traffic and Parking','http://www.vanderbilt.edu/traffic_parking/'],
             ['Medical Center Shuttle Routes and Schedules (PDF)','http://cpc-fis.vanderbilt.edu/pdf/ShuttleMap.pdf'],
             ['Medical Center Maps and Directions','http://www.mc.vanderbilt.edu/facts/maps.html'],
             ['Medical Center Parking and Transportation','http://www.mc.vanderbilt.edu/root/vumc.php?site=medcenterparking'],
             ['Medical Center Patient and Patient Visitor Parking (PDF)','http://cpc-fis.vanderbilt.edu/pdf/PatientParking.pdf']];

function OpenWindow(url){
   if(!url.length) return;
   newWindow=window.open(url,"links");
}

function genLinks( div ) {
   var div = document.getElementById(div);
   if(typeof div == "undefined" || div == null) return;
   var selectElem = document.createElement("select");
       selectElem.id = "selLinks";
       selectElem.name = "selLinks";
       selectElem.onchange = function(){ OpenWindow(this.value); };
   for(var i=0; i<links.length;i++){
       addSelOption(selectElem,links[i][0],links[i][1],false)
   }
   addSelOption(selectElem,"","",true);
   div.appendChild(selectElem);
}

function addSelOption( div,txt,val,selected ) {
   var opt = new Option();
       opt.setAttribute("selected", selected);
   var optText = document.createTextNode(txt);
       opt.appendChild(optText);
       opt.value = val;
   div.appendChild(opt);
}

// fix IE's lack of support of Javascript
if(!Array.indexOf){
   Array.prototype.indexOf = function(obj){
      for(var i=0; i<this.length; i++){
         if(this[i]==obj){
            return i;
         }
      }
      return -1;
   }
}

function imgHeader() {
   document.getElementById('h_image').innerHTML=randImage(headerAr,3,'class="headerImage"','imgHeader()');
}

function randImage(ar, cnt, param, onclick) {
   // return html code for randon images in an array
   // takes array, # of images to select, params to pass to img tag...ie. class='xxx'
   cnt = (cnt < ar.length) ? cnt : ar.length;           // try not to exceed array boundary
   param = (param != undefined) ? ' '+param+' ' : '';   // make code pretty with spacing
   onclick = (onclick != undefined) ? onclick : false;  // if true, provide <a> to regenerate html
   var used=[];                                         // array of used indexs of ar so we don't duplicate
   var html='';
   while(used.length < cnt) {
      var randId = Math.floor((ar.length)*Math.random());
      if(used.indexOf(randId) == -1) used.push(randId);
   }
   for(var i=0; i<used.length; i++) {
      html += '<img src="'+ar[used[i]]+'"'+param+(onclick ? 'onclick="'+onclick+'"' : ' ')+'/>';
   }
   return html;
}

