(function($) {

$.fn.jScroll = function(options) {
	
	var offset = $('#jScroll_content').height()-$('#jScroll_wrapper').height()+$('#jScroll_bottom').height();
	//var offset = $('#jScroll_content').height();
	
	if(!options)
		options = {duration: false, mousewheel: false};
		
	if(!options.duration)
		options.duration = offset*5;
	
	
	// mouse wheel
	if(options.mousewheel)
	{
		$('#jScroll_content').mousewheel(function(e, d){
			
			var top = d > 0 ? '0' : '-'+offset;
			
			$('#jScroll_content').animate({
			'top': top+'px'
			}, options.duration, 'linear');
		});
	}

	// up
	$('#jScroll_link_up').click(function(e) {
		e.preventDefault();
	});
		
	$('#jScroll_link_up').mouseover(function() {

		offset = $('#jScroll_content').height()-$('#jScroll_wrapper').height()+$('#jScroll_bottom').height()+10;
		
		var duration = (Math.abs(parseInt($('#jScroll_content').position().top)))*options.duration/offset;
		
		$('#jScroll_content').animate({
			'top': '0px'
		}, duration, 'linear');
	});

	$('#jScroll_link_up').mouseout(function() {
		$('#jScroll_content').stop();
	});
	

	// down
	$('#jScroll_link_down').click(function(e) {
		e.preventDefault();
	});
	
	$('#jScroll_link_down').mouseover(function() {
	
		offset = $('#jScroll_content').height()-$('#jScroll_wrapper').height()+$('#jScroll_bottom').height()+10;
		
		var duration = (offset + parseInt($('#jScroll_content').position().top))*options.duration/offset;
		
		$('#jScroll_content').animate({
			'top': '-'+offset+'px'
		}, duration, 'linear');
	});

	
	$('#jScroll_link_down').mouseout(function() {
		$('#jScroll_content').stop();
	});
};

})(jQuery);
