var $smitscrollCounter = 0;
var $default_px = 500;
var $default_fps = 60;
var $default_pad = 10;

jQuery.fn.smitscroller = function( p_px, p_fps, p_padding ) {
	// Unique id for this scroller instance
	var scrollid = "smitscroller_"+$smitscrollCounter++;
	// Pixels per second to scroll
	var px = (p_px == null) ? $default_px : p_px;
	// Frame rate to scroll
	var fps = (p_fps == null) ? $default_fps : p_fps;
	// Frame interval length
	var intlength = Math.round( 1000 / fps );
	// Pixels per frame to move
	var amnt = px / fps;
	// Wrap the content with the necessary structure
	this.wrap('<div id="'+scrollid+'" class="scrollContainer"></div>').addClass("scrollContent");
	// Add the up and down arrows
	$('#'+scrollid).append('<div class="downArrow"></div>').append('<div class="upArrow"></div>');
	$(this).width( $(this).width() - $('#'+scrollid+" .downArrow").width() - (( p_padding == null ) ? $default_pad : p_padding) );
	// This is the scrollup function
	var e = $(this);
	var o = $('#'+scrollid);
	e.css("top",0);
	var h = $('#'+scrollid).height();
	var offset = h - $(this).height();
	var intid;
	var scrollup = function() {
		var t = parseInt(e.css("top"));
		t += amnt;
		if( t > 0 ) t = 0;
		e.css("top",t);	
	}
	var scrolldown = function() {
		var t = parseInt(e.css("top"));
		t -= amnt;
		if( t < offset ) t = offset;
		e.css("top",t);
	}
	// Up arrow functionality
	$('#'+scrollid+' .upArrow').mousedown( function() {
		clearInterval(intid);
		intid = setInterval(scrollup,intlength);
	}).mouseup( function() {
		clearInterval(intid);	
	});
	// Down arrow functionality
	$('#'+scrollid+' .downArrow').mousedown( function() {										  
		clearInterval(intid);
		intid = setInterval(scrolldown,intlength);
	}).mouseup( function() {
		clearInterval(intid);	
	});
	
	return this;

};