﻿var slide = 2;
var paused = false;
var seconds_per_slide = 3.5;
var playlist = Array();


// fill the playlist
for(var n=1; n<=16; n++) playlist.push(ApplicationPath + '/Uploads/Gallery/Culture_Slideshow/' + n + '.jpg');
var num_slides = playlist.length;


var loader = imagePreloader(playlist);

// set a trigger to start the slideshow after the first image is loaded
loader.setTrigger('0', 'startSlideshow()');	
loader.init();


function slideshow(playlist){
	this.playlist = playlist;
	this.init = function(){
		
	}
}
function startSlideshow(){
	slide = 1;
	updateCounter(1);
	changeSlideShow();
}
function pauseSlideShow(){
	document.getElementById('playButton').src = ApplicationPath + '/images/play-button-white.gif';
	document.getElementById('pauseButton').src = ApplicationPath + '/images/pause-button.gif';
	
	if(window.timer) clearTimeout(timer);
	window.status = 'Paused';
	paused = true;
}
function restartSlideShow(){
	var pause_button = document.getElementById('ctl01_pauseButton');
	updateCounter(1);
	setOpacity(pause_button, 100);
	document.getElementById('ctl01_playButton').src = ApplicationPath + '/images/play-button.gif';
	clearTimeout(timer);
	slide = 1;
	changeSlideShow();
}
function resumeSlideShow(){

	if(paused){
		window.status = '';
		document.getElementById('playButton').src = ApplicationPath + '/images/play-button.gif';
		document.getElementById('pauseButton').src = ApplicationPath + '/images/pause-button-white.gif';
		changeSlideShow();
		paused = false;
	} else {
		
		if(slide>=num_slides){
			restartSlideShow()
		} else {
			//alert('not paused');
		}
	}
}

var activeSlide = -1;
function changeSlideShow(){
	
	if(loader.isLoaded((slide-1))){	// must decrement by 1 since we are lookingat an index
		
		if(slide>2){
			var domid = 'slide' + (slide-3);
			var x = document.getElementById(domid);
			document.getElementById('slide_show').removeChild(x);
		}
		var cont = document.createElement('DIV');
		
		cont.id = 'slide' + (slide-1);
		cont.style.position = 'absolute';
		cont.style.top = '0px';
		cont.style.left = '0px';
		cont.style.overflow = 'hidden';
		
		cont.style.width = '300px';
		cont.style.height = '275px';
				
		cont.zIndex = 100;	
		
		var im = loader.getImage(slide-1);
		
		setOpacity(cont, 0);
		cont.appendChild(im);
		document.getElementById('slide_show').appendChild(cont);
		fadeIn(cont.id, 0, 100);
		updateCounter();
		slide++;
		
		if(slide>num_slides) {
			endShow();		
			clearTimeout(timer);
		} else {
			timer = setTimeout("changeSlideShow()", (seconds_per_slide*1000));
		}
	} else {
		timer = setTimeout("changeSlideShow()", 500);
	}
}
function endShow(){
	fadeOut('pauseButton', 100, 0);
	document.getElementById('ctl01_playButton').src = ApplicationPath + '/images/play-button-white.gif';
}
function updateCounter(number){

	if(document.getElementById('counter')){
	
		if(number) document.getElementById('counter').innerHTML = number + '/' + num_slides;
		else document.getElementById('counter').innerHTML =  slide + '/' + num_slides;
	}
}