function ImageRotator(lastId, recensions, img_width) {
	//Starting at 0 so the 3rd element has the index 2
	this.middleElement = 2
	this.firstId = 0;
	this.count = lastId;
	this.recensions = recensions;
	this.shiftLock = false;
	this.shiftCount = 0;
	this.imgWidth = "114px";
	
	this.getId = function (position) {
		//Wrap at the beginning
		if(position < 0 ) {
			return this.count - (Math.abs(position)-1) % (this.count+1);
		}
		//Wrap at the end
		return position % (this.count+1);
	}
	
	this.shiftRecursive = function() {
		if(this.shiftCount>0) {
			this.shiftLeft();
			this.shiftCount--;
		} else if(this.shiftCount<0) {
			this.shiftRight();
			this.shiftCount++;
		}
	}
	
	this.shiftLeft = function() {
		if(this.shiftLock) {
			if(this.shiftCount<0) {
				this.shiftCount=0;
			}
			this.shiftCount++;
			return;
		} else {
			$('.red_border_icon').css('z-index', '10');
			this.shiftLock = true;
			newFirstId = this.getId(this.firstId-1);
			
			lastElement = $('#img_wrap'+newFirstId);
			$('#img_wrap'+this.getId(this.firstId-1)).remove();
			$('#img_wrap'+this.firstId).before(lastElement);
			this.firstId = newFirstId;
			
			$('.rotator').css("margin-left", "-"+this.imgWidth);
			$('#recension_description').fadeTo(500, 0.01, function() {
				ImageRotator.instance.updateRecension();
				$('#recension_description').fadeTo(500, 1);
			});
			
			
			$('.rotator').animate({"marginLeft": "0"}, 1000, function () {
				ImageRotator.instance.shiftLock=false;
				ImageRotator.instance.shiftRecursive();
				$('.red_border_icon').css('z-index', '0');
			});
		}
	}
		
	this.shiftRight = function() {
		if(this.shiftLock) {
			if(this.shiftCount>0) {
				this.shiftCount=0;
			}
			this.shiftCount--;
			return;
		} else {
			this.shiftLock = true;
			$('.red_border_icon').css('z-index', '10');
			this.firstId = this.getId(this.firstId+1);
			$('.rotator').css("margin-left", "0px");
			$('#recension_description').fadeTo(500, 0.01, function() {
				ImageRotator.instance.updateRecension();
				$('#recension_description').fadeTo(500, 1);
			});
			
			$('.rotator').animate({"marginLeft": "-"+this.imgWidth}, 1000, function () {
				firstId = ImageRotator.instance.getId(ImageRotator.instance.firstId-1);
				lastId = ImageRotator.instance.getId(ImageRotator.instance.firstId-2);
				
				firstElement = $('#img_wrap'+firstId);
				$('#img_wrap'+firstId).remove();
				$('#img_wrap'+lastId).after(firstElement);
				
				$('.rotator').css("margin-left", "0px");
				$('.red_border_icon').css('z-index', '0');
				ImageRotator.instance.shiftLock=false;
				ImageRotator.instance.shiftRecursive();
			});
		}
	}
	
	this.center = function(image) {
		id = image.id
		id = id.substr(3)
		pos = this.getId(id-this.firstId);
		while(pos<this.middleElement) {
			this.shiftLeft();
			pos++;
		}
		while(pos>this.middleElement) {
			this.shiftRight();
			pos--;
		}
	}
	
	this.updateRecension = function() {
		id = this.getId(this.firstId+this.middleElement);
		$('#recension_title').html(this.recensions[id]['title']);
		$('#recension_text').html(this.recensions[id]['tx_enetrecension_text']);
		$('#recension_img').html(this.recensions[id]['img']);
		$('#recension_name').html(this.recensions[id]['name']);
		$('#recension_location').html(this.recensions[id]['location']);
		$('#recension_additional').html(this.recensions[id]['additional']);
//		$('#recension_additional_long').html(this.recensions[id]['additional_long']);
		$('#details').html(''+this.recensions[id]['detail_link']+'');
	}
	
	this.updateRecension();	
}
