// Preload some images
if(document.images) {
  var img1 = new Image(); 
  img1.src="./img/bgJournalistiek.gif"; 
  var img2 = new Image(); 
  img2.src="./img/bgEindredactie.gif"; 
  var img3 = new Image(); 
  img3.src="./img/bgGames.gif"; 
  var img4 = new Image(); 
  img4.src="./img/bgOverig.gif"; 
  var img5 = new Image(); 
  img5.src="./img/bgBio.gif"; 
  var img6 = new Image(); 
  img6.src="./img/bgContact.gif";
}

// Got the AJAX code from http://www.w3schools.com/ajax/ajax_browsers.asp
function getXMLHtppRequestObject() {
  var xmlHttp;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e) {
    // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
	alert("Your browser does not support AJAX!");
	return false;
      }
    }
  }
  return xmlHttp;
}

function showContent(sFile) {
  var ajaxDiv = document.getElementById('content');

  if( sFile == 'empty') {
    ajaxDiv.innerHTML = '';
    ajaxDiv.className = 'content';
  }
  else {
    // AJAX part
    var xmlHttp = getXMLHtppRequestObject();

    var sFileName = "./pages/" + sFile + ".html";

    // (Re)define the onreadystatechange function
    // We have to do this everytime because the message changes every time
    xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 0 ) {
	ajaxDiv.innerHTML = "The request is not initialized";
      }
      if(xmlHttp.readyState == 1) {
	ajaxDiv.innerHTML = "Loading...";
      }
      if( xmlHttp.readyState == 2) {
	ajaxDiv.innerHTML = "The request has been sent";
      }
      if( xmlHttp.readyState == 3) {
	ajaxDiv.innerHTML = "The request is in process";
      }
      if(xmlHttp.readyState == 4) {
	ajaxDiv.innerHTML = xmlHttp.responseText;
	ajaxDiv.className = 'content_';
      }
    }

    xmlHttp.open("GET", sFileName, true);
	
    // The null is essential to Firefox, which will otherwise never return...
    xmlHttp.send(null);
  }
}

function emailMe() {
  // Moeilijk gedoe om spammers dwars te zitten...
  var sFlut = "ilto:miranda@mir";
  document.location = 'ma' + sFlut + 'andawrites.nl';
}
