newsTicker2 = function () {
	var speed = 8000; //change every 5 secs; TAKE INTO ACCOUNT THE FADE TIME THOUGH!
	var count = 0;
	var trendCount = 0;
	var paused = false;
	var newsHeadlines = $('#missing  span'); //get the headlines
	var instance = this;
	
	this.changeStory = function(direction, hover) {
		var currentItem = $(newsHeadlines).eq(count);
		var newItem;

		timer = window.clearTimeout(timer);
		switch (direction) {
			case 'back' :  //previous
				if(paused) { 
					paused = false; //make sure we unpause when clicking next or previous
				}
				//decrement the count; go to the end if we've reached the first one
				(count === 0) ? count = newsHeadlines.length-1 : count--;
				//get the previous item 
				newItem = newsHeadlines.eq(count);
				break;		
			case 'pause' : //next
				if(!paused) {
					paused = true;
					break;
				} else {
					paused = false;
				}
				

			default : 	//next - or the default
				if(paused) { 
					paused = false;
				}
				//increment the count; set to 0 if we're at the end
				(count === newsHeadlines.length-1) ? count = 0 : count++;
				//get the next one
				newItem = newsHeadlines.eq(count);
				break;
		}
		if(!paused) {
			currentItem.fadeOut(1000, function() {
				newsHeadlines.hide();
				newItem.fadeIn(1000);				
			});
			timer = window.setTimeout(function() {instance.changeStory();}, speed);
		}
	};

/*	this.hoverPause = function(ev) {
		if(ev=="in") {
			timer = window.clearTimeout(timer);
		} else {
			timer = window.setTimeout(function() {instance.changeStory('pause');}, 2000);
		}
	};
	
	//set up event handlers
	$('p#ticker-controls input').click( function() {		
		var direction = $(this).attr('alt');
		instance.changeStory(direction);
	});

	newsHeadlines.hover(function() { 
		instance.hoverPause('in');
	})
	.hover(function() {
		instance.hoverPause('out');
	});
	*/
	//set the timer running
	var timer = window.setTimeout ( function() {instance.changeStory();}, speed);
};	
 
$(document).ready(function() {
	var myTicker = new newsTicker2();
	  
});
 
