function convertFootnotes(contID,noteID)
{
	var cont = document.getElementById(contID);
	var noteholder = document.getElementById(noteID);
	var spans = cont.getElementsByTagName("span");
	var notes = 0;
	var fnlocator = new PageLocator("window.location.href", "#");
	var hash_exl = fnlocator.getHash().substr(0, fnlocator.getHash().indexOf("&hash="));
	if(hash_exl==null || hash_exl=='' || hash_exl==' '){
		hash_exl = fnlocator.getHash();
	}
	//alert(hash_exl);
	
	for (i=0;i<spans.length;i++)
	{
		if (spans[i].className == "footnote")
		{
			notes++;
			/*
			noteholder.innerHTML += "<div class='footnote'><a name='note"+notes+"'></a>" + notes + ". " + spans[i].innerHTML + " <a href='#nlink"+notes+"' title='return to text'>&#8617;</a></div>";
			spans[i].innerHTML = "<a name='nlink"+notes+"' href='#note" + notes + "' title='view footnote' class='footnote'>" + notes + "</a>";
			*/
			noteholder.innerHTML += "<div class='footnote'><a name='note"+notes+"'></a>" + notes + ". " + spans[i].innerHTML + " <a href='"+ hash_exl +"/#nlink"+notes+"' onclick=\"setAddressURL('"+ hash_exl +"&hash=nlink"+notes + "'); return false;\" title='return to text'><br />naar positie in tekst »</a></div><br />";
			spans[i].innerHTML = "<sup><a name='nlink"+notes+"' href='"+ hash_exl +"/#note" + notes + "' onclick=\"setAddressURL('"+ hash_exl +"&hash=note"+notes + "'); return false;\" title='view footnote' class='footnote'>" + notes + "</a></sup>";
		}
	}
	
	// hide button
	document.getElementById("btn").style.display = 'none';
	
}
/* PAGELOCATOR */
function PageLocator(propertyToUse, dividingCharacter) {
	this.propertyToUse = propertyToUse;
	this.defaultQS = 1;
	this.dividingCharacter = dividingCharacter;
}
PageLocator.prototype.getLocation = function() {
	return eval(this.propertyToUse);
}
PageLocator.prototype.getHash = function() {
	var url = this.getLocation();
	if(url.indexOf(this.dividingCharacter)>-1) {
		var url_elements = url.split(this.dividingCharacter);
		return url_elements[url_elements.length-1];
	} else {
		return this.defaultQS;
	}
}
PageLocator.prototype.getHref = function() {
	var url = this.getLocation();
	var url_elements = url.split(this.dividingCharacter)
	return url_elements[0];
}

/* AjaxUrlFixer */
function AjaxUrlFixer() {
	//alert(window.location.href);
	
		this.hashlocator = new PageLocator("window.location.href", "#");
		this.questlocator = new PageLocator("window.location.href", "?");
		this.timer = new Timer(this);
		this.checkWhetherChanged(0);	
	
	
	
	
}
AjaxUrlFixer.prototype.checkWhetherChanged = function(location){
	this.timer.setTimeout("checkWhetherChanged", 200, this.hashlocator.getHash());
	if(this.hashlocator.getHash() != location) {
		this.callAjaxInclude();
	}else{
		//if(window.location.href == "http://127.0.0.1/esthetica/index_beta.php"||window.location.href == "http://127.0.0.1/esthetica/index_beta.php#"){
		if(window.location.href == "http://esthetica.nge.nl/"||window.location.href == "http://esthetica.nge.nl/index.php" ){
		//alert(window.location.href);
		//window.location = "http://127.0.0.1/esthetica/index_beta.php#/home/";
		setAddressURL("/home/");
		}
	}
}
AjaxUrlFixer.prototype.callAjaxInclude = function(){
		
		var from_hash = this.hashlocator.getHash();
		var pd = from_hash.split("/");
		
		var page = pd[1]+".php";
		
		var query = this.questlocator.getHash();
		//
		var include= '';
		if( query != '' && query != 1){
			include = page+"?"+query	
		}else{
			if(from_hash == ''|| from_hash == ' '|| from_hash == 1 || from_hash == '/' || !from_hash){
				page = 'home.php';
			}
			include = page;	
		}
		ajaxinclude(include);
}
/*PAGE include function*/
function ajaxinclude(url) {
	
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
		}
	}
	else
	return false
	page_request.open('GET', "website/pagemodules/"+url, false) //get page synchronously 
	page_request.send(null)
	writecontent(page_request, getQSvars(url))
}
function getQSvars(qs){
	var si = qs.indexOf("?");
	var key_data = new Array();
	if(si>0){
		var keys = qs.substring(si+1, qs.length).split("&");
		for(i=0; i<keys.length; i++){
			var store = keys[i].split("=");
			key_data.push(store);
		}	
	}
	return key_data;
}
function writecontent(page_request, keys){	
	if (page_request.readyState == 4){
		if ( page_request.status==200){
			document.getElementById('pagecontent').innerHTML = page_request.responseText;
			
			if(keys.length>0){
				if(keys.length>1 ){
					showSubNav(keys[0][1], keys[1][1]);
					
					convertFootnotes('pages','footnotes');
					var hash_data = keys[keys.length-1];
					
					if(hash_data[0]=="hash"){
						//alert(hash_data[1]);
						var links = document.getElementsByTagName("A");
						
						for(var i=0; i<links.length; i++) {						
							var fn_name = links[i].getAttribute("name");
							if(fn_name == hash_data[1]){
								
								var d = findPos(links[i]);
								window.scrollTo(d[0], d[1]);
							}
						}
					}
				}else{
					showSubNav(keys[0][1], 0);
				}
			}
			
			var loader = document.getElementById('loader');
			loader.innerHTML = "";
		}	
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function hideSubNav(h){
	if (h) {
		h.style.display='none';
	}
}
function showSubNav(menu, id) {
	//alert(menu);
	var menu = document.getElementById(menu);
	var nodes = menu.getElementsByTagName("dd");
	for (var i = 0; i<nodes.length; i++) {
		hideSubNav(nodes[i]);
	}
	var s = nodes[id];
	if (s) {
		s.style.display='block';
	}	
}
function changeClass(element, newClass) {
	identity=element;
	identity.className=newClass;
}
//-----------------------------------------
function addFlash(la_date){
    var so = new SWFObject("website/flashmenu/menu_v5.swf?la_date="+la_date, "menu_v5", "830", "200", "8", "#B1B09A");
    so.useExpressInstall('website/flashmenu/swfobject/expressinstall.swf');
	so.addParam('allowScriptAccess', 'always');
    so.addParam('menu', 'false');
   	so.write("flashcontent");
}
/*
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function formSend(data) {
	getFlashMovie("menu_v5").sendTextToFlash(data);
}*/

function composeTitle(val) {
	
	var pagenames = Array("/lopende-jaargang/", "/nieuws/", "/archief/", "/search/");
	var pagelabels = Array("Lopende jaargang", "Nieuws", "Archief", "Search");
	
	for (var i in pagenames) { 
		if (pagenames[i] === val){
			return "Esthetica / "+pagelabels[i];
		}
	}
	return -1;	
}
function setAddressURL(val){
	var xPos = (screen.width/2)-125;
	var yPos = (screen.height/2)-180;
	if(val!= SWFAddress.getValue()){
		var loader = document.getElementById('loader');
		loader.innerHTML = "<div style=\"background-color:#FFFFFF; opacity:0.8; padding:30px; border:1px solid #000000; font-size:10px; font-weight:bold; text-align:center; width:250px; position:fixed; left:"+xPos+"; top:"+yPos+";\">Het artikel wordt geladen.<br/>Een moment geduld a.u.b.</div>";
	}
	var page = composeTitle(SWFAddress.getPath());
	SWFAddress.setValue(val);
	SWFAddress.setTitle(page);
}
function onPageLoaded(la_date){
	addFlash(la_date);
	FixBackAndBookmarking();
}
function FixBackAndBookmarking() {
	fix = new AjaxUrlFixer();
}