// JavaScript Document

if ("onhashchange" in window) { // event supported?
    window.onhashchange = function () {
        changeContentFromAnchor(window.location.hash);
    }
}
else { // event not supported:
    var storedHash = window.location.hash;
    window.setInterval(function () {
        if (window.location.hash != storedHash) {
            storedHash = window.location.hash;
            changeContentFromAnchor(storedHash);
        }
    }, 100);
}

function changeContentFromAnchor(anchorTo) {
	// Update display
	//document.getElementById("headtitle").style.opacity = 0;
	document.getElementById("headtitle").innerHTML = document.getElementById("loaderBox").innerHTML;
	document.getElementById("entries").innerHTML = "";
	//fade('entries');
	
	if (anchorTo == "") {
		anchorTo = "#news";
	}
	
	if (anchorTo.toString() != window.location.hash.toString()) {
		window.location.hash = anchorTo.toString();
	}
	
	var page = "";
	var opt = "?max=5";
	switch (anchorTo) {
		case "#news":
			page = "news.ext.php";
			break;
		
		case "#posts":
			page = "posts.ext.php";
			break;
		
		case "#tweets":
			page = "tweets.ext.php";
			opt = "?max=10";
			break;
		
		case "#videos":
			page = "videos.ext.php";
			break;
		
		case "#projects":
			page = "projects.ext.php";
			break;
	}
	
	/*
	if (clearCache) {
		opt = "&clearcache";
	}
	*/
	
	if (page != "") {
		ajaxpage("http://berenger.496.fr/sub/" + page + opt, "entries", "headtitle", "modelHeadTitle", "XXXXX");
	}
}
