var timerCustomers = null;
var timerTickers = null;

Shadowbox.init();

function setupTicker(duration) {
	
	if (duration == undefined) {
		duration = 6000;
	}
	
	clearTimeout(timerTickers);
	
	timerTickers = setTimeout('rotateTicker()', duration);
}

function rotateTicker() {
	
	if ($('#ticker .tick').length > 1) {
		$('#ticker .tick.select').fadeOut(
			250,
			function() {
				
				$(this).removeClass('select');
				
				if ($(this).attr('id') == $('#ticker .tick:last').attr('id')) {
					$('#ticker .tick:first').fadeIn(250).addClass('select');
				}
				else {
					$(this).next().fadeIn(250).addClass('select');
				}
			}
		);
		
		setupTicker();
	}
}

function setupCustomersTicker(duration) {
	
	if (duration == undefined) {
		duration = 3000;
	}
	
	clearTimeout(timerCustomers);
	
	timerCustomers = setTimeout('rotateCustomersTicker()', duration);
}

function rotateCustomersTicker() {
	
	$('#customers .customer.select').fadeOut(
		350,
		function() {
			
			$(this).removeClass('select');
			
			if ($(this).attr('id') == $('#customers .customer:last').attr('id')) {
				$('#customers .customer:not(#none):first').fadeIn(350).addClass('select');
			}
			else {
				$(this).next().fadeIn(350).addClass('select');
			}
		}
	);
	
	setupCustomersTicker();
}

function selectSubNavigation() {
	
	var url = location.pathname.split('/');
	var tiers = new Array;
	var last = new String;
	var total = new String;
	
	for (var i = 0; i < url.length; i++) {
		
		if (url[i] != '') {
			
			tiers.push(last + '/' + url[i]);
			total = tiers.length;
			last = tiers[total - 1];
		}
	}
	
	if (tiers[0] == Path_root) {
		total -= 1;
	}
	
	$('#sub-navigation a').each(
		function() {
			
			tier = $.inArray($(this).attr('href'), tiers);
			
			if (tiers[0] != Path_root) {
				tier += 1;
			}
			
			if (tier != -1) {
				
				$(this).addClass('tier-' + tier + '-link-select');
				
				if ((tier == 1 && total == 1) || tier == 2) {
					
					var parent = $(this).parent().get(0);
					$(parent).addClass('tier-' + tier + '-select');
				}
			}
		}
	);
}

$(document).ready(
	function() {
		
		if ($('#buckets').length > 0) {
			$('#buckets li').hover(
				function() {
					$(this).addClass('select');
				},
				function() {
					$(this).removeClass('select');
				}
			);
		}
		
		if ($('#ticker').length > 0) {
			setupTicker();
		}
		
		if ($('#customers').length > 0) {
			setupCustomersTicker();
		}
		
		if ($('#sub-navigation').length > 0) {
			selectSubNavigation();
		}
	}
);