/*
 * 	inhouseAdSlideShow.js
 * 	js to turn a list of inhouse image ads into a slideshow
 * 	dominic watson, 25th Feb 2009
 */

var inhouseAdSlideShow = function(el){
	this.root = typeof el == 'string' ? document.getElementById(el) : el;
	
	return this.init();
}

inhouseAdSlideShow.prototype.init = function(){
	this.ads = [];
	this.currentAd = 0;
	this.nAds = 0;
	
	if(this.root){
		var lis = this.root.getElementsByTagName('li');
		
		this.nAds = lis.length;
		
		for(var i=0; i < this.nAds; i++){
			this.ads.push(lis[i]);
		}
	}
	
	return this;
}

inhouseAdSlideShow.prototype.nextAd = function(){
	if (this.nAds > 0) {
	
		if(this.currentAd < 0 || this.currentAd > this.nAds-1){
			this.currentAd = 0;
		}
		
		for(var i=0; i<this.nAds; i++){
			this.ads[i].className = '';
		}
		this.ads[this.currentAd].className = 'active';
		
		this.currentAd++;
	}
}

var mySlideShow = new inhouseAdSlideShow('inline-ads');
setInterval("mySlideShow.nextAd()", 4000);
