/*
var timerInterval = 5000;  // milliseconds

$(document).ready(function() {
  // preload other frontpage image
  jQuery("<img>").attr("src", "/images/frontpage2.jpg");
  var image = 1;
  $.timer(timerInterval, function(timer) {
    image = ( image == 1 ? 2 : 1 );
    var src = ( image == 1 ? "frontpage.jpg" : "frontpage2.jpg" );
    $('img.frontpage').attr('src','/images/'+src);
  });
});
*/
function delegate( that, thatMethod )
{
	return function() { return thatMethod.call(that); }
}

var slideshow = 
{
		amount:null,
		items:null,
		current:0,
		interval_time:5000,
		interval_id:null,
		initialize:function()
		{
			/*
			for(i=1;i<= this.images;i++)
				jQuery("<img>").attr("src", "/images/slides/slide_" + i + ".png");
			*/
			this.items = $('#slide_images div.moduletable > *');
			this.amount = this.items.length;
			this.showNextImage();
			this.start();
		},
		start:function()
		{
			this.interval_id = setInterval(delegate(this, this.showNextImage), this.interval_time);
		},	
		
		showImage:function()
		{
			$('#slideholder').html(this.items[(this.current -1)]);
		},
		showNextImage:function()
		{
			this.setNext();	
			this.showImage()	
		},
		stop:function()
		{
			clearInterval(this.interval_id);
		},
		setNext: function()
		{
			if(this.current == this.amount)			
				this.current = 1;
			else
				this.current++;
		},setPrevious:function(){
			if(this.current == 1)
				this.current = this.amount;
			else
				this.current--;
		},next:function(){
			this.stop()
			this.showNextImage();
			this.start();
		},previous:function(){
			this.stop();
			this.setPrevious();
			this.showImage();
			this.start();
		},showImageById:function(id)
		{
			this.stop();
			this.current = id;
			this.showImage();
			this.start();
		}
}
$(document).ready(function() {
	//slideshow.initialize();
});
