/*!
 * jQuery vertTicker Plugin
 * Author: Mark Sharp
 * Requires: jQuery v1.3.2 or later
 */
 
(function($) {
	$.fn.vertTicker = function(opts) {
		return this.each(function() {
			var defaultOptions = {
				speed: 500,
				timeout: 3000,
				direction: 'down',
				animation: 'none',
				mousePause: true,
				showItems: 3
			};
			var options = $.extend({}, defaultOptions, opts);
			var container = this;
			
			
			var timeoutID = 0;
			
			if($(container).find('li').length<=options.showItems) return;
			
			if(options.mousePause) {
				$(container).hover(function() {
					window.clearTimeout(timeoutID);			
				}, function() {
					timeoutID = window.setTimeout(go,options.timeout);
				});
			}
			
			timeoutID = window.setTimeout(go,options.timeout);
			
			function go() {
				var listItems = $(container).find('li');
				var poppingItem = (options.direction=='up') ? $(listItems).first() : $(listItems).last();
				var theClone = $(poppingItem).clone();
				$(theClone).hide();
				if(options.direction=='up') {
					switch(options.animation)
					{
						case 'hide':
							$(poppingItem).hide(options.speed).remove();
							$(container).append(theClone);
							$(theClone).show();
							break;
						case 'fade':
							$(poppingItem).fadeOut(options.speed,function() {
								$(container).append(theClone);
								$(theClone).show();
							}).remove();
							break;
						case 'slide':
							$(poppingItem).slideUp('slow', function() {
								$(container).append(theClone);
								$(theClone).show();
							}).remove();
						default:
							$(poppingItem).remove();
							$(container).append(theClone);
							break;
					}
					
					
				}
				
				
				if(options.direction=='down') {
	
					switch(options.animation)
					{
						case 'hide':
							$(container).prepend(theClone);
							$(theClone).show(options.speed, function() {
								$(poppingItem).remove();	
							});
							
							break;
						case 'fade':
							$(container).prepend(theClone)
							$(theClone).fadeIn(options.speed, function() {
								$(poppingItem).remove();
							});
							break;
						case 'slide':
							$(container).prepend(theClone)
							$(theClone).slideDown(options.speed, function() {
								$(poppingItem).remove();
							});
						default:
							$(poppingItem).remove();
							$(container).prepend(theClone);
							break;
					}
					
				}
				
				
				
				
				
				timeoutID = window.setTimeout(go,options.timeout);
				
			}
			
		
		
		});
		
	}
    

})(jQuery);

