activeEmployee = activeAnniversary = 0;
empInterval = annInterval = 0;
b_busy_o = false;
b_busy_c = false;
$(function () {
	$('.thickbox').each(function () {
		this.href += '?width=550&height=400';
	});
	$('#news .articles li').each(function(i) {
		if (i > 4) $(this).addClass('minimal');
	});
	$('#announcements .articles li').each(function(i) {
		if (i > 2) $(this).addClass('minimal');
	});
	$('#bulletins li p.summary').hide();
	
	$('#bulletins li div.title').hover(function () {
		if (!b_busy_o) 
		{
			b_busy_o = true;
			$(this).next('p.summary').slideDown('fast', function(){ b_busy_o = false; });
		}
	}, function () {
		if (!b_busy_c) 
		{
			b_busy_c = true;
			$(this).next('p.summary').slideUp('fast', function(){ b_busy_c = false; });					
		}
	});	
	$('.dept').hide();
	$('#employeeDates li').addClass('enhanced').click(function () {
		if ($(this).find('.dept:hidden').length) $(this).find('.dept:hidden').slideDown('fast');
		else $(this).find('.dept:visible').slideUp('fast');
	});
	$('#anniversaries li:first').addClass('active');
	$('#newEmployees li').hide();
	$('#newEmployees').prepend('<p class="navItems"><a href="." class="prev">Previous</a> <span class="count"><span id="employeeIndex">1</span> of '+$('#newEmployees li').length+'</span> <a href="." class="next">Next</a></p>');
	$('#newEmployees div.bio').before('<p class="bio">[ <a href="" class="show">Show Detail</a> ]</p>');
	$('#newEmployees .bio a').click(function () {
		if (this.className == 'show') {
			$('#newEmployees li:visible div.bio').slideDown('fast');
			$('#newEmployees').removeClass('hidebio').addClass('showbio');
			$('#newEmployees p.bio a').html('Hide Detail').removeClass('show').addClass('hide');
			clearInterval(empInterval);	
		} else {
			$('#newEmployees li:visible div.bio').slideUp('fast');
			$('#newEmployees').removeClass('showbio').addClass('hidebio');
			$('#newEmployees p.bio a').html('Show Detail').removeClass('hide').addClass('show');
			startEmployeeAutoRun();
		}
		return false;
	});
	$('#newEmployees li:first').show();
	$('#newEmployees .navItems .prev').click(function () {
		if (activeEmployee == 0) activeEmployee = $('#newEmployees li').length - 1;
		else activeEmployee -= 1;
		changeEmployee();
		return false;
	});
	$('#newEmployees .navItems .next').click(function () {
		if (activeEmployee == ($('#newEmployees li').length - 1)) activeEmployee = 0;
		else activeEmployee += 1;
		changeEmployee();
		return false;
	});
	/* autoruns */
	startEmployeeAutoRun();
	startAnniversaryAutoRun();
	$('#newEmployees').hover(function () {
		clearInterval(empInterval);
	}, function () {
		if (!$('#newEmployees p.bio:visible').length) startEmployeeAutoRun();
	});
	$('#anniversaries li').hover(function () {
		clearInterval(annInterval);
	}, function () {
		startAnniversaryAutoRun();
	});
	$('#menu .stackHead').append('<ul><li class="active"><a href=".">Caf&eacute; Biola</a></li><li><a href=".">Eagle\'s Nest</a></li></ul>');
	$('#menuCafe').addClass('pane').show();
	$('#menuNest').addClass('pane');
	$('#menu .stackHead a').eq(0).click(function () {
		$('#menuNest:visible').hide();
		$('#menuCafe:hidden').show();
		$(this).parent('li').addClass('active').siblings('li').removeClass('active');
		return false;
	});
	$('#menu .stackHead a').eq(1).click(function () {
		$('#menuCafe:visible').hide();
		$('#menuNest:hidden').show();
		$(this).parent('li').addClass('active').siblings('li').removeClass('active');
		return false;
	});
});

function startEmployeeAutoRun() {
	clearInterval(empInterval);
	if ($('#newEmployees li').length > 1) empInterval = setInterval(function () { activeEmployee = activeEmployee == $('#newEmployees li').length - 1 ? 0 : activeEmployee + 1; changeEmployee(); }, 6500);
}
function startAnniversaryAutoRun() {
	clearInterval(annInterval);
	if ($('#anniversaries li').length > 1) annInterval = setInterval(function () { activeAnniversary = activeAnniversary == $('#anniversaries li').length - 1 ? 0 : activeAnniversary + 1; changeAnniversary(); }, 6000);
}
function changeEmployee() {	
	$('#newEmployees li:visible').fadeOut('medium', function () {
		$('#newEmployees li').eq(activeEmployee).fadeIn('medium');
	});
	$('#employeeIndex').html(activeEmployee + 1);
}
function changeAnniversary() {
	$('#anniversaries li:visible').slideUp('medium', function () {
		$('#anniversaries li').eq(activeAnniversary).slideDown('medium').addClass('active');
	}).removeClass('active');
	//$('#employeeIndex').html(activeEmployee + 1);
}
