jQuery.fn.newsTicker = function(settings) {
	
	var ticker = this;
	this.currentItem = 0;	
	this.items = null;
	this.tickFunction = null;
	this.pause = false;
	
	this.settings = jQuery.extend({
		delay: 6000,
		navigation: true
  	}, settings);

	
	
	this.init = function() {
		this.stopTicker();
		
		this.items = $('li', this);
		this.items.addClass('data');
		this.items.hover(
			function() {
				ticker.pauseTicker();
			},
			function() {
				ticker.resumeTicker();
			}
		);
		
		this._hideItems();
				
		if(this.settings.navigation == true) {
			this._buildNavigation();
		}
				
		this.gotoKey(0);
		this.startTicker();
	}
		
	this.stopTicker = function() {
		clearInterval(this.tickFunction);
	}
	
	this.startTicker = function() {
		this.tickFunction = setInterval(function() { ticker.next() }, this.settings.delay)
	}
	
	this.next = function() {
		if(this.currentItem < (this.items.length - 1)) {
			var nextItem = this.currentItem+1;
		} else {
			this.rewind();
			return;
		}
		
		this.gotoKey(nextItem);
	}
	
	this.previous = function() {
		if(this.currentItem > 0) {
			var prevItem = this.currentItem-1;
		} else {
			var prevItem = this.items.length-1;	
		}
		
		this.gotoKey(prevItem);
	}
	
	this.current = function() {
		return $(this.items[this.currentItem]);
	}
	
	this.key = function() {
		return this.currentItem;
	}
	
	this.rewind = function() {
		this.gotoKey(0);		
	}
	
	this.gotoKey = function(itemNum) {
		if(this.pause) return;
		
		this.current().fadeOut('fast', function() {
			$(ticker.items[itemNum]).fadeIn('fast', function() {														 
				ticker.currentItem = itemNum;
			 });
		});

	}
	
	this.pauseTicker = function() {
		if(this.pause == false) this.pause = true;
	}
	
	this.resumeTicker = function() {	
		if(this.pause == true) this.pause = false;
	}
	
	this._buildNavigation = function() {
		this.append('<li class="last"><a class="tickerNext" href="javascript: void(0)"><span>Next</span></a></li>');
		$('li.last a.tickerNext', this).click(
			function() {
				ticker.stopTicker();
				ticker.next();
			}
		);
		
		this.prepend('<li class="first"><a class="tickerPrev" href="javascript: void(0)"><span>Prev</span></a></li>');
		$('li.first a.tickerPrev', this).click(
			function() {
				ticker.stopTicker();
				ticker.previous();
			}
		);
	}
	
	this._hideItems = function() {
		this.items.hide();	
	}
	
	this.init();
	return this;
};

$(document).ready(
	function() {
		$('#newsticker').newsTicker();
	}
);