$(document).ready(function(){
	init_css();	
	$(window).resize(function(){ init_css(); });
	
	init_cycle();
	init_menu();
	
	do_height();
});

function init_menu(){
	$('#nav li').click(function(){
		$('#nav li.active').removeClass('active');
		$(this).addClass('active');
	});
}

function init_cycle(){
	$('#content').cycle({
		fx: 'fade',
		timeout: 0,
		speed: 500,
		startingSlide: 0,
		after: onAfter
	});
}

function onAfter(curr, next, opts, fwd) {
	var index = opts.currSlide;
	//get the height of the current slide
	var $ht = $(this).height();
	//set the container's height to that of the current slide
	$(this).parent().css('height', $ht);
}


function init_css(){
	// header shadow
	var shadow_width = ($(window).width() - 1020) / 2;
	$('#header .shadow').css('left', shadow_width + 'px')
	
	//the main nav
	var nav_width = 20;
	$('#nav li').each(function(){
		nav_width += $(this).outerWidth();
	});
	$('#nav')
		.css('width', nav_width + 'px')
		.css('margin', '0 auto');
}

var check_height = true;
function do_height(){
	if( check_height == true && $('#content .current_thing').length > 0 ){
		//$(this).closest('#content').height( $(this).outerHeight() );
	}
}
