$(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();
				content.load("index_sub.html #section_home", hideLoading);
				content.slideDown();
				break;
			case "vehicles":
				content.slideUp();
				content.load("vehicles.html #section_vehicles", hideLoading);
				content.slideDown();
				break;
			case "about":
				content.slideUp();
				content.load("about.html #section_about", hideLoading);
				content.slideDown();
				break;
	
			case "packages":
				content.slideUp();
				content.load("packages.html #section_packages", hideLoading);
				content.slideDown();
				break;
				
			case "photos":
				content.slideUp();
				content.load("photos.html #section_photos", hideLoading);
				content.slideDown();
				break;
	
			case "partners":
				/*
				content.slideUp();
				content.load("partners.html #section_partners", hideLoading);
				content.slideDown();
				*/
				window.location = 'partners_fullWindow.html';
				break;
				
			case "contact":
				content.slideUp();
				content.load("contact.html #section_contact", hideLoading);
				content.slideDown();
				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(1000, 0);
	};
	
	//TODO - check post var for page direction
	
	function checkPageVar(){
		var query = window.location.search;
		if (query.substring(0, 1) == '?') {
			query = query.substring(1);
		}
		
		switch(query){
			case "home":
				content.load("index_sub.html #section_home", hideLoading);
				break;
			case "vehicles":
				content.load("vehicles.html #section_vehicles", hideLoading);
				break;
			case "about":
				content.load("about.html #section_about", hideLoading);
				break;
			case "packages":
				content.load("packages.html #section_packages", hideLoading);
				break;
			case "photos":
				content.load("photos.html #section_photos", hideLoading);
				break;
			case "contact":
				content.load("contact.html #section_contact", hideLoading);
				break;
		}
	}
	
	checkPageVar();
});