BondelagetRotatingGallery = Class.create({

	d: null,  // delay, milliseconds
	c: null,  // count, total number of elements
	dc: null, // displayCount, how many elements to show simultaneously
	arr: null,// array that keeps track of hidden/visible
	i: null,  // pointer to the current start position
	id: null, // the id of the container and the javascript variable

	initialize: function(seconds, displayCount, id) {
	    this.d = seconds*1000;
	    this.dc = displayCount;
	    this.i = 0;
	    this.id = id;

	    // count elements
	    this.c = $(this.id).select('div.image').length;

	    // create lookup table for hidden/visible elements
	    this.arr = new Array(this.c);

	    // update right away
	    this.doStuff();

	    // set up interval
	    setInterval(this.id + ".doStuff()", this.d);

	},
	updateLookup: function(){
	    // initialise array
	    for(var a=0; a<this.c; a++) {
		this.arr[a] = "hidden";
	    }

	    // set visible based on the value of this.i
	    for(a=0; a<this.dc; a++) {
		this.arr[(a+this.i)%this.c] = "visible";
	    }

	    // prepare lookup for next time
	    this.i = (this.i + this.dc)%this.c;
	},
	showElements: function(){
	    // displays/hides elements according to the lookup array
	    for(var a=0; a<this.c; a++) {
		if (this.arr[a] == "hidden") {
		    $(this.id).down('div.image', a).addClassName('hidden');
		} else {
		    $(this.id).down('div.image', a).removeClassName('hidden');
		}
	    }
	},
	doStuff: function(){
	    this.updateLookup();
	    this.showElements();
	}
});
