// Vertically scrolling box
var VerticalScroll = {
	// Options
	'selector':'.scrollable', // Selector used to set things up
	'scrollAmount':100, // Number of pixels to move on each scroll
	'scrollSpeed':400, // Animation speed

	// Initialization function
	'init':function() {

		// Get content box
		var content = $(this.selector);
		if (content.lenth<1) return; // Nothing to do

		// Set up necessary HTML structure; containers first
		content.wrap('<div class="scroll-outer"><div class="scroll-inner"></div></div>');

		// Now the navigation links
		content.parent().parent().prepend('<a class="up" href="#"></a><a class="down" href="#"></a>');

		// And now we set up the actual scrolling code
		$('.scroll-outer>a').click(this.clickHandler);

	}, // End function init()


	// Click / scroll handler
	'clickHandler':function() {

		// Setting up the scroll
		var container = $('.scroll-inner',$(this).parent()); // Inner container
		var curMargin = parseInt(container.css('marginTop'));
		if (isNaN(curMargin)) curMargin=0; // Needed for IE

		// What's our new amount?
		var newMargin = ($(this).hasClass('up'))? curMargin+VerticalScroll.scrollAmount : curMargin-VerticalScroll.scrollAmount;

		// What's our limit?
		if (newMargin > 0) newMargin = 0;
		else {
			var max = container.parent().outerHeight() - container.outerHeight();
			if (newMargin < max) newMargin = max;
		}

		// Finally, animate
		container.animate({'marginTop':newMargin}, VerticalScroll.scrollSpeed);

		// Disable default action
		return false;

	} // End function clickHandler()

};

