$(document).ready(function() {

	// Let the CSS know that the user does indeed have Javascript enabled
	$('#coreexpectations').removeClass('nojs').css('display','none');
//	$('#coreexpectations').removeClass('nojs');

	// Hide the slideshow on load, append the "Back/Next" div
	$('#slides').css('opacity',0).before('<a id="closethis" href="#">close<span>&#215;</span></a>').append('<div rel="generated" id="pagination"><a href="#" id="back">&laquo; <span>Back</span></a> | <a href="#" id="next"><span>Next</span> &raquo;</a>');

	// Append the "learn more" button
	$('#intro').append('<a href="#">Learn More</a>');

	// Hide the intro text on click
	$('#intro a').click(function(event){
		event.preventDefault();
		if( $.browser.msie && $.browser.version < 7 ){
			$('#intro').css('display','none');
			$('#slides').css('opacity',1);
		}else{
			$(this).parent().animate({ 'opacity': 0 }, 700, function(){
				$(this).hide();
			});
			$('#slides').animate({ 'opacity': 1 }, 700);
		}
	});

	$('a[href="#coreexpectations"]').click(function(event){
		event.preventDefault();
		$('#coreexpectations').css({
			'display': 'block',
			'opacity': 0
		}).animate({
			'opacity': 1
		}, 350);
	});

	$('#closethis').click(function(event){
		event.preventDefault();
		$('#coreexpectations').animate({
			'opacity': 0
		}, 350, function(){
			$(this).css('display','none');
		});
	});

	// Set up the carousel
	var theSpeed = ( $.browser.msie && $.browser.version < 7 ) ? 1 : 350;
	$('#slides ol').cycle({
		fx: 'fade',
		speed: theSpeed,
		prev: $('#back'),
		next: $('#next'),
		timeout: 0,
		nowrap: 1,
		cleartype: 1,
		before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			// Dim the next/previous button if it doesn't have a use
			if( $(nextSlideElement).nextAll('li').length == 0)
				$('#next').addClass('disabled');
			else
				$('#next').removeClass('disabled');
		},
		after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			if( $(nextSlideElement).prevAll('li').length == 0 ){
				$('#back').unbind('click');
				$('#back').bind('click.uncycle', function(event){
					event.preventDefault();
					if( $.browser.msie && $.browser.version < 7 ){
						$('#intro').css('display', 'block');
						$('#slides').css('display','none');
						$('#intro').css('opacity',1);
					}else{
						$('#slides').animate({ 'opacity': 0 }, 700);
						$('#intro').css('display', 'block');
						$('#intro').animate({ 'opacity': 1 }, 700);
					}
				});
			}
			else
				$('#back').unbind('click.uncycle');
		}

	});

});
