function ImageRotator(holderSelector) {
	var _this = this;
	
	
	
	this.init = function(holderSelector) {
		this.container = jQuery(holderSelector);
		this.images = this.container.children('img');
		
		this.currentImage = 0;
		this.rotateSpeed = 4000;
		this.fadeOutSpeed = 1000;
		this.fadeInSpeed = 600;
		
		this.interval = null;
		
		this.startRotation();
	}
	
	
	
	this.startRotation = function() {
		this.interval = setInterval(function() {
			_this.nextImage();
		}, this.rotateSpeed);
	}
	
	
	
	this.stopRotation = function() {
		clearInterval(this.interval);
	}
	
	
	
	this.nextImage = function() {
		this.stopRotation();
		jQuery(this.images.get(this.currentImage)).fadeOut(this.fadeOutSpeed, function() {
			_this.currentImage += 1;
			if (_this.currentImage >= _this.images.length) {
				_this.currentImage = 0;
			}
			jQuery(_this.images.get(_this.currentImage)).fadeIn(_this.fadeInSpeed, function() {
				_this.startRotation();
			});
		});
	}
	
	
	
	this.init(holderSelector);	
}

jQuery(document).ready(function() {
	var rotator = new ImageRotator('#HomepageSlideshow');
});

