$(document).ready(function(){
	//References
	var sections = $("#menu li");
	var loading = $("#loading");
	var content = $("#content");
	
	//Manage click events
	sections.click(function(){
		//show the loading bar
		showLoading();
		//load selected section
		switch(this.id){
			case "home":
				content.slideUp();
				function HomeLoad()
				{

				content.load("sections.html #section_home", hideLoading);
				content.slideDown();
				}
				setTimeout(HomeLoad, 400);
				break;
			case "kosken":
				content.slideUp();
				
				function KoskenLoad()
				{
					content.load("sections.html #section_Kosken", function(){
					hideLoading();
					$('#KoskenCA').load('available.html #Kosken_InfoCA')
					$('#KoskenFL').load('available.html #Kosken_InfoFL')
					$('#KoskenMI').load('available.html #Kosken_InfoMI')
					
					$(".toolPop").tooltip({ effect: 'slide', opacity: 1, offset:[0,0] });
					})
			
				
					content.slideDown();	
				}
				
				
				setTimeout(KoskenLoad, 400);
				

	
				break;
			case "tjd":
				content.slideUp();
				
				function TJDLoad()
				{
					content.load("sections.html #section_tjd", function(){
					hideLoading();
					
					$('#TJD').load('available.html #TJD_Info')
					$("a[rel='goldMedal']").colorbox({slideshow:false,current:""});
					$(".toolPop").tooltip({ effect: 'slide', opacity: 1, offset:[0,0] });
					})
				
					content.slideDown();	
				}
				
				
				setTimeout(TJDLoad, 400);
				
				break;
				
			case "contact":
				content.slideUp();
				function ContactLoad()
				{


				content.load("sections.html #section_contact", hideLoading);
				
				
				
				content.slideDown();
				}
				
				setTimeout(ContactLoad, 400);
				break;
			default:
				//hide loading bar if there is no selected section
				hideLoading();
				break;
		}
	});

	//show loading bar
	function showLoading(){
		loading
			.css({visibility:"visible"})
			.css({opacity:"1"})
			.css({display:"block"})
		;
	}
	//hide loading bar
	function hideLoading(){
		loading.fadeTo(800, 0);
	};
});
