jQuery.fn.glebsn_carousel = function(){
	var carousel_items = $("#years").find("li").length;
	var item_width = $("#years").find("li").width() + 26; // margin: 265
	var carousel_width = item_width*carousel_items;
	var clip_width = $("#carousel-clip").width();
	var carousel_list = $("#years");
	var first_delta = -26;
	var last_delta = -26;
	var current = $('#current').length ? $('#current').attr('value'):0;
	var speed = 2000;
	
	var can_move = (clip_width) < (carousel_width-first_delta + last_delta);
	
	/* we can move if carousel width minus deltas is bigger than carousel clip */
	if (current && can_move) {
		
		move_carousel_to_position(current);
	}
	
	/* functions */
	$("#next").live("mouseover", function() {
		
		if(can_move) {
			
			var desctination = -carousel_width+clip_width+last_delta+first_delta;
			var current_speed = change_speed(desctination);
			carousel_list.animate({"left": desctination},current_speed, function() { $("#next").addClass("disabled"); });
			$("#prev").removeClass("disabled");
		}
	});
		
	$("#prev").live("mouseover", function() {
		if(can_move) {
			var current_speed = change_speed(first_delta);
			carousel_list.animate({"left": first_delta},current_speed, function() { $("#prev").addClass("disabled");});
			$("#next").removeClass("disabled");
		}
	});
	
	$("#prev").live("mouseout", function() {
		carousel_list.stop();
	});
	
	$("#next").live("mouseout", function() {
		carousel_list.stop();
	});
	
	function change_speed(destination) {
		var current_left = parseInt(carousel_list.css("left"));
		var distance = Math.abs(destination-current_left);
		
		var current_speed = parseInt(speed * Math.pow(distance / parseInt(item_width), 1/1.3) );
		//current_speed = current_speed < 2000 ? 2000:current_speed;
		
		current_speed = Math.round(current_speed/1000)*1000;
		
		
		return current_speed; 
	}
};
