$(document).ready(function() {
	
		holdername = "#carousel-images"
		cImages = $(holdername + " img").size();
		currentImage = 0;
	
		//Initialisation of the text bar
		imageText = $(holdername + " img:eq(0)").attr("title");
		if(imageText != "") {
			$("#carousel-text").html(imageText);
			$("#carousel-text").slideDown();
		}
	
		var timerval = setInterval(function() {
			moveAlong(1);
		}, 5000);
	
	
	
		$("#next").click(function() {
			
			clearInterval(timerval);
			moveAlong(1);
	
		});
		
		$("#prev").click(function() {
			
			clearInterval(timerval);
			moveAlong(-1);
	
					
		});
		
	});
	
	
	function moveAlong(direction) {
	
		currentImage = currentImage + direction;
	
		$("#carousel-text").slideUp(function() {
			
			imageText = $(holdername + " img:eq(" + currentImage + ")").attr("title");
		
			if(imageText != "") {
				$("#carousel-text").html(imageText);
				$("#carousel-text").slideDown();
			}
			
		});
	
	
		if(currentImage >= cImages) {
			currentImage = 0;	
		}
		
		if(currentImage < 0) {
			currentImage = (cImages-1);	
		}
		
		if(currentImage == 0) {
			$("#prev").fadeOut();	
		} else {
			$("#prev").fadeIn();	
		}
		
		if(currentImage == (cImages-1)) {
			$("#next").fadeOut();	
		} else {
			$("#next").fadeIn();	
		}
		
		var leftPosition = (600 * currentImage * -1)
		
		$(holdername).animate({
			left: leftPosition + 'px'
		},500);	
		
		
	}
