$(document).ready(function() {
		$('div.itemscroll').itemScroll({interval:3000,speed:600});
});

/*********************
 * Itemscroll plugin *
 *********************/
(function($){
	var methods = {
		init:function(options) {
			var settings = $.extend({
				speed:600,
				interval:3000
			},options);
			return this.each(function(i,e) {
				if($(e).find('ul li').length < 2) return;
				settings.intervalTimer = setInterval(
					function(){methods.onInterval.apply($(e));},
					settings.interval);
				$(e).data('itemscroll',settings);
			});
		},
		onInterval:function() {
			me = this;
			data = this.data('itemscroll');
			height = this.find('ul li').eq(0).outerHeight();
			this.find('ul').animate({
					'marginTop': '-='+height+'px'
				},{
					duration:data.speed,
					complete:function() {
						topItem = me.find('ul li').eq(0).remove();
						me.find('ul').append(topItem);
						me.find('ul').css('marginTop','0px');
					}
				}
			);
		}
	};
	$.fn.itemScroll = function(method) {
		if (methods[method] ) {
			return methods[method].apply(this,
				Array.prototype.slice.call( arguments, 1 ));
		}
	 	else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
	 	}
		else {
			$.error('Method '+method+' does not exist on itemScroll');
		}
	};
})(jQuery);

