/*
Interactive Image slideshow with text description
By Christian Carlessi Salvads (cocolinks@c.net.gt).
Visit http://www.dynamicdrive.com for script
*/
/* kquinn: this script has been considerably modified */


/* global variables */
g_fPlayMode = 0;
g_iimg = -1;
g_imax = 0;
g_ImageTable = new Array(); /* this is the original array. Another smaller array (smallArray) is randomly selected from its contents. */
g_img_dir = '/graphics/sustainability/slideshow/images/';


function illuminate(thisLight) {

    // turn the lights off
    var lights = new Array();
    lights[1] = getobject("light_01");
    lights[2] = getobject("light_02");
    lights[3] = getobject("light_03");
    lights[4] = getobject("light_04");
    lights[5] = getobject("light_05");
    lights[6] = getobject("light_06");
//    lights[7] = getobject("light_07");

    for( n=1;n<lights.length;n++ ) {
	if( thisLight == n ) {
	    // turn on one light
	    //	    var onlight = document.getElementById(thisLight);
	    //      onlight.src = g_img_dir + 'sustainability-slideshow_11.png'
	    
	    lights[n].src = g_img_dir + 'sustainability-slideshow_11.png'
		} else {
		    lights[n].src = g_img_dir + 'off.png';
		}
    }
return false;
}

/* slideshow functions */
function ChangeImage(fFwd)
{
if (fFwd)
{
   if (++g_iimg==g_imax){
         g_iimg=0;
   }
}
else
{
   if (g_iimg==0){
      g_iimg=g_imax;
   }
   g_iimg--;
   
}
Update();
}

function getobject(obj){
if (document.getElementById)
return document.getElementById(obj)
else if (document.all)
return document.all[obj]
}

function Update(){

//  g_imax = 6;

  // need to call modifyimage to apply transition filter for IE
  illuminate(g_iimg+1);
  modifyimage("_Ath_Slide_Container",g_iimg);
  getobject("_Ath_FileName").innerHTML = smallArray[g_iimg][2];

  // added this to create hyperlink
//  getobject("_Ath_Href").href = smallArray[g_iimg][1];
}


function Play()
{
  g_fPlayMode = !g_fPlayMode;
  if (g_fPlayMode)
  {  // play mode
    getobject("btnPlay").alt = "Pause Slideshow";
    getobject("btnPlay").src = g_img_dir + 'pause.png';

    Next();

  } else {    // stop mode
  getobject("btnPlay").alt = "Play Slideshow";
  getobject("btnPlay").src = g_img_dir + 'play.png';
  }
}
function OnImgLoad() {
  if (g_fPlayMode)
  g_to = window.setTimeout("Tick()", g_dwTimeOutSec*1000);
}
function Tick() {
  if (g_fPlayMode)
  Next();
}
function Prev() {
  ChangeImage(false);
}
function Next() {
  ChangeImage(true);
}
function showSlide(number) {

    // stop the show
    Stop();

    // change the current image in the slideshow
    g_iimg = number-1;

    // show one slide
    modifyimage("_Ath_Slide_Container",number-1);

    // show appropriate description
    getobject("_Ath_FileName").innerHTML = smallArray[number-1][2];    
    
    // turn on light which corresponds to it
    illuminate(number);
    return false;
}
function Stop() {

    // clearTimeOut for Tick or the slide change will get erratic after stopping and starting show
    clearTimeout(g_to)

    // change play mode
    g_fPlayMode = false;

    // direct the user
    getobject("btnPlay").alt = "Play Slideshow";

    // change the image to play button
    getobject("btnPlay").src = g_img_dir + 'play.png';
}
    
    


////configure below variables/////////////////////////////


//configure the below images and description to your own. 
/* elements: [0] is the image filepath, [2] is the title/hyperlink shown, [1] is the URL to link to. */
g_ImageTable[g_imax++] = new Array ("/graphics/sustainability/slideshow/charles-kim.jpg","/graphics/sustainability/slideshow/charles-kim_lg.jpg","<div class=\"desc_header\">Charles H. Kim ES</div>\"Charles H. Kim Elementary School's sustainable design epitomizes core CHPS principles.\"<br /><br />- Guy Mehula");
g_ImageTable[g_imax++] = new Array ("/graphics/sustainability/slideshow/maywood.jpg","/graphics/sustainability/slideshow/maywood_lg.jpg","<div class=\"desc_header\">Maywood Academy</div>At the Sustainable Leadership Awards for Design and Development, Maywood was a \"Highly Commended\" Semi-Finalist.");
g_ImageTable[g_imax++] = new Array ("/graphics/sustainability/slideshow/south-east-hs.jpg","/graphics/sustainability/slideshow/south-east-hs_lg.jpg","<div class=\"desc_header\">Southeast Learning Center</div>Southeast Learning Center is a recipient of the Southern California Edison Energy Efficient Schools Award.");
g_ImageTable[g_imax++] = new Array ("/graphics/sustainability/slideshow/john-liechty-ms.jpg","/graphics/sustainability/slideshow/john-liechty-ms_lg.jpg","<div class=\"desc_header\">John Liechty MS</div>John Liechty Middle School is one of the LAUSD \"showcase\" schools and one of our best examples of California High Performance Schools (CHPS).");
g_ImageTable[g_imax++] = new Array ("/graphics/sustainability/slideshow/pv-solar-installation-1.jpg","/graphics/sustainability/slideshow/pv-solar-installation-1_lg.jpg","<div class=\"desc_header\">Pico Rivera Solar Installation</div>Workers installing solar panels for LAUSD's first solar energy generation project in Pico Rivera. This warehouse installation will deliver 1MW of power to more than offset peak demand of this large warehouse.");
g_ImageTable[g_imax++] = new Array ("/graphics/sustainability/slideshow/isee-at-solar-project.jpg","/graphics/sustainability/slideshow/isee-at-solar-project_lg.jpg","<div class=\"desc_header\">iSEE Internship Program</div>Student interns take a listen to Randy Britt, Director of Sustainability Initiatives.<br /><br />iSEE: \"Connecting LAUSD High School Students to Careers in Architecture, Engineering and Construction\"");
g_ImageTable[g_imax++] = new Array ("/graphics/sustainability/slideshow/pv-solar-installation-complete.jpg","/graphics/sustainability/slideshow/pv-solar-installation-complete_lg.jpg","<div class=\"desc_header\">LAUSD Renewable Energy</div>The Pico Rivera Solar Project is the first in the District's program to install a minimum of 50 MW of renewable technology, including solar power, at schools and other facilities by 2012.");


// Kevin Quinn
// March 3, 2004
// set g_imax to the number of  elements of the array for viewing in slideshow


function inArray(value,thisArray) {
   for( i=0;i<thisArray.length;i++ ) {
      if( thisArray[i] === value ) {
         return 1;
      }
   }
return 0;
}

smallArray = new Array();
var z = 0;
var nextnum = null;
g_imax = 6;

while( smallArray.length < g_imax) {
    z++;    
    nextnum = Math.floor(Math.random() * g_ImageTable.length)
	// the break number was increased to 50 so that you always wind up with a full array (small array with g_imax elements)
    if (z > 50) break;
    
    if(!inArray(g_ImageTable[nextnum],smallArray)) { 
       smallArray.push(g_ImageTable[nextnum]);
    }
}

/*
for( n = 0;n<smallArray.length;n++ ) {
     document.write( smallArray[n][0] + ": " + n + "<BR>" );
}
*/

//extend the above list as desired
g_dwTimeOutSec=5

////End configuration/////////////////////////////

if (document.getElementById||document.all)
window.onload=Play



// begin transitions JavaScript

//Preload images ("yes" or "no"):
var preloadimg="no"// otherwise pageload will take too long

//Set optional link target to be added to all images with a link:
var optlinktarget="_self"

//Set image border width
var imgborderwidth=0

//Optionally, change 1.0 and 0.7 below to affect Wipe gradient size and duration in seconds in IE5.5+:
//var filterstring="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=1.0)"
var filterstring="progid:DXImageTransform.Microsoft.Fade(Overlap=1)"

///////No need to edit beyond here/////

if (preloadimg=="yes"){
for (x=0; x<smallArray.length; x++){
var myimage=new Image()
myimage.src=smallArray[x][0]
}
}

function returnimgcode(theimg){
var imghtml=""
if (theimg[1]!="")
imghtml='<a style="cursor:hand;cursor:pointer;"'
imghtml+=' onmouseover = "window.status = \'Click image to open larger image.\'"'
imghtml+=' onclick = "openWindow(\'' + theimg[1] + '\')" target="'+optlinktarget+'">'
imghtml+='<img onload = "OnImgLoad()" width = "346" height="162" src="'+theimg[0]+'" border="'+imgborderwidth+'">'


if (theimg[1]!="")
imghtml+='</a>'
return imghtml
}

function modifyimage(loadarea, imgindex){
if (document.getElementById){
var imgobj=document.getElementById(loadarea)
if (imgobj.filters && window.createPopup){
imgobj.style.filter=filterstring
imgobj.filters[0].Apply()
}
imgobj.innerHTML=returnimgcode(smallArray[imgindex])
if (imgobj.filters && window.createPopup)
imgobj.filters[0].Play()
return false
}
}

function openWindow(urlString) {
popupWin=window.open(urlString,'remote','width=800,height=600,top=50,left=100,resizable=yes')
}




