//scroller
jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};

$(document).ready(function() { 
	// left nav select / deselect on click
	$('.leftNav .jTab').click(function() {
		tabContentID = $(this).attr('href');
		//console.log(tabContentID);
		$(tabContentID).siblings('div').hide();
		$(tabContentID).show(300);
		$(this).parent('li').siblings('li').removeClass('active');
		$(this).parent('li').addClass('active');
		id = $(this).parent('li').parent('ul').attr('id');
		$('#mainNav div a.'+id).parent('div').addClass('active').siblings('div').removeClass('active');
		return false;
	});
	// on events main nave click select gen info and deselect home
	$('#mainNav .events').click(function() {
		$('#genInfo').siblings('div').hide();
		$('#genInfo').show(300);
		$('.leftNav .jTab').parent('li').removeClass('active');
		$('.leftNav .genInfo').parent('li').addClass('active');
		id = $('.leftNav .genInfo').parent('li').parent('ul').attr('id');
		$('#mainNav div a.'+id).parent('div').addClass('active').siblings('div').removeClass('active');
	});
	
	// road rides nav logic
	$('.rideTab').click(function() {
		tabContentID = $(this).attr('href');
		//console.log(tabContentID);
		$(tabContentID).siblings('div.rideInfo').hide();
		$(tabContentID).fadeIn(600);
		$(this).parent('li').siblings('li').removeClass('active');
		$(this).parent('li').addClass('active');
		return false;
	});
	
/*	window.adScrollerApi = $("#adScroller").scrollable().circular().autoscroll({
		autoplay: true,
		api: true
	});
*/	
    $("#adScrollerList").liScroll(); 
});

