	
	function changeContent(url) {
		var	$menu = $('#nav'),
			activeClass = 'current',
			activeSelector = '.current',
			menuChildrenSelector = 'a',
			$menuChildren;
			

			$.ajax({
				url: "getContents.php?url=" + url,
				success: function (responseText) {
					$("#content").hide().html(responseText).fadeIn('slow');
				}
			});

		
		$.ajax({
	        url: "getTitle.php?url=" + url,
	        success: function (responseText) {
				var newtitle = (responseText);
	            document.title = newtitle;
	        }
	    });
		
		$menuChildren = $menu.find(menuChildrenSelector);
		$menuChildren.filter(activeSelector).removeClass(activeClass);
		$('a[href = "'+ url +'"]').addClass(activeClass);
	}
		
	$(document).ajaxComplete(function (event, request, settings) {
		if (settings.url == 'getContents.php?url=photos.html') {
			$("a[rel=example_group]").fancybox({
				'overlayShow': false,
				'cyclic': true,
				'transitionIn': 'elastic',
				'transitionOut': 'elastic'
			});
		}
	});
	
	$(document).ajaxComplete(function (event, request, settings) {
		if (settings.url == 'getContents.php?url=contact.html') {
			nameFocus();
		}
	});

	$(document).ready(function () {
	
		var $this = $(this);
		$this.find('#nav a').click(function (event) {
			var $this = $(this)
			var url = $this.attr("href");
			if (event.which == 2 || event.metaKey) {
				return true;
			}
			// Ajaxify this link
			changeContent(url);
			history.pushState(null, null, url);
			event.preventDefault();
			return false;
		});

		
		window.onpopstate = function (e) {
			if(window.location.hash){
				hash = window.location.hash;
				url = hash.replace('#-','')
				changeContent(url);
			} else {
				var pathArray = window.location.pathname.split('/');
				var n = pathArray.length;
				if (pathArray[n - 1]) {
					changeContent(pathArray[n - 1]);
				} else {
					changeContent('index.html');
				}
			}
		}

	});

