(function($) {
	$.fn.vertical_scroller = function(options) {
		// Set the options.
		options = $.extend({}, $.fn.vertical_scroller.defaults, options);

		// Go through the matched elements and return the jQuery object.
		return this.each(function() {
			var element = $(this);
			var in_animation = false;
			var auto_animation = null;
			var waiting_to_animate = null;

			function expand_active_item() {
				element.find('li').each(function() {
					$(this)
						.removeClass('first')
						.removeClass('second')
						.removeClass('third')
						.removeClass('fourth');
				});

				element.find('li:eq(0)').addClass('first');
				element.find('li:eq(1)').addClass('second');
				element.find('li:eq(3)').addClass('third');
				element.find('li:eq(4)').addClass('fourth');

				element.find('li:eq(2)').addClass('active')
					.find('a').animate({"height": "150px"});
			}

			function collapse_active_item() {
				element
					.find('.active')
					.removeClass('active')
					.find('a')
					.animate({"height": "75px"}, 'normal');
			}

			function next() {
				if (in_animation == true) {
					return;
				}

				in_animation = true;

				collapse_active_item();

				var last_item = element.find('li:last');

				last_item.find('a').animate({"height": "0"}, 'normal', function() {
					last_item.detach().prependTo(element.find('ul'))
					expand_active_item();
					last_item.find('a').animate({"height": "75px"}, 'normal', function() {
						in_animation = false;
						wait_for_animation();
					});
				});
			}

			function previous() {
				if (in_animation == true) {
					return;
				}

				in_animation = true;

				collapse_active_item();

				var first_item = element.find('li:first');
				first_item.find('a').animate({"height": "0"}, 'normal', function() {
					first_item.detach().appendTo(element.find('ul'))
					expand_active_item();
					first_item.find('a').animate({"height": "75px"}, 'normal', function() {
						in_animation = false;
						wait_for_animation();
					});
				});
			}

			function start_animating() {
				auto_animation = window.setInterval(next, 5000);
			}

			function wait_for_animation() {
				window.clearInterval(waiting_to_animate);
				waiting_to_animate = window.setTimeout(start_animating, 10000);
			}

			expand_active_item();

			element.find('.first, .second').live('mouseover, mousemove', function() {
				window.clearInterval(auto_animation);
				window.clearInterval(waiting_to_animate);
				next();
			});

			element.find('.third, .fourth').live('mouseover, mousemove', function() {
				window.clearInterval(auto_animation);
				window.clearInterval(waiting_to_animate);
				previous();
			});

			element.find('.active').live('mouseover, mousemove', function() {
				window.clearInterval(auto_animation);
				window.clearInterval(waiting_to_animate);
			});

			element.find('.active').live('mouseout', function() {
				wait_for_animation();
			});

			start_animating();
		});
	};

	// Public defaults.
	$.fn.vertical_scroller.defaults = {
		property: 'value'
	};

	// Private functions.
	function func()
	{
		return;
	};

	// Public functions.
	$.fn.vertical_scroller.func = function()
	{
		return;
	};
})(jQuery);

$('.vertical_scroller').vertical_scroller();
