(function($) {
	$.fn.timelineSlider = function(options){
		var defaults = {
			previousId: 'previous',
			nextId: 'next',	
			speed: 800
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			var obj = $(this);
			var box_w = obj.width();
			var ul_w = 0;
            $("li", obj).css('float', 'left');
            $("li", obj).css('overflow', 'hidden');
			$("li", obj).each(function() {
			    var w = $(this).outerWidth();
			    $(this).width(w);
			    ul_w += w;
			});
			$("ul", obj).css('width', ul_w);
			$("ul", obj).css('margin-left', -(ul_w - box_w));
			var ts = parseInt(ul_w / box_w);
			var t = ts;
			$("#"+options.nextId).click(function(e){
			    e.preventDefault();
				animate("next");
			});
			$("#" + options.previousId).click(function(e){
			    e.preventDefault();
				animate("previous");
			});
			function animate(dir){
				if (dir == "next" && t < ts){
					t = t + 1;
    				p = (t * box_w * - 1);
    				p = (p < -(ul_w - box_w)) ? -(ul_w - box_w) : p;
	    			$("ul", obj).animate({ marginLeft: p }, options.speed);
				} else if (dir == "previous" && t > 0) {
					t = t - 1;
    				p = (t * box_w * - 1);
	    			$("ul", obj).animate({ marginLeft: p }, options.speed);
				};
			};
		});
	};
})(jQuery);
