var tabsInterval = 0,
	tabsIntervalLength = 10000;

jQuery(document).ready(function() {
	jQuery(function() {
		$("#promo").tabs({ 
			fx: { opacity: 'toggle', duration: 'medium' } 
		}).bind('tabsselect', function (event, ui) { 
			jQuery('#promo-nav li.ui-before-active').removeClass ('ui-before-active');
			if (ui.index > 0) {
				jQuery("#promo-nav li:nth-child(" + ui.index + ")").addClass('ui-before-active');
			}
			clearInterval( tabsInterval );
		});
		
		$(".ui-tabs-nav li:last-child").addClass("ui-last-child");
		$(".ui-tabs-nav li:first-child").addClass("ui-first-child");
		
		tabsInterval = setInterval( "switchTab()", tabsIntervalLength );
	});
});

switchTab = function() {
	var $tabs = $('#promo').tabs(),
		selected = $tabs.tabs('option', 'selected'),
		next = selected + 1 == $tabs.tabs( 'length' ) ? 0 : selected + 1;
	
	$tabs.tabs('select', next);
}

