    var Slideshow = {
	showControls: false,
	controlsDate: false,
	goDate: new Date(),
	doPlay: false,
	doShuffle: false,
	doRepeat: false,
	height: 0,
	width: 0,
	i: 1,
	count: 0,

	init: function(numPhotos){
	    var arrPage = getPageSize();
	    Slideshow.width = arrPage[2];
	    Slideshow.height = arrPage[3];
	    Slideshow.i = 0;
	    Slideshow.count = numPhotos;
		
	    Slideshow.next();
	    Slideshow.play();

	    Slideshow.controlsMove();

	    //_('lightbox').onclick = function(e) {
	    //if (eventIsBubble(e)) return;
	    //hideLightbox();
	    //}

	},

	
	controlsMove: function(){
	    Slideshow.controlsDate = new Date();
	    if (!Slideshow.showControls) {
		Slideshow.showControls = true;
		new Effect.Appear('controls', {duration:.3, queue: {position:'end', scope: 'controlsscope'}});
	    }

	    window.setTimeout("Slideshow.hideControls();", 3500);
	},
	
	hideControls: function() {
	    if (!Slideshow.showControls) return;

	    var curDate = new Date();
	    if ( (curDate-Slideshow.controlsDate)>3000 ) {		
		Slideshow.showControls = false;
		new Effect.Fade('controls', {queue: {position:'end', scope: 'controlsscope'}});
	    }
	},

	next: function(auto){
	    if ( Slideshow.doShuffle ) {
		var next = Slideshow.getShuffle();
	    } else {
		if ( Slideshow.i<Slideshow.count ) {
		    var next = Slideshow.i+1;
		} else {
		    var next = 1;
		} 
	    }
	    Slideshow.go(next, auto);
	},

	prev: function(auto){
	    if ( Slideshow.doShuffle ) {
		var prev = Slideshow.getShuffle()
	    } else {
		if ( Slideshow.i>1 ) {
		    var prev = Slideshow.i-1;
		} else {
		    var prev = Slideshow.count;
		} 
	    }
	    Slideshow.go(prev, auto);
	},

	go: function(num, auto){
	    if (auto==undefined || !auto) {
                var fadeDuration = 0;
                var appearDuration = 0;
                var moveDuration = 0;
            } else {
		var fadeDuration = (navigator.userAgent.toLowerCase().indexOf('opera')>-1 ? 0 : 2);
                var appearDuration = (navigator.userAgent.toLowerCase().indexOf('opera')>-1 ? 0 : 5);
                var moveDuration = 4;

		var curDate = new Date();
                if ( (curDate-Slideshow.goDate)<5000 ) {
		    return;
		}
	    }
	    Slideshow.goDate = new Date();

	    var curObj = document.getElementById("photo"+Slideshow.i);
	    if (curObj) {
   		Effect.Fade("photo"+Slideshow.i, {duration: fadeDuration, fps: 50, afterFinish:function(effect){effect.element.style.display = 'none';}});
	    }
	    
	    var newObj = document.getElementById("photo"+num);

	    // Get object height & width
	    newObj.style.visibility = 'hidden';
	    newObj.style.display = '';
	    var newObjHeight = newObj.height;
	    var newObjWidth = newObj.width;
	    newObj.style.display = 'none';
	    newObj.style.visibility = 'visible';

	    //Place new photo
	    var top = Math.floor((Slideshow.height-newObjHeight)/2.0);
	    var left = Math.floor((Slideshow.width-newObjWidth)/2.0);

	    var xDir = (Math.random()>.5 ? -1 : 1);
	    var yDir = (Math.random()>.5 ? -1 : 1);

	    if ( moveDuration>0 ) {
   	        top += Math.random()*newObj.height*.05*yDir;
	        left += Math.random()*newObj.width*.05*xDir;
            }

	    var yMove = Math.random()*newObj.height*.05*yDir*-1;
	    var xMove = Math.random()*newObj.width*.05*xDir*-1;

	    newObj.style.top = top + 'px';
	    newObj.style.left = left + 'px';

	    new Effect.Appear('photo'+num, {duration: appearDuration, fps: 50});
	    //new Effect.MoveBy('photo'+num, yMove, xMove, {duration: moveDuration, fps: 50});

	    _('detailscount').innerHTML = num + " / " + Slideshow.count;


	    Slideshow.i = num;
	},
	
	play: function(){
	    Slideshow.doPlay = true;
	    Slideshow.updateButton();

	    if (Slideshow.i==Slideshow.count && !Slideshow.doRepeat && !Slideshow.doShuffle) {
		// Stop by going to the first photo
		window.setTimeout("Slideshow.doPlay=false; Slideshow.go(1, true);", 5000);
	    } else {
		// Go! Onwards and upwards...
		window.setTimeout("if (Slideshow.doPlay) {Slideshow.next(true);Slideshow.play();}", 5000);
	    }
	},
	
	stop: function(){
	    Slideshow.doPlay = false;
	    Slideshow.updateButton();
	},
	
	getShuffle: function(){
	    var rnd = Slideshow.i;
	    while (rnd==Slideshow.i) {
		rnd = Math.ceil(Math.random()*Slideshow.count);
	    }
	    return(rnd);
	},

	updateButton: function(){
	    if ( Slideshow.doShuffle ) {
		_s('shuffle').textDecoration = 'underline';
	    } else {
		_s('shuffle').textDecoration = 'none';
	    }
	    
	    if ( Slideshow.doRepeat ) {
		_s('repeat').textDecoration = 'underline';
	    } else {
		_s('repeat').textDecoration = 'none';
	    }
	    
	    if ( Slideshow.doPlay ) {
		_s('play').display = 'none';
		_s('pause').display = '';
	    } else {
		_s('play').display = '';
		_s('pause').display = 'none';
            }
        },

        possiblyStartSlideshow: function(){
            if ( getQueryVariable('startSlideshow') ) {
	       a = $$('a[rel=slideshow]');
	       if(a.length>0) location.href = a[0].href;
            }
        }
    }
