// SlideShow Code


/////////////////////////////////////////////////////////////////////////////////////
// Dave 24/08/08
// Globals for slideshow speed

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000

// Duration of crossfade (seconds)
var crossFadeDuration = 3


//////////////////////////////////////////////////////////////////////////////////////
// Dave 24/08/08
// Global timeout function for clicking over slides - nb not part of class 
// (couldnt supply hook to outr class as callback, so used global menus[])
// It refernces global variable elecdes_slideshow which is created by a new call in the html
// ... var elecdes_slideshow = new slideshow(23, "eld_ss", 400, 300  );


function global_timeout( imagename, menu_id ) 
{
	elecdes_slideshow.slide_change(imagename) ;
}


//////////////////////////////////////////////////////////////////////////////////////
// Dave 24/08/08
// Classes  function to click over a slide 
//
//


function slideshow_slide_change(imagename) 
{
    var new_image_path;
    
    this.currentslide++; // else increment
    
   // limit requested / incremented number
   if (this.currentslide >=  this.count) {
       this.currentslide = 0; // save current slide num
   }

    // Demand load version 
    // set up slide only as required
    if (this.szfilenamepath[this.currentslide] != "") {
        window.status = "Loading " +  this.szfilenamepath[this.currentslide] + "  ...";
        this.SlideImages[this.currentslide].src = this.szfilenamepath[this.currentslide];
	this.szfilenamepath[this.currentslide] = "";
        window.status = "Done";
    }

    // build string
    new_image_path = "" + this.SlideImages[  this.currentslide  ].src +"";

    // enable cross fade if browser is compatible
    // NB: uses our selected image
    if (document.all)
    {
         document.images[imagename].style.filter="blendTrans(duration=2)"
         document.images[imagename].style.filter="blendTrans(duration=crossFadeDuration)"
         document.images[imagename].filters.blendTrans.Apply()      
    }

    //display it in aour intital image box
    if (document.images) document.images[imagename].src = new_image_path;

    // Run cross fade if browser is compatible
    // NB: uses our selected image
    if (document.all){
      document.images[imagename].filters.blendTrans.Play()
    }


}




//////////////////////////////////////////////////////////////////////////////////////
// Dave 24/08/08
// Setup Large Changing graphic on left of page for each page
//

function slideshow(  numberofslides, slidefileprefix, ssW, ssH) 
{

    // Check for a count before doing anything
    if (numberofslides < 1) return;
    
    var str;
    var i;

    // Initialise

    this.get_path = general_get_path;                // hook the path generator function - requires inclusion of js/scada_general.js
    this.slide_change = slideshow_slide_change;                // hook the slide change function 
    this.xpos = 0;
    this.ypos = 0;
    this.w =    ssW;   // width from caller usually 400
    this.h =    ssH;   // heigth from caller usually 300

    this.name = slidefileprefix; 
    this.alt_string = 'EDS slideshow';
    this.SlideImages = [];
    this.count = numberofslides;
    this.slidefilepathandprefix = "";
    this.slidefilesuffix = ".gif";
    this.szfilenamepath = []; 
    this.currentslide = 0;
    
    // set current slide to the first one.
    this.currentslide = 0;

    // build up the filenames, first the path and prefix, requires number AND .gif
    str = "" + this.get_path("images") + slidefileprefix + "";
    this.slidefilepathandprefix = str;
    
    // now the full filenames are built and the images made
    for (i = 0; i < this.count; i++ ) {

       this.SlideImages[i] = new Image();
       str = "" + this.slidefilepathandprefix + i + this.slidefilesuffix + "";
       this.szfilenamepath[i] = str;

// this.SlideImages[i].src = str;
// Demand load version 
     }

    // Demand load version 
    // set up slide 0 only
    if (this.szfilenamepath[0] != "") {
       	   
       window.status = "Loading " +  this.szfilenamepath[0] + "  ...";
       this.SlideImages[0].src = this.szfilenamepath[0];
       this.szfilenamepath[0] = "";
       window.status = "Done";
    }
   
    // make the first image appear as a static item and 
    document.write (
		'<a class = "slide_show"'
			+' style= "position: absolute; top: ' + this.ypos + 'px;left: ' + this.xpos + 'px;"'
			+' onClick =    "slideshow_slide_change(\''+this.name+'\', -1 );"'   // change to start on click
			+' ondClick =   "slideshow_slide_change(\''+this.name+'\', 0 );"'    // change to start on click
			+' >'
			+' <img src="'+ this.SlideImages[0].src +'"'
			+' alt=   "'+   this.alt_string   +'"'
			+' width = "'+  this.w            +'"'
			+' height = "'+ this.h            +'"'
			+' name = "' +  this.name         + '"></a>\n'

	);


    // Automatic cycler set to 3 seconds
    setInterval('global_timeout("' + this.name + '")', slideShowSpeed); // default is 5000ms

}

