// JavaScript Document

$busaEventsTicker = {
	targetPosition:0,
	currentSetID:0,
	numSteps:0,
	tickerDelay:3000,
	tickerInterval:0,
	autoMode:false,
	targetTicker:new Object(),
	
	init: function(targetTickerValue, autoModeValue) {
		this.targetTicker = targetTickerValue;
		this.autoMode = autoModeValue;
		
		this.numSteps = Math.ceil($(this.targetTicker + ' .events').height() / $(this.targetTicker + ' .events-wrapper ').height());
		
		$(this.targetTicker + ' .events-nav a.up').hover(function() {
			$(this).css('opacity', .8);
		}, function(){
			$(this).css('opacity', 1);
		});
		
		$(this.targetTicker + ' .events-nav a.up').click(function(e) {
			e.preventDefault();
			
			$busaEventsTicker.currentSetID--;
			if($busaEventsTicker.currentSetID < 0){
				$busaEventsTicker.currentSetID = $busaEventsTicker.numSteps - 1;
			}
			
			$busaEventsTicker.moveTicker();
			
			if (this.autoMode) {
				clearInterval($busaEventsTicker.tickerInterval);
				$busaEventsTicker.startTicker();
			}
		});
		
		
		
		$(this.targetTicker + ' .events-nav a.down').hover(function() {
			$(this).css('opacity', .8);
		}, function(){
			$(this).css('opacity', 1);
		});
		
		$(this.targetTicker + ' .events-nav a.down').click(function(e) {
			e.preventDefault();
			
			$busaEventsTicker.currentSetID++;
			
			if($busaEventsTicker.currentSetID == $busaEventsTicker.numSteps){
				$busaEventsTicker.currentSetID = 0;
			}
			
			$busaEventsTicker.moveTicker();
			
			if (this.autoMode) {
				clearInterval($busaEventsTicker.tickerInterval);
				$busaEventsTicker.startTicker();
			}
		});
		
		
		if (this.autoMode) {
			$busaEventsTicker.startTicker();
		}
		
		this.updateTickerArrows();
		
	},
	
	startTicker: function() {
		this.tickerInterval = setInterval("$busaEventsTicker.autoMoveTicker()", this.tickerDelay);
	},
	
	autoMoveTicker: function() {
		this.currentSetID++;
		if(this.currentSetID == this.numSteps){
			this.currentSetID = 0;
		}
		
		this.moveTicker();
	},
	
	moveTicker: function() {
		this.targetPosition = (this.currentSetID * -$($busaEventsTicker.targetTicker + ' .events-wrapper').height()) + "px";
		$($busaEventsTicker.targetTicker + ' .events').stop().animate({"top":this.targetPosition});
	},
	
	updateTickerArrows: function() {
		/*if(this.currentSetID == this.numSteps - 1){
			$('.slideshow-right-arrow img').css('opacity', .5);
			$('.slideshow-right-arrow img').unwrap();
		}
		else{
			$('.slideshow-right-arrow img').css('opacity', 1);
			$('.slideshow-right-arrow img').wrap('<a href="."></a>');
		}
		
		if(this.currentSetID == 0){
			$('.slideshow-left-arrow img').css('opacity', .5);
			$('.slideshow-left-arrow img').unwrap();
		}
		else{
			$('.slideshow-left-arrow img').css('opacity', 1);
			$('.slideshow-left-arrow img').wrap('<a href="#"></a>');
		}*/
	}
	
}

$(function() {
	$busaEventsTicker.init('#events-ticker', false);
	//$busaEventsTicker.init('#news-ticker', false);
})
