jQuery.fn.carousel = function(previous, next, options){
	var sliderList = jQuery(this).children()[0];
	
	if (this && sliderList) {
		var increment = jQuery(sliderList).children().width(),
		elmnts = jQuery(sliderList).children(),
		numElmts = elmnts.length,
		sizeFirstElmnt = increment,
		firstElementOnViewPort = 1,
		margin = 10,
		isAnimating = false;
		
		var widthVidewPort = 0;
		var leftMAX = 0;
		for (var i = 0; i < numElmts; i++) {
			widthVidewPort += jQuery(elmnts[i]).width();
			widthVidewPort += margin;
		}
		
		leftMAX = (jQuery('#viewport').width()-widthVidewPort);
		jQuery(sliderList).css('width',(widthVidewPort+1000) + "px");
		
		jQuery(previous).click(function(event){
			if (!isAnimating) {
				if (firstElementOnViewPort > 1) {
					firstElementOnViewPort--;
					li = jQuery(sliderList).children()[firstElementOnViewPort - 1];
					increment = $(li).find('img').width();
					increment=increment+margin;
					jQuery(sliderList).animate({
						left: "+=" + increment,
						y: 0,
						queue: true
					}, "swing", function(){
						isAnimating = false;
					});
					isAnimating = true;
				}
			}
			
		});
				
		jQuery(next).click(function(event){
			if (!isAnimating) {
				if (leftMAX < parseInt(jQuery(sliderList).css('left').replace('px','')) ) {
					firstElementOnViewPort++;
					li = jQuery(sliderList).children()[firstElementOnViewPort - 2];
					increment = $(li).find('img').width();
					increment=increment+margin;
					
					jQuery(sliderList).animate({
						left: "-=" + increment,
						y: 0,
						queue: true
					}, "swing", function(){
						isAnimating = false;
					});
					isAnimating = true;
				}
			}
		});
	}
};

