var FeaturedRotate = {
	employers: 0,
	current: 0,
	
	init: function() 
	{
		this.employers = $$('div[id^=featured-employer-]').length;
		if (this.employers > 1) {
			this.wait();
		}
	},

	rotate: function()
	{
		this.current++;
		if (this.current>=this.employers) {
			this.current = 0;
		}
		this.changeAdvertiser();
		this.wait();
	},

	wait: function()
	{
		var self = this;
		setTimeout(function() {
			self.rotate();
		}, 4000);		
	},
	
	changeAdvertiser: function()
	{
		var self = this;
		$$('div[id^=featured-employer-]').each(function(el) {
			var id = parseInt(el.id.replace('featured-employer-', ''));
			if (id == self.current) {
				el.setStyle('display', 'block');
			} else {
				el.setStyle('display', 'none');
			}
		});
	}
		
};

//Initialise on DOM ready
window.addEvent('domready', function() {
    FeaturedRotate.init();
});
