// expects  default.css and mootools.js to be loaded
function assertThisBrowserWorks(fontName) {
  var div = document.createElement('div');
  var different = false;

  div.innerHTML = '<span style="font-family: sans-serif">Any Text</span>' +
                  '<span style="font-family: monospace">Any Text</span>';

  document.body.insertBefore(div, document.body.firstChild);

  different = div.childNodes[0].offsetWidth != div.childNodes[1].offsetWidth;

  document.body.removeChild(div);

  return different;
}


function isInstalled(name) {
  if (!assertThisBrowserWorks(name)) {
    //alert("assumption failed");
    return false;
  }

  var body = document.body;
  var testDiv = document.createElement('div');
  var installed = false;
  var template =
            '<span id="testSpan1" style="display:inline !important; width:auto !important; font:normal 10px/1 \'' + name + '\',sans-serif !important">ii</span>'+
            '<span id="testSpan2" style="display:inline !important; width:auto !important; font:normal 10px/1 \'' + name + '\',monospace  !important">ii</span>';

  testDiv.innerHTML = template;

  testDiv.style.cssText = 'position: absolute; display: block !important';

  body.insertBefore(testDiv, body.firstChild);

  installed = areSameWidth("testSpan1", "testSpan2"); 
  body.removeChild(testDiv);
  return installed;
}

function areSameWidth(elementId1, elementId2) { 
  return document.getElementById(elementId1).offsetWidth == document.getElementById(elementId2).offsetWidth;
}

window.addEvent('domready', function() {
  var documentBody = document.getElementsByTagName("BODY")[0];

  var footerDiv = document.createElement("DIV");
  var sig = document.createElement("DIV");
  var w3c = document.createElement("DIV");

  sig.id = "sig";
  sig.style.clear="both";
  sig.style.cssFloat="right";
  sig.width="30%";

  var meInEgytpian = "&#xF3733;&#xF3B9D; &#xF3f17;&#xF457b;&#xF3EF1;";
  if (isInstalled("Aegyptus")) {
    sig.style.fontFamily = "Aegyptus";
    sig.title="Tim Pizey (Tm Psy)";
    sig.innerHTML = "&copy " + meInEgytpian;
  } else { 
    sig.innerHTML="&copy; Tim Pizey";
  }
  footerDiv.appendChild(sig);
	
  w3c.id = "w3c";
  w3c.innerHTML = "<a href='http://validator.w3.org/check?uri=referer' style='text-decoration:none;'>xhtml1</a> " + 
                  "<a href='http://jigsaw.w3.org/css-validator/check/referer?profile=css3' style='text-decoration:none;'>css3</a>";
  w3c.style.cssFloat="left";
  w3c.style.textDecoration="none";
	
  footerDiv.appendChild(w3c);
  documentBody.appendChild(footerDiv);

  $$('a').each(function(e1) { 
      e1.addEvent('click', function(e) {
        e1.tween('background-color', '#fff', '#c40');
       });
      e1.addEvent('mouseenter', function(in1) {
        e1.tween('background-color', '#fff', '#fcc');
       });
      e1.addEvent('mouseleave', function(out1) {
        e1.tween('background-color', '#fcc', '#fff');
       });
  });
});

window.addEvent('load', function() {
  var meInEgytpian = "&copy; &#xF3733;&#xF3B9D; &#xF3f17;&#xF3EF1;";
  if (isInstalled("Aegyptus")) {
    var sig = document.getElementById("sig");
    sig.innerHTML = meInEgytpian;
  } else {
    sig.innerHTML = "&copy; Tim Pizey"; 
  }
});

