function onloader() {
     initialiseStateFromURL();
	if (document.getElementById("text_ingelogd_huidig").className == "new_page_loaded" && document.getElementById("text_ingelogd_override") != "new_page_verzonden"){
		authIngelogd();
	}

    setInterval(initialiseStateFromURL, 13000);
    setInterval(intitialiseStatFromURLingelogd, 5000);
}

 
function initialiseStateFromURL() {
	var initialTab = window.location.hash;
 	var hashstring = window.location.hash.substring(1);
 	
 	if(hashstring == "") {
 		window.location.hash = "home";
 		hashstring = "home";
 		
 	}
 	
 	getPage(hashstring);	
}

function intitialiseStatFromURLingelogd() {
	if (document.getElementById("text_ingelogd_override").className == "new_page_verzonden") {
		document.getElementById("text_ingelogd_huidig").className = "status";
		document.getElementById("text_ingelogd_override").className = "";
	}
	
	if (document.getElementById("text_ingelogd_huidig").className != "new_page_loaded"){
		authIngelogd();
	}
}

function getPage(str)
{
if (str=="")
  {
  document.getElementById("text_empty").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("text_empty").innerHTML=xmlhttp.responseText;
		/*$("#text_empty img").each(function(){
 			  	var source = $(this).attr('src') || '', alttext = $(this).attr('alt') || '';
		     $(this).wrap('<a href="'+source+'" title="'+alttext+'" class="l>');
		    	
			});*/
		
		//$("#text_empty img").parent().lightBox();
		$("a:has(img)").fancybox();
		
		$(".popup").fancybox({
			'width' : '80%',
			'height' : '80%',
			'type' : 'iframe'
		});
		
	 }
  }
xmlhttp.open("GET","php/test.php?q="+str,true);
xmlhttp.send();

window.location.hash = str;
}


function authIngelogd() {
	$.post("php/auth.php", { waarde: "1"},
   function(data){
   	if (data == "fout") {
     	$(".login_container").fadeTo("fast", 1.0);
     	$(".login").fadeTo("slow", 1.0);
     	$(".ingelogd_container").fadeTo("fast", 0);
     }
     if (data == "goed") {
     	$(".login_container").fadeTo("fast", 0);
     	$(".error_login").fadeTo("fast", 0);
     	$(".ingelogd_container").fadeTo("slow", 1.0);
     	$(".login").fadeTo("fast", 0);
		 var ingelogdPage = document.getElementById("text_ingelogd_huidig").className;
			
			$('#text_empty_ingelogd').load('php/ingelogd.php?p='+ingelogdPage);
		
     } else {
      	$(".login_container").fadeTo("fast", 1.0);
     	$(".ingelogd_container").fadeTo("fast", 0);    	
     	$(".login").fadeTo("slow", 1.0);
     }
   });

}

function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}

