$(function() {

	campaignDisplay = $('#campaign-display');
	campaignController = $('#campaign-controller');
	
	if (campaignDisplay.length > 0) {
		campaignDisplay.find('li:gt(0)').hide();
	}
	
	if (campaignDisplay.length > 0 && campaignController.length > 0) {

		campaignController.find('a').hover(function() {
			campaignController.find('li').removeClass('selected');
			$(this).parent('li').addClass('selected');
			position = $(this).parent('li').prevAll().length;
			
			campaignDisplay.find('li').hide().end().find('li:eq('+position+')').show();			
		},function() {

		});
		
	}


});

$(function() {

	var visibleChannels = 4;
	var currentFirstChannel = 1;

	channels = $('#channel-ticker');
	channelCount = channels.find('li').length;
	
	channels.find('ul').animate({ 
		height: "24px"
	}, 400).addClass('wide');

	
	// if there are more channels in the list than can be displayed in the ticker area we should hide the rest and set up the ticker
	if (channelCount > visibleChannels) {
	
		// hide channels that will not initially be shown
		// channels.find('li').hide().end().find('li:lt('+visibleChannels+')').show();

		// add navigation links
		channels.append('<a href="#" class="prev inactive">prev</a><a href="#" class="next">next</a>');

		channels.find('.prev').click(function() {
		
			if (currentFirstChannel > 1) {
		
				currentFirstChannel-=4;
			
				nextChannel = currentFirstChannel + visibleChannels;
			
				//channels.find('li:nth-child('+currentFirstChannel+')').show();
				//channels.find('li:nth-child('+nextChannel+')').hide();
				channels.find('ul').animate({left: (1-currentFirstChannel)*84 + "px"}, 1000 )

				if (currentFirstChannel < 4) $(this).addClass('inactive');
				if (nextChannel <= channelCount) channels.find('a.next').removeClass('inactive');

			} 
		 	
			return false;
		
		});

		channels.find('.next').click(function() {
		
			nextChannel = currentFirstChannel + visibleChannels;
			
			if (nextChannel < channelCount) {
		
			 	currentFirstChannel += visibleChannels;
				
				// channels.find('li:nth-child('+currentFirstChannel+')').hide();
				// channels.find('li:nth-child('+nextChannel+')').show();
				channels.find('ul').animate({left: (1-currentFirstChannel)*84 + "px"}, 1000 )
	
				if ((nextChannel+visibleChannels) >= channelCount) $(this).addClass('inactive');
				if (currentFirstChannel > 1) channels.find('a.prev').removeClass('inactive');

			}
			
			return false;
		
		});

	}
	

});