function logme(a) {
	var m = $('messages');
    var b = document.createTextNode(a);
	m.appendChild(b);
	m.appendChild(new Element('br'));
};
function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
};
var so =  function(opacity){
		if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
		if (window.ie) this.style.filter = (opacity == 1) ? '' : "alpha(opacity=" + opacity * 100 + ")";
		this.style.opacity = this.$tmp.opacity = opacity;
		if (opacity == 0){
			if (this.style.visibility != "hidden") this.style.visibility = "hidden";
		} else {
			if (this.style.visibility != "visible") this.style.visibility = "visible";
		}
		return this;
}	

var PauseSlideshow = false;
var Slideshow = new Class({
	initialize: function(imagearray) {
		this.imagearray = imagearray;
		this.effect = new Fx.Styles($('overdiv'), {wait: false, duration: 800, fps:30});
		this.currentImage = -1;
		this.effect2 = new Fx.Styles($('slideindicator'), {wait: false, duration: 800, fps:30});

		this.nextSlide(true);
	},
	nextSlide: function(bFirst) {
		if( PauseSlideshow) {
			this.nextSlide.delay(500, this);
			return;
		}
	
		if (this.currentImage < this.imagearray.length-1) {
			this.currentImage++;
		} else {
			this.currentImage = 0;
		}
		if( !bFirst) {
			this.showSlide.delay(3000, this);
		} else {
			this.showSlide();
		}
	},
	showSlide: function() {
		// If this is not the first image, set the base image to the over image
		if( $('overdiv').getStyle('display') != 'none') {
			$('base').onload = function() { this.baseLoaded(); }.bind(this);
			$('base').src =  $('over').src;
		} else {
			this.loadImage();
		}
	},
	baseLoaded: function() {
		$('base').setStyle('display','');
		this.loadImage();
	},
	loadImage: function() {
		$('overdiv').setStyle('opacity', 0.0);
		$('over').onload = function() { this.imageLoaded(); }.bind(this);
		$('over').src =  this.imagearray[this.currentImage];
	},
	imageLoaded: function() {
		$('overdiv').setStyle('display','');
		
		this.effect.start({
			'opacity': 1.0
		});
		this.effect2.start({
			'left': (this.currentImage*38)
		});

		this.nextSlide(false);
	}
});

