function slideToSlide(newSlide) {
	var newLeft = newSlide * 640;
	
	$('#slider').animate( { left: '-'+newLeft+'px' }, 'slow');
	$('#slider').data('curSlide', newSlide);
}

$(function() {
	$('#nav a').removeClass('noscript');
	$("#nav a").bind('mouseover', function() {
		$(this).parent().prepend('<span class="navItemHighlight"></span>');
		var highlight = $(".navItemHighlight", $(this).parent());
		
		newWidth = $(this).parent().width();
		highlight.css("width", newWidth);
		highlight.stop().animate({
			height: "24px"
		}, 'fast');
	});
	$("#nav a").bind('mouseout', function() {
		var highlight = $(".navItemHighlight", $(this).parent());
		highlight.stop().animate({
			height: "0"
		}, 'fast', function() {
			highlight.remove();
		});
	});
	
	
	$('#subnav a').removeClass('noscript');
	$('#subnav li').not('.selected').children('a').css("backgroundPosition", "-220px 0px"); //IE needs this line to be set
	$("#subnav a").bind('mouseover', function() {
		$(this).stop().animate(
			{ "backgroundPosition" : "0px 0px" }, '800'
		);
	});
	$("#subnav a").bind('mouseout', function() {
		if (!$(this).parent().is('.selected')) {
			$(this).stop().animate(
				{ "backgroundPosition" : "-220px 0px" }, '800'
			);
		}
	});
	
	$('#people a').bind('click', function() {
		$('.curProfile').removeClass('curProfile');
		$(this).addClass('curProfile');
		
		var content = $(this).attr('rel');
		
		if (!$('#'+content+'Content').is('.openProfile') && $('#peopleContent').is(':visible')) {
			$('#peopleContent').slideUp('normal', function() {
				$('.openProfile').hide().removeClass('openProfile');
				$('#'+content+'Content').show().addClass('openProfile');
				$('#peopleContent').slideDown();
			});
		}
		else {
			$('#peopleContent').slideDown();
		}
	});
	
	$('#faqsText .answer').hide();
	$('#faqsText h4').bind('click', function() {
		if (!$(this).is('.openQuestion')) {
			/*$('.openQuestion').css('backgroundColor', 'transparent');
			$(this).css('backgroundColor', '#FDE503');*/
			
			$('.openQuestion').removeClass('openQuestion');
			$(this).addClass('openQuestion');
			$('#faqsText .answer').slideUp();
			$(this).next('.answer').slideDown();
		}
	});
	
	/*$('#faqsText h4').bind('mouseover', function() {
		if (!$(this).is('.openQuestion')) {
			$(this).css('backgroundColor', '#FDE503');
		}
	});
	$('#faqsText h4').bind('mouseout', function() {
		if (!$(this).is('.openQuestion')) {
			$(this).css('backgroundColor', 'transparent');
		}
	});*/
	
	$('#slider').data('curSlide', 0);
	$('.next').bind('click', function() {
		if (!$(this).is('.nextDisabled')) {
			var nextSlide = $('#slider').data('curSlide')+1;
			if (nextSlide >= ($('.slide').length-1)) {
				$(this).addClass('nextDisabled');
			}
			slideToSlide(nextSlide);
			$('.prev').removeClass('prevDisabled');
		}
	});
	$('.prev').bind('click', function() {
		if (!$(this).is('.prevDisabled')) {
			var nextSlide = $('#slider').data('curSlide')-1;
			if (nextSlide <= 0) {
				$(this).addClass('prevDisabled');
			}
			slideToSlide(nextSlide);
			$('.next').removeClass('nextDisabled');
		}
	});
	
	$('.showFact').bind('click', function() {
		if (!$(this).is('.selectedFact')) {
			var clickedID = $(this).attr('id');
			$('.selectedFact').removeClass('selectedFact');
			$(this).addClass('selectedFact');
			if ($('.openFact').length) {
				$('.openFact').animate({
					//left: '-500px'
					opacity: '0'
				}, 'normal', function() {
					$('#'+clickedID+'_text').animate({
						left: '15px'
					}, 'normal', function() {
						$('.openFact').css('left', '-350px').css('opacity', 1).removeClass('openFact');
						$('#'+clickedID+'_text').addClass('openFact');
					});
				});
			}
			else {
				$('#'+clickedID+'_text').animate({
					left: '15px'
				}, 'normal').addClass('openFact');
			}
		}
	});
});