function initMainMenu() {
	$('div.header #mainmenu ul a').click(function(){
		var contentID = '#' + $('div.contentDisplay').attr('id');
		var targetID = this.href.slice(this.href.indexOf('#'));

		hideContent(contentID,targetID);

		// do not re-show content if we clicked the link for what is already showing
		if (targetID != contentID ) {
			showContent(targetID);
			$(this).addClass('selected');
		}

		return false;
	});
	$('div.wrapper > div.footer a#contactShortcut').click(function(){
		$('div.header > #mainmenu > ul a[href="#contact"]').click();
		return false;
	});
}

function showContent(targetID) {
	targetDiv = $(targetID);
	switch(targetID) {
		case '#trio' :
			$('#masthead').animate({top:'23px'});
			$(targetDiv).slideDown().addClass('contentDisplay');
			break;
		case '#photos' :
			$('#masthead').animate({top:'23px'});
			$(targetDiv).slideDown().addClass('contentDisplay');
			break;
		default:
			targetDiv.fadeIn().addClass('contentDisplay');
			break;
	}
}

function hideContent(contentID,targetID) {
	$('div.header #mainmenu ul a.selected').removeClass('selected');
	contentDiv = $(contentID);
	switch(contentID) {
		case '#trio' :
			if(targetID != '#photos') $('#masthead').animate({top:'100px'});
			contentDiv.slideUp().removeClass('contentDisplay');
			break;
		case '#photos' :
			if(targetID != '#trio') $('#masthead').animate({top:'100px'});
			contentDiv.slideUp().removeClass('contentDisplay');
			break;
		default:
			contentDiv.fadeOut().removeClass('contentDisplay');
			break;
	}
}


function initPhotoLinks() {
	$('#photos a').click(function(){
		$('#photoContainer img').attr('src',$(this).attr('href'));
		return false;
	});
}

function initContent() {
	// get hash
	var winHash = location.hash;

	$('#mainmenu ul a').each(function(){
		// if any link's target matches hash, click it
		if ( this.href.slice(this.href.indexOf('#')) == winHash) {
			$(this).trigger('click');
		}
	});

}

$(document).ready(function(){
	$('body').addClass('done');
	initMainMenu();
	initPhotoLinks();
	initContent();
});
