Event.observe(window, 'load', function() {
	// add scrolly left and right to the homepage features
	if ($$('#property_slider').length) {
		(function() {

			// generic Shifter component definition
			var Shifter = function(elem, steps, visible, step, callback) {
				this.elem     = $(elem);
				this.steps    = steps   || 0;
				this.visible  = visible || 0;
				this.step     = step    || 0;
				this.callback = callback || null;
				if (this.callback) { this.callback(this); }
			}
			Shifter.prototype = {
				offset : 0,
				active : false,
				shift: function(dir) {
					// ignore clicks until we've finished the last request
					if (this.active) { return; }
					// work out which way we're moving and how far
					var dir = (dir == 'left' ? -1 : 1);
					var dist = this.step * dir;
					// can we move in this direction?
					if ((dir == 1 && this.offset <= 0) || (dir == -1 && this.offset >= (this.steps - this.visible))) { return; }
					// set this shifter active (ignore any other clicks until done)
					this.active = true;
					// move it!
					new Effect.Move(this.elem, {
						x    : dist,
						mode : 'relative',
						// once we're done, we can process new requests
						afterFinish: function() {
							this.active = false;
							this.offset = this.offset - dir;
							if (this.callback) { this.callback(this); }
						}.bind(this)
					});
				}
			}

			// define the new shifter object
			var pod_shifter = new Shifter(
				$$('#property_slider .wrapper')[0],       // container to shift left/right
				$$('#property_slider .property').length,  // number of steps
				2,                                 // the number of visible steps
				233,                               // the size of the steps
				function(sh) {                     // callback to show/hide navs
					var fn = (sh.offset <= 0 ? Element.hide : Element.show); fn($$('#property_slider .prev')[0]);
					var fn = (sh.offset >= (sh.steps - sh.visible) ? Element.hide : Element.show);fn($$('#property_slider .next')[0]);
				}
			);

			// listen to click events on the nav and shift in the appropriate direction
			Event.observe($$('#property_slider .next')[0], 'click', function(e) {
				pod_shifter.shift('left');
				Event.stop(e);
			});
			Event.observe($$('#property_slider .prev')[0], 'click', function(e) {
				pod_shifter.shift('right');
				Event.stop(e);
			});
		})();
 	}
});