jQuery.fn.carousel = function(previous, next, options){
	var sliderList = jQuery(this).children()[0];
	
	if (sliderList) {
		var increment = jQuery(sliderList).children().outerWidth("true"),
		elmnts = jQuery(sliderList).children(),
		numElmts = elmnts.length,
		sizeFirstElmnt = increment,
		shownIntoprated = Math.round(jQuery(this).width() / sizeFirstElmnt),
		firstElementOntoprated = 1,
		isAnimating = false;
		
		for (i = 0; i < shownIntoprated; i++) {
			jQuery(sliderList).css('width',(numElmts+shownIntoprated)*increment + increment + "px");
			jQuery(sliderList).append(jQuery(elmnts[i]).clone());
		}
		
		jQuery(previous).click(function(event){
			if (!isAnimating) {
				if (firstElementOntoprated == 1) {
					jQuery(sliderList).css('left', "-" + numElmts * sizeFirstElmnt + "px");
					firstElementOntoprated = numElmts;
				}
				else {
					firstElementOntoprated--;
				}
				
				jQuery(sliderList).animate({
					left: "+=" + increment,
					y: 0,
					queue: true
				}, "swing", function(){isAnimating = false;});
				isAnimating = true;
			}
			
		});
		
		jQuery(next).click(function(event){
			if (!isAnimating) {
				if (firstElementOntoprated > numElmts) {
					firstElementOntoprated = 2;
					jQuery(sliderList).css('left', "0px");
				}
				else {
					firstElementOntoprated++;
				}
				jQuery(sliderList).animate({
					left: "-=" + increment,
					y: 0,
					queue: true
				}, "swing", function(){isAnimating = false;});
				isAnimating = true;
			}
		});
	}
};
