var FeaturedPropertyRotator = Class.create();
FeaturedPropertyRotator.prototype = {
	initialize:function(options){
		this.options = {
			selector: 'div.FeaturedHomeItem',
			prevButtonSelector: 'a.FeaturedHomePrev',
			nextButtonSelector: 'a.FeaturedHomeNext',
			time: 6000,
			doshow: null
		}
		Object.extend(this.options, options || {});
		this.elements = {next:null,prev:null,properties:null,currentProp:0,timer:null}
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {window.onload = function(){this.onLoad();}.bind(this)}
		else {window.onload = function(){oldonload(); this.onLoad();}.bind(this)}
	},
	onLoad: function(){
		this.elements.properties = $$(this.options.selector);
		if(this.elements.properties.length > 0){
			this.elements.next = $$(this.options.nextButtonSelector);
			this.elements.prev = $$(this.options.prevButtonSelector);
			for(var i=0; i<this.elements.next.length; i++){
				Event.observe(this.elements.next[i], 'click', this.next.bindAsEventListener(this));
			}
			for(var i=0; i<this.elements.prev.length; i++){
				Event.observe(this.elements.prev[i], 'click', this.prev.bindAsEventListener(this));
			}
			this.elements.timer = setTimeout(function(){this.rotate();}.bind(this), this.options.time);
		}
	},
	next: function(event){
		if(event != null){Event.stop(event); clearTimeout(this.elements.timer);}
		this.elements.properties[this.elements.currentProp].style.display = 'none';
		this.elements.currentProp++;
		if(this.elements.currentProp >= this.elements.properties.length){this.elements.currentProp = 0;}
		this.elements.properties[this.elements.currentProp].style.display = 'block';
	},
	prev: function(event){
		if(event != null){Event.stop(event); clearTimeout(this.elements.timer);}
		this.elements.properties[this.elements.currentProp].style.display = 'none';
		this.elements.currentProp--;
		if(this.elements.currentProp < 0){this.elements.currentProp = this.elements.properties.length - 1;}
		this.elements.properties[this.elements.currentProp].style.display = 'block';
	},
	rotate: function(){
		if(this.options.doshow == false){
			this.elements.timer = null;
			return false;
		}else{
			this.next();
			clearTimeout(this.elements.timer);
			this.elements.timer = setTimeout(function(){this.rotate();}.bind(this), this.options.time);
		}
	}
}
