/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
(function($){
	$.fn.newsTicker=$.fn.newsticker=function(b){
		b=b||15000;
		initTicker=function(a){
			stopTicker(a);
			//a.items=$("li",a);
			a.items=$("li[name='vest']",a);
			
			a.items.not(":eq(0)").hide().end();
			a.currentitem=0;
			$("#prev").bind('click', function(){nextPrevTick(a, false); return false;});
			$("#next").bind('click', function(){nextPrevTick(a, true); return false;});
			startTicker(a)
			};			
			
			
		startTicker=function(a){
			a.tickfn=setInterval(function(){doTick(a)},b)
			};			
			
		stopTicker=function(a){
			clearInterval(a.tickfn)
			};
			
		pauseTicker=function(a){
			a.pause=true
			};
		resumeTicker=function(a){
			a.pause=false
			};
		doTick=function(a){
			if(a.pause)return;
			a.pause=true;
			$(a.items[a.currentitem]).fadeOut("slow",function(){
					$(this).hide();					
					a.currentitem=++a.currentitem%(a.items.size());					
					$(a.items[a.currentitem]).fadeIn("slow",function(){a.pause=false})
				})
			};	
		nextPrevTick=function(a,smer){
			if(a.pause)return;
			a.pause=true;
			$(a.items[a.currentitem]).fadeOut("100",function(){
					$(this).hide();
					if (smer){
						a.currentitem=++a.currentitem%(a.items.size());
					}else{						
						if(a.currentitem>0)
							a.currentitem--;
						else
							a.currentitem = a.items.size()-1;
					}
					$(a.items[a.currentitem]).fadeIn("100",function(){a.pause=false})
				})
			};	
					
			
		this.each(function(){
			if(this.nodeName.toLowerCase()!="ul")return;
			initTicker(this)
		}).addClass("newsticker").hover(function(){
				pauseTicker(this)},function(){
				resumeTicker(this)});
				
			
	return this
	}
}
)(jQuery);

