$.ajaxSetup({
	// Disable caching of AJAX responses */
	cache: false
});

function removeFilter(el) {
	try {
		el.style.removeAttribute('filter'); 
	}
	catch(err){
	}
};

$(document).ready(function(){	
	/*
	var items = parseUri(document.location.href);	
	var fontFamily = items.queryKey.font
	switch (fontFamily) {
		case 'Times':
			$('body').css('font-family', 'Times');
			break
		case 'Arial':
			$('body').css('font-family', 'Arial');
			$('body').css('font-size', '14px');
			break;
	}
	*/
	
	$("#logo").click(function(){
		$(".menu > li > ul:visible").hide(400);
		$("li").removeClass('selected');
		showPage("pages/first-page.html");
	});
	
	$(".menuItem").click(function(){
		
		if ( $(this).find('+ul').is(':visible') ) {
			//$(".menu").addClass('animating');
			//$(this).find('+ul').hide(400, function(){
			//	$(".menu").removeClass('animating')		
			//});
			return;
		}
		
		$(".menu").addClass('animating');
		$(".menu > li > ul:visible").hide(400);
		var label = $.trim($(this).text());
		$(this).find('+ul').show(400, function(){
			removeFilter(this); // for ie
			$(".menu").removeClass('animating')			
			switch (label) {
				case "Attention Dynamics":
					$(".subMenu > li:contains(About)").click();
					break;
				case "Academics":
					$(".subMenu > li:contains(Theoretical Work)").click();
					break;
			}
		});
	});

	$("li").click(function(){
		if ($(this).find('.menuItem').length){
			//alert($(this).text());
			return true;
		}
		$("li").removeClass('selected');
		$(this).addClass('selected');
	
		var label = $.trim($(this).text());
		switch (label){
			case "About":
				showPage("pages/about-attention-dynamics.html");
				break;

			case "Workshops":
				showPage("pages/attention-dynamics-workshops.html");
				break;
				
			case "Editorial Work":
				showPage("pages/editorial-work.html");
				break;
				
			case "Academic Publications":
				showPage("pages/academic-publications.html");
				break;
				
			case "Theoretical Work":
				showPage("pages/academics-theoretical-work.html");
				break;
				
			case "Curriculum Vitae":
				showPage("pages/glenn-hartelius-academic-resume.html");
				break;
							
			case "About Glenn Hartelius, Ph.D.":
				$(".menu > li > ul:visible").hide(400);
				showPage("pages/about-glenn-hartelius.html");
				break;
				
			case "Contact":
				$(".menu > li > ul:visible").hide(400);
				showPage("pages/contact.html");
				break;

		}
	});
	
	showPage("pages/first-page.html");

});

function showPage(url){
	$("#contentBox").empty();
	var scrollPane = $("<div/>").addClass("scrollPane").appendTo($("#contentBox"));
	scrollPane.load(url, function(){
		scrollPane.jScrollPane({
			scrollbarWidth: 21,
			scrollbarMargin: 20,
			reinitialiseOnImageLoad: true
		});
	});
}