
var slide_show_speed = 6000;

var t;
var j;
var loadedImages = [];
var imageIsLoaded= new Boolean(true);
var soundIsPlaying = new Boolean(false);
var pic_array_length = pic_array.length;
chosen_image = new Image();
chosen_image.src = url + pic_array[random(pic_array.length)];

shuffle (pic_array);




function run_slide_show(){
   //writeUpdate(pic_array.length);
   if (imageIsLoaded)  {
   document.images.SlideShow.src = chosen_image.src;
   loadedImages.push (chosen_image.src);
   pic_array.shift();
   } 
   imageIsLoaded=true;
   chosen_image = new Image();
   chosen_image.onLoad = function() {
          imageIsLoaded=true;
   				};
   if (pic_array.length >0) {
   		chosen_image.src = url + pic_array[0];
   } else {
   		chosen_image.src = loadedImages[random(loadedImages.length)];
   }
   t = setTimeout('run_slide_show()', slide_show_speed);
}

function writeUpdate(x) {
		document.getElementById('debug_box').innerHTML = x;
}

function random(x) {
// returns random interger st 0 ≤ i ≤ (x-1)
// http://www.merlyn.demon.co.uk/js-randm.htm
    return Math.floor(x * (Math.random() % 1));
}

function shuffle(q) {
// http://www.merlyn.demon.co.uk/js-randm.htm
    var j, k, t;
    for (j = q.length - 1; j > 0; j--) {
        k = random(j + 1);
        t = q[j];
        q[j] = q[k];
        q[k] = t;
    }
    return q;
}

function toggleSound() {
   if (document.getElementById("toggle_sound").firstChild.nodeValue=="play sound") {
		document.getElementById('add_sound').innerHTML = '<embed src="http://verix-the-cat.net/mp3/lj/080321/alabama_3-power_in_the_blood.mp3"  width="1" height="1" autostart="true" hidden="true" loop="true">'
        document.getElementById('toggle_sound').innerHTML =  'stop sound'
   } else { 
		document.getElementById('add_sound').innerHTML = "stop";
        document.getElementById('toggle_sound').innerHTML =  'play sound'
   }
 }


