function SlideShow_autoStart(){
    //addLoadEvent (this.play());
    //window.onload = this.play ;
    //window.onload= this.play ;
	var pThis = this;
	var f = function(){pThis.play();}
	var timerID = window.setTimeout(f,  1000);
}
function SlideShow_start(){

	if (this.enabled) {
		//alert(this.ticks);
		this.playing = 1;
   		if (this.ticks >= this.slideDuration ) {
			this.ticks=0;
			this.setTicker();
			this.move(1);	// Next slide
			this.ignoreFirstCall=false;
		}
		else {
            	this.ticks++;
               this.setTicker();
  		}
		var pThis = this;
		var f = function(){pThis.start();}
		this.timerID = window.setTimeout(f,  500);

 	}
}
// --------------------------------------------------------------
function SlideShow_setTicker( ){

	if (this.showTicks){

		var elTicker = xbGetElement(window, 'divSSCounter');
		var divWidth = Math.floor(100/  this.slideDuration ) *    this.ticks  + "%";

		if (elTicker)  elTicker.style.width = divWidth;
	}
}
// --------------------------------------------------------------
function SlideShow_move(step){

	var win = window;
	var elImg = win.document.images[this.imgID]
 	if( elImg != null){		// we've found the slideshow image
 		slideCount = this.slideCount;
 		slideFolder =  this.showDir;
 		slideSecs = this.slideDuration;
 		style= this.showStyle.toUpperCase();
 		style= style.substr(0,3);
 		random = (style=='RAN');
 			
	 	this.slideIndex += step;
	 
		if ( this.slideIndex > this.slideCount ) this.slideIndex = 1;
		if ( this.slideIndex < 1 ) this.slideIndex = this.slideCount;
			
		if (is_ie5up) xbElHide(elImg); // Hide in IE5 up so we can transiton
		if (this.preLoad) elImg.src = this.slides[this.slideIndex].src;
		else elImg.src = this.slides[this.slideIndex];
 
 		// Change teh caption if there is one
		if(this.captions[this.slideIndex]) newCap= this.captions[this.slideIndex];
		else newCap = ''; //this.captions[1];
		//alert(newCap);
		 
		if(newCap) {
            if (this.showSlideNums) newText = '<b>Slide ' + this.slideIndex + ' of ' + this.slideCount + '</b>: ' + newCap
            else newText = newCap
  		}
		else newText = ''; //<b>Slide ' + this.slideIndex + ' of ' + this.slideCount + '</b>';
		
		var elTxt = xbGetElement(window, this.textID);
		if (elTxt) xbSetInnerHTML(window, this.textID, newText);

		if (is_ie5up) {	// Filters in IE5+
			elImg.filters.item(0).Transition = this.slideTransition; 
			elImg.filters.item(0).Apply();
			xbElShow(elImg);
			elImg.filters.item(0).Play(1);
		} 			
	}
}
// -----------------------------
function SlideShow_init( ){

	if (getQSParam('pf')==1) this.enabled=false;	// Compatible browser
 	else this.enabled=true;	//
 	// Pre-load the slides - this should be just the next slide?
	this.loadSlides();
	// Do we want controls?
	var elCtrls = xbGetElement(window, 'divSSControls');
	var selOptions;
	if (elCtrls){
		var ctrlHtml = '<table cellpadding="0" cellspacing="0" id="tblSSControls" width="100%"  ><tr>';
		ctrlHtml += '<td width="25%" align="center"><a id="aSSFirst" class="aSSFirst"  href="javascript:void(0)" onclick="return(ss.first());" ><span>First</span></a></td>';
		ctrlHtml += '<td width="25%" align="center"><a id="aSSBack" class="aSSBack"  href="javascript:void(0)" onclick="return(ss.back());" ><span>Back</span></a></td>';
		ctrlHtml +=  '<td width="25%" align="center"><a id="aSSPlay" class="aSSPlay"  href="javascript:void(0)" onclick="return(ss.play());" ><span>Play</span></a></td>';
		ctrlHtml += '<td width="25%" align="center"><a id="aSSNext" class="aSSNext"  href="javascript:void(0)" onclick="return(ss.next());" ><span>Next</span></a></td>';

		ctrlHtml += '</tr>';

		if (selOptions ){
			ctrlHtml += '<tr><td colspan="4"><select id="ssSelect" onChange="this.selectSlide(this)">>';
			ctrlHtml += selOptions;
			ctrlHtml += '</select></td></tr>';
		}
		ctrlHtml += '</table>';

		xbSetInnerHTML(window, 'divSSControls', ctrlHtml);
	}
}
// -----------------------------
// Start/Stop the show!
// -----------------------------
function SlideShow_play(){
	var elPlay = xbGetElement(window, 'aSSPlay'); // get the play/pause button

	if (this.playing){
		if (elPlay) xbSetInnerHTML(window, 'aSSPlay', '<span>Play</span>'); //set the play/pause button to Play
		xbSetElClass(elPlay,'aSSPlay')
		this.stop();
	}
	else{
		if (elPlay) xbSetInnerHTML(window, 'aSSPlay', '<span>Stop</span>');//set the play/pause button to Stop
		xbSetElClass(elPlay,'aSSStop')
		this.ignoreFirstCall=false;
		this.start();
	}
}
// -----------------------------
// Stop the show!
// -----------------------------
function SlideShow_stop(){
	if(this.timerID) clearTimeout(this.timerID);
	this.playing = 0;
    	this.ticks = 0;
	this.setTicker();
}
// -----------------------------
// First slide
// -----------------------------
function SlideShow_first(){
	this.slideIndex =0;
	this.move(1)
}
// -----------------------------
// Next slide
// -----------------------------
function SlideShow_next(){
	this.move(1)
}
// -----------------------------
// {revious Slide
// -----------------------------
function SlideShow_back(){
	this.move(-1)
}
// -----------------------------
// User has clicked on an image so show popup
// -----------------------------
function SlideShow_zoom(){
	this.play();

	zoomPath = this.zoomDir  + this.files[this.slideIndex];
	arSizes =  this.sizes[this.slideIndex].split(',');
	var imgWidth = arSizes[0];
	var imgHeight = arSizes[1];
	caption = this.captions[this.slideIndex];

 	if (this.useDP){
	     dp.setSSData(this.zoomDir, this.files , this.captions, this.sizes );
	     dp.ssView( this.slideIndex );
  	}
 	else if (this.useIV){
	     //iViewSetData( zoomPath, this.files , this.captions  );
    		iViewFiles(this.zoomDir, this.files , this.captions ,this.slideIndex-1 ); // cos we use bad 1-based indexing
  	}
	else openImgWindow(zoomPath, imgWidth, imgHeight, caption, false, false);

}
function SlideShow_selectSlide(elSelect){
	//if (this.playing) this.play() // toggles the player OFF
	alert(this.slides[elSelect.selectedIndex].src)
}
// -----------------------------
function SlideShow_loadSlides(){

	if (this.files.length > 1){

		for(f=1; f <= this.slideCount;f++){

			if (this.preLoad){
				this.slides[f] = new Image();
				this.slides[f].src = this.showDir + this.files[f];
			}
			else {
				this.slides[f]  = this.showDir + this.files[f];
			}
		}
	}
	else{
		for(f=1;f<=this.slideCount;f++){
			if (this.preLoad){
				this.slides[f] = new Image();
				this.slides[f].src = this.showDir + "/slide_" + f + this.slideExtn;
			}
			else this.slides[f] = this.showDir + "/slide_" + f + this.slideExtn;
		}
	}
}
function SlideShow() {

	this.slideIndex = 1;
	this.slideTransition = 12; // 23=random;
	this.slides = new Array();
	this.files = new Array();
	this.sizes = new Array();
	this.captions = new Array();	
	this.showDir=String('');
	this.zoomDir=String('');
	this.zoomWidth=820;
	this.zoomHeight=640;
	this.slideCount=0;
	this.showTicks = true;
	this.playing=0;
	this.interactiveMode=0;
	this.slideDuration=12;
	this.showStyle='SEQ';
	this.showSlideNums=0;
	this.imgID='imgSS';
	this.textID='divSSCaption';
	this.slidePreLoad = new Image();
 	this.slideExtn=".jpg";	
	this.enabled=false;
	this.ignoreFirstCall=true;	// turn off in interactive mode
	this.ticks=0;
	this.start = SlideShow_start;
	this.autoStart = SlideShow_autoStart;
	this.selectSlide = SlideShow_selectSlide;
	this.init = SlideShow_init;
	this.play = SlideShow_play;
	this.first = SlideShow_first;
	this.stop = SlideShow_stop;
	this.zoom = SlideShow_zoom;
	this.setTicker = SlideShow_setTicker;
	this.next = SlideShow_next;	
	this.back = SlideShow_back;
	this.pause = SlideShow_stop;
	this.move = SlideShow_move;
	this.preLoad=true;
	this.useDP=false;
	this.useIV=false;
	this.loadSlides=SlideShow_loadSlides;
}
function xbSetElClass(el,strClass){

	if (el != null){
 		if (document.layers ) ; //unsupported in document.layers.X
		else if (document.getElementById) el.className = strClass;
		else if (document.all ) el.className = strClass;
	}
}