$(document).ready(function()
{
	
	
	//put the menu highligter under the selected li
	placeMenuHiglighterOnSelectedLi();
	
	
	if ($('body').hasClass('subPage')) {
		addSubMenu();	
	} else {
		fadeInSubMenu();
	}
	
	//this first thing we want to happen is the title to fade in
	//Once the title is there, we want the rest of the page to come in
	//we need to have it fade in to 0 and then to 1 to make it cross browser compatible - don't ask me why!
	$( '.pageTitle' ).fadeIn("slow", 0.0);
	$( '.pageTitle' ).fadeIn("slow", 1.0);
	setTimeout("fadeInSequence()",1000);
	
	
	
	//this part deals with what happens when a first level nav item is clicked
	$('ul.menu li a').not('ul.menu li ul a').click(function(){
															
	
		//animate the menu highlighter from its current position to the clicked li
		//get the clicked li position
		var clickedLiPosition = $(this).position().top;
		$('#menuHiglighter').animate({'top' : clickedLiPosition - 4}, 500)
		
		//fade out the main page content
		$('#mainContentHolder').fadeOut();
		
		//fade out the sub nav
		$('ul.menu li ul').fadeOut();
		
		//navigate to the new url
		setTimeout("nav('"+this.href+"')",1000);
		return false;
	});
	
	//submenu item clicked 
	$('ul.menu li ul li a').not('ul.menu li ul li.targetBlank a').click(function(){
		$('#mainContentHolder').fadeOut();
		//change the color and move the clicked link out a bit
		$(this).css('color', '#90866f');
		$(this).animate({'padding-right' : 10}, 500);
		//if we're already on a sub page, move back the current li
		if ($('body').hasClass('subPage')) {
			$('ul.menu li ul li.selected a').animate({'padding-right' : 0}, 500)
			.css('color', '#111111');
		}
		setTimeout("nav('"+this.href+"')",1000);
		return false;
	});
});


function fadeInSequence() {
	
	//fade in the text
	$( '.pageText' ).fadeIn("slow", 0.0);
	$( '.pageText' ).fadeIn("slow", 1.0);
	
	var timeDelay = 300;
	var numberOfImages = $("#imageHolder img").size();
	
	var i = 0; //counter
	$("#imageHolder img").each(function() {
		$(this).delay(i++ * timeDelay)								
		$(this).fadeIn("slow", 0.0);
		$(this).fadeIn("slow", 1.0);
	});


};



function nav(href){
	location.href=href;
};


function placeMenuHiglighterOnSelectedLi() {
	//FOR THE MAIN MENU
	//make it visible
	$('#menuHiglighter').css('visibility', 'visible');
	//find the position of the currently selected li
	var selectedLiPosition = $('li.selected').position().top;
	//set menuHighligter to same position
	$('#menuHiglighter').css('top', selectedLiPosition - 3);
};



function addSubMenu() {
	$( 'ul.menu li.selected ul' ).css({'display': 'block'});
};

function fadeInSubMenu() {
	//$( 'ul.menu li.selected ul' ).fadeIn("slow", 0.0);
	//$( 'ul.menu li.selected ul' ).fadeIn("slow", 1.0);
	$( 'ul.menu li.selected ul' ).slideDown(2000);
};
