/*! NV News Ticker v1 <http://nvinteractive.co.nz>
	Copyright (c) NV Interactive
	
	References:
		jquery-1.2.6.js
		
	Release Notes:

	Usage:
		
		
*/

nvNewsTicker = function(){
	
	var TICKERDELAY = 5000;
	var REVEALSPEED = 500;
	
	var init = function(){
		
		$(".news-ticker").each(setupTicker);		
		
	}
	
	var setupTicker = function(){
		
		var itemCount = $("li", this).css("display", "none").length;
		
		$(this)
			.data("itemCount", itemCount)
			.hover( pause, start);
		
		showItem(this, 0);
		start(this);
	}
	
	var showItem = function(list, i){
		
		i = i >= $(list).data("itemCount") ? 0 : i;
		
		$("li", list)
			.css("display", "none")
			.eq(i).fadeIn(REVEALSPEED);
			
		$(list)
			.data("currentItem", i);
	}
	
	var showNext = function(list){ 
		var currentItem = $(list).data("currentItem");
		showItem(list, currentItem + 1);
	}
	
	var pause = function(){
		clearInterval( this.__newsTickerInterval);
	}
	
	var start = function(list){
		el = list.tagName == undefined ? this : list;
		el.__newsTickerInterval = setInterval( function() { showNext( el ) }, TICKERDELAY );
	}
	
	
	return {
	/* Public API
	*/
	init: init
	}
}();

$(document).ready(nvNewsTicker.init);

/*
	var headline_interval;
	
	function headline_animate(){
		var el = $("#news-ticker ul");
		var cp = Number(el.attr("currentPosition"));
		
		if(cp + el.height() <= 0){
			cp = 15;
			el.css({top: 15});		
		}
		
		el.animate({top: cp - 15}, 500);
		el.attr({currentPosition: cp-15});
	}
	
	
	$(document).ready(function(){
	
		var el = $("#news-ticker ul");
		el.attr({currentPosition: 0});
		headline_interval = setInterval(headline_animate, 3000);
		
		$('#latest_news ul').hover(function() {
		clearInterval(headline_interval);
		}, function() {
			headline_interval = setInterval(headline_animate,3000);
		});
	
	
	});
*/