/*
 * This file contains all code needed to execute a random image display. 
 * Simply include this file on any web page where you want to implement the random image display.
 * To implment: 
 *    1) Copy the line below and place it in between the <head> tags of the web page you want to 
 *       implement the random display. 
 *          *copy --> <script src="/includes/list_random_images.js"></script>
 *
 *    2) In the page where you place the line above, make sure the <image> tag and the <p> tag have
 *       the id names like the code snippet below:
 * 
 *           <img id="section-image" src="/images_main/temp_lg_home3.jpg">
 *           <p id="section-image-caption">This the default caption.</p>
 *
 *    3) if you want to include navigation to move or cycle between the different images, paste the 
 *       line below into the page as well just after the image and caption code from item 2 above.
 *       
 *        <?php include($_SERVER['DOCUMENT_ROOT'].'/includes/display_random_images.php'); ?>
 *
 *        ** Please note this is PHP code - so the page you paste this HAS TO BE A PHP page. **
 * 
*/


// ----------- functions related to section images display for the web site ----------- //

// javascript function to change images
function displayImage(a,i) {
   var im = document.getElementById('section-image');
   if (im) im.src = a[i]['path'];
   var c = document.getElementById('section-image-caption');
   if (c && a[i]['caption']) c.firstChild.nodeValue = a[i]['caption'];
}


// javascript function to get a random image from the passed array reference
function getRandomImage(a) {
   var rval = null;
   var newa = a;
   if (newa) {
      // see if array has any children to draw from a larger pool of images
      var ch = getChildSections(newa);
      if (ch != undefined) {
         for (i=0; i < ch.length; i++) { newa.push( ch[i] ); }
         // remove after testing 
         //for (i=0; i < newa.length; i++) { alert(newa[i]['caption']); }
      }
      // get random images
      var ran = Math.floor(Math.random() * newa.length);
      rval = newa[ran];
   }
   return rval;
}


// javascript function to get all child arrays of the passed array reference
function getChildSections(a) {
   var rval = null;
   var newa = new Array();
   if (a != undefined && a['parent'] != undefined) {
      var p = a['parent'];
      for (i=0; i < p.length; i++) {
         for (j=0; j < sections.length; j++) {
            if (sections[j] == p[i]) { 
               var b = eval(p[i]);
               for (k=0; k < b.length; k++) { newa.push( b[k] ); }
            }
         }
      }
   }
   if (newa.length > 0) rval = newa;
   return rval;
}

// code to create a cookie
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


// code to create a cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



// javascript function to show and hide the top image region of the pages
function toggleImages(a) {
   var action = a;
   var t = document.getElementById('hide-image');
   var i = document.getElementById('feature');

   if (i.style.display == 'block') {
      if (i) i.style.display = "none";
      if (t) t.firstChild.nodeValue = 'SHOW IMAGE';
      action = 'hide';
   } else if (i.style.display == 'none') {
      if (i) i.style.display = "block";
      if (t) t.firstChild.nodeValue = 'HIDE IMAGE';
      action = 'show';
   }
   createCookie('sols-image-show',action,0);
}


function checkToggleImages() {
   var i = document.getElementById('feature');
   var t = document.getElementById('hide-image');
   var cookie = readCookie('sols-image-show');
   
   if (cookie == 'hide') {
      if (i) i.style.display = "none";
      if (t) t.firstChild.nodeValue = 'SHOW IMAGE';
   } else if (cookie == 'show') {
      if (i) i.style.display = "block";
      if (t) t.firstChild.nodeValue = 'HIDE IMAGE';
   }
}


function checkImageCookie() {
   var cookie = readCookie('sols-image-show');
   if (cookie == null || cookie == undefined) {
      //alert('creating cookie');
      createCookie('sols-image-show','show',0);
   }
   checkToggleImages();
}





// ------------ Data arrays for the different sections of the web site ----------- //

// this array contains all the section names (arrays from below), used as a master list of all 
// sections for looping through entire list
var sections = new Array('home', 'about', 'ugrad', 'grad', 'people', 'research', 
                         'news', 'support', 'contact', 'bb', 'cm', 'eee', 'geb', 'hd', 'ois', 'facilities');


// Home page section
var home = new Array();
home[0] = { path: '/images_main/home_darwin_sols.gif', caption: 'Why do Darwin&rsquo;s ideas still matter?' };
home[1] = { path: '/images_main/temp_lg_home3.jpg', caption: 'Butterfly catch at desert garden on Tempe campus' };
home[2] = { path: '/images_main/temp_lg_home2.jpg', caption: 'Undergraduate Research' };
home[3] = { path: '/images_main/temp_lg_home.jpg', caption: 'Neurological research' };
home[4] = { path: '/images_main/temp_lg_home4.jpg', caption: 'Natural comb at the Bee Lab on Polytechnic campus' };

// About Us section
var about = new Array();
about[0] = { path: '/about/images/lg_about_01.jpg', caption: '' };
about[1] = { path: '/images_main/temp_lg_home4.jpg', caption: '' };
about[2] = { path: '/about/images/lg_research_cell.jpg', caption: '' };
about[3] = { path: '/about/images/lg_about_em.jpg', caption: '' };
about[4] = { path: '/about/images/lg_about_em2.jpg', caption: '' };
about[5] = { path: '/about/images/lg_bee_guards.jpg', caption: '' };
about[6] = { path: '/about/images/lg_brown_jaguar.jpg', caption: '' };
about[7] = { path: '/about/images/lg_page_bee.jpg', caption: '' };
about[8] = { path: '/about/images/lg_night_about.jpg', caption: 'Nighttime at the Tempe campus' };


//Facilities (About Us) (used support the school as a tester)
var facilities_rnd = new Array();
facilities_rnd['parent'] = [ 'support' ];
facilities_rnd[0] = { path: '/facilities/Images/lse.jpg', caption: 'Life Sciences bridge between E and C building, Tempe Campus' };
facilities_rnd[1] = { path: '/facilities/Images/lg_stock015.jpg', caption: '' };
facilities_rnd[2] = { path: '/facilities/Images/lse3.jpg', caption: 'Nightime studying on Life Sciences E building ledge' };


// Undergraduate Studies section
var ugrad = new Array();
ugrad[0] = { path: '/images_main/temp_lg_home3.jpg', caption: 'Butterfly catch at desert garden on Tempe campus' };
ugrad[1] = { path: '/images_main/temp_lg_home2.jpg', caption: 'Undergraduate Research' };
ugrad[2] = { path: '/images_main/temp_lg_home.jpg', caption: 'Neurological research' };
ugrad[3] = { path: '/images_main/temp_lg_home4.jpg', caption: 'Natural comb at the Bee Lab on Polytechnic campus' };
ugrad[4] = { path: '/ugrad/images/lg_ugrad_lab.jpg', caption: '' };
ugrad[5] = { path: '/ugrad/images/lg_ugrad_ubep.jpg', caption: 'Undergraduate Poster Symposium' };
ugrad[6] = { path: '/ugrad/images/lg_ugrad_ubep2.jpg', caption: 'Undergraduate Poster Symposium' };
ugrad[7] = { path: '/ugrad/images/lg_ugrad_ubep07_02.jpg', caption: '' };
ugrad[8] = { path: '/ugrad/images/lg_ugrad_ubep07_lemau.jpg', caption: '' };
ugrad[9] = { path: '/ugrad/images/lg_ugrad_ubep07.jpg', caption: '' };
ugrad[10] = { path: '/ugrad/images/awards_01.jpg', caption: '' };
ugrad[11] = { path: '/ugrad/images/awards_02.jpg', caption: '' };
ugrad[12] = { path: '/ugrad/images/awards_03.jpg', caption: '' };
ugrad[13] = { path: '/ugrad/images/awards_04.jpg', caption: '' };
ugrad[14] = { path: '/ugrad/images/awards_05.jpg', caption: '' };
ugrad[15] = { path: '/ugrad/images/awards_06.jpg', caption: '' };





// Graduate Studies section
var grad = new Array();
grad[1] = { path: '/grad/images/lg_grad_student.jpg', caption: '' };
grad[2] = { path: '/grad/images/lg_grad_student02.jpg', caption: '' };
grad[3] = { path: '/grad/images/lg_grad_student03.jpg', caption: '' };
grad[4] = { path: '/people/images/lg_people_alcock.jpg', caption: 'Ladybugs. Image courtesy of emeritus, John Alcock' };
grad[5] = { path: '/people/images/lg_neuer_in_lab.jpg', caption: 'Biogeochemist and biological oceanographer Susanne Neuer at work with phytoplankton.' };
grad[6] = { path: '/grad/images/lg_mb_1.jpg', caption: 'Petalonema alatum, a cyanobacterium Image courtesy of Ferran Garcia-Pichel' };
grad[7] = { path: '/grad/images/lg_mb_3.jpg', caption: 'Asterionella, a diatom from local lakes. Image courtesy of Susanne Neuer.' };
grad[8] = { path: '/grad/images/lg_mb_6.jpg', caption: 'Spherule from valley fever fungi engulfed by a human dendritic cell. Image courtesy of Douglas F. Lake.' };
grad[9] = { path: '/grad/images/lg_mb_2.jpg', caption: 'Sampling Mojave soils. Image courtesy of Ferran Garcia-Pichel.' };

// People section
var people = new Array();
people[1] = { path: '/people/images/lg_denardo_d_lab.jpg', caption: 'Dale Denardo in the lab' };
people[2] = { path: '/people/images/lg_neuer_in_lab.jpg', caption: 'Susanne Neuer interests are in the areas of oceanic biogeochemistry, especially the transport of particles and elements from surface water to the deep ocean.' };
people[3] = { path: '/people/images/lg_people_nash.jpg', caption: 'Thomas H. Nash III' };
people[4] = { path: '/people/images/lg_elser_j.jpg', caption: 'James J. Elser high vantage point' };
people[5] = { path: '/people/images/lg_faculty_wu.jpg', caption: 'Jianguo (Jingle) Wu' };
people[6] = { path: '/people/images/lg_people_goldstein.jpg', caption: 'Elliot Goldstein ' };
people[7] = { path: '/people/images/lg_pinkava_people.jpg', caption: 'Emeritus, Donald Pinkava' };
people[8] = { path: '/research/images/lg_research_pratt2.jpg', caption: 'Stephen C. Pratt focusing on social insects' };
people[9] = { path: '/about/images/lg_grad_gadau.jpg', caption: '' };




// Research section
var research = new Array();
research[1] = { path: '/research/images/lg_research_01.jpg', caption: '' };
research[2] = { path: '/research/images/bee1.jpg', caption: 'European honeybees at the Bee lab' };
research[3] = { path: '/sustainability/images/lg_sustain_01.jpg', caption: '' };
research[4] = { path: '/research/images/lg_research.jpg', caption: '' };
research[5] = { path: '/research/images/lg_research_deviche.jpg', caption: 'Image courtesy of Pierre Deviche' };
research[6] = { path: '/research/images/lg_research_pratt2.jpg', caption: 'Stephen C. Pratt' };
research[7] = { path: '/research/images/lg_research_pratt.jpg', caption: '' };
research[8] = { path: '/research/images/lg_research_neuer_ship.jpg', caption: 'image courtesy of Susanne Neuer' };
research[9] = { path: '/research/images/gelss_nels_ad.jpg', caption: '<a href="http://www.asu.edu/clubs/gelss/index.html">The Graduates in Earth, Life, and Social Sciences (GELSS)</a> is a recognized association within Arizona State University, formed by an integrative group of graduate students from different departments of the <a href="http://clas.asu.edu/">College of Liberal Arts and Sciences</a>.' };



// News section
var news = new Array();


// Supporting the School section
var support = new Array();
support[0] = { path: '/support/images/lg_support_01.jpg', caption: 'The School of Life Sciences presents an evolving and innovative model for life sciences research and education' };
support[1] = { path: '/people/images/lg_people_alcock.jpg', caption: 'Ladybugs. Image courtesy of emeritus, John Alcock' };


// Contact Us section
var contact = new Array();
contact[0] = { path: '/contact/images/lg_contact_01.jpg', caption: 'Image by emeritus <a href="/people/faculty/jalcock.php">John Alcock</a>' };
contact[1] = { path: '/contact/images/lg_contact.jpg', caption: 'Image by <a href="/people/faculty/pdeviche.php">Pierre Deviche</a>' };
contact[2] = { path: '/contact/images/lg_contact_lizard.jpg', caption: '' };
contact[3] = { path: '/contact/images/lg_contact_wasp.jpg', caption: '' };



// Biomedicine & Biotechnology section
var bb = new Array();
bb['parent'] = [ 'home', 'undergrad', 'grad' ];
bb[0] = { path: '/galleries/gallery1/images/gallery_01.jpg', caption: 'bb caption for image 1' };
bb[1] = { path: '/galleries/gallery1/images/gallery_02.jpg', caption: 'bb caption for image 2' };
bb[2] = { path: '/galleries/gallery1/images/gallery_03.jpg', caption: 'bb caption here image 3' };


// Cellular & Molecular section
var cm = new Array();
cm['parent'] = [ 'undergrad', 'grad' ];


// Ecology, Evolution & Environmental section
var eee = new Array();
eee['parent'] = [ 'undergrad', 'grad' ];


// Geomics, Evolution & Biometrics section
var geb = new Array();
geb['parent'] = [ 'undergrad', 'grad' ];


// Human Dimensions section
var hd = new Array();
hd['parent'] = [ 'undergrad', 'grad' ];


// Organismal, Integrative & Systems section
var ois = new Array();
ois['parent'] = [ 'undergrad', 'grad' ];

