$(document).ready(function(){
	var oldText = 'See what else is new in QuickBooks 2010';
	var newText = 'Minimize - show fewer new features';
	// Make the first item active
	$('ul.whatsNewNav li:first').addClass('active');
	$('.whatsNewBox:first').show();
	// Navigation Click Function
	$('ul.whatsNewNav > li > a').click(function() {
		$('*:animated').stop(true,true);
		var curSecIndex = $(this).parent().parent().attr('id');
		curSecIndex = curSecIndex.substring(curSecIndex.length, curSecIndex.length - 1);

		if (curSecIndex < 3) {
			var curIndex = $('ul#navSection' + curSecIndex + ' li a').index(this);
			$('ul.whatsNewNav > li').removeClass('active').removeClass('notActive');
			if (curIndex == 0 && curSecIndex == 2) {
				$(this).parent().addClass('active');
				$('.whatsNewNav:first > li:last').addClass('notActive');
			} else if (curIndex == 0) {
				$(this).parent().addClass('active');
			} else {
				$(this).parent().addClass('active').prev().addClass('notActive');
			}
			$('.whatsNewBox:visible').hide();
			$('div#whatsNewSection' + curSecIndex).children('.whatsNewBox').eq(curIndex).show();
		} else {
			var curText = $(this).text();
			if (curText == oldText) {
				$(this).text(newText);
				$('#navSection2').slideDown(500);
			} else {
				$(this).text(oldText);
				$('#navSection2').slideUp(500);
				$('.whatsNewNav li').removeClass('active').removeClass('notActive');
				$('.whatsNewNav li:first').addClass('active');
				$('.whatsNewBox:visible').hide();
				$('.whatsNewBox:first').show();
				document.location.hash = '#section1';
			}
		}
	});
	// Goto a specific box on page load
	function pageInt() {
		var whichBox = document.location.hash.toLowerCase();
		if (whichBox != '') {
			whichBox += 'Box';
			var curSecIndex = $(whichBox).parent().attr('id');
			curSecIndex = curSecIndex.substring(curSecIndex.length, curSecIndex.length - 1);
			
			var curIndex = $('#whatsNewBoxParent').children('#whatsNewSection' + curSecIndex).children('.whatsNewBox').index($(whichBox));
			$('.whatsNewNav li').removeClass('active').removeClass('notActive');
			if (curIndex == 0 && curSecIndex == 2) {
				$('.whatsNewNav:first > li:last').addClass('notActive');
				$('#navSection' + curSecIndex + ' li').eq(curIndex).addClass('active');
			} else if (curIndex == 0) {
				$('#navSection' + curSecIndex + ' li').eq(curIndex).addClass('active');
			} else {
				$('#navSection' + curSecIndex + ' li').eq(curIndex).addClass('active').prev().addClass('notActive')
			}
			$('.whatsNewBox').hide();
			$(whichBox).show();

			if (curSecIndex != 1) {
				$('#navSection2').show();
				$('#navSection3 li a').text(newText);
			}
			
		}
	}
	pageInt();
});