var count = 0;

$(document).ready(function() {

	/* IE z-index fix.  This is why devs HATE IE */
	if ((navigator.appVersion.indexOf('MSIE 6') > -1) || (navigator.appVersion.indexOf('MSIE 7') > -1))
	{
		var zIndexNumber = 5000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	}

	/* Services */
	$('.service').hover(function () {
		var id = $(this).attr('id');
		$('#' + id + ' > ul').slideDown(200);
		$(this).addClass('hover');
	},
	function() {
		var id = $(this).attr('id');
		$('#' + id + ' > ul').slideUp(200, function () {
			$('#' + id).removeClass('hover');
		});
	});
	
	/* Featured Customers */
	var activeTimer;
	
	$.timer(5000, function(timer){
		activeTimer = timer;
		doRotations(activeTimer);
	});

	// Show the first one automatically
	$('#logo_0').show();
	$('#fNav_0 a').addClass('selected');
	
	// If the nav is used
	$('.fNav').click(function() {
		// Select the box
		var id = $(this).attr('id');
		
		// Fade out the old logo, and in with the new
		var numArr = id.split('_');
		var num = Number(numArr[1]);
		
		doRotations(activeTimer, num);
	});
	
});

function doRotations(timer, cnt)
{
	if (cnt == undefined)
	{
		var num = $('.logo').length - 1;
		
		if (count < num) 
		{
			count += 1;
		}
		else 
		{
			count = 0;
		}
	}
	else
	{
		count = cnt;
	}
	
	swap(timer, count);
}

function swap(timer, num) {
	$('.fNav a').removeClass('selected');
	
	// Select the box
	$('#fNav_' + num + ' a').addClass('selected');
	
	// Fade out the old logo, and in with the new
	$('.logo').fadeOut(200);
	$('#logo_' + num).fadeIn();
	
	// Reset the timer
	timer.reset(5000);
}
