var current = false;
var working = false;
function checkForUrlChange() {
	urlChanged();
	window.setTimeout(checkForUrlChange, 1000);
}
function urlChanged() {
	var hash = new String(document.location).indexOf("#");
	if(hash > 0) {
		var page = new String(document.location).substring(hash + 1);
		if(page.length <= 0) {
			fadeTo(false);
		} else {
			fadeTo("#" + page);
		}	
	} else {
		fadeTo(false);
	}
}
function fadeTo(name) {
	if(working) {
		return;
	}
	if(current == name) {
		return;
	}
	var base_location = location.href.split('#')[0];
	if(name) {
		location.href = base_location + name;
	} else {
		location.href = base_location + '#';
	}
	if(current) {
		working = true;
		$(current).fadeOut('slow', function() {
			if(name) {
				$(name).fadeIn('slow');
			}
			current = name;
			working = false;
		});
	} else {
		working = true;
		$(name).fadeIn('slow', function() {
			current = name;
			working = false;
			});
	}
}
$(document).ready(function() {
	$("#projects-menu ul li a").removeAttr('href');
	$("#projects div").removeAttr('name');
	$("#projects div").hide();
	checkForUrlChange();
});
