// JavaScript Document
var viewportwidth;
var viewportheight;
 
function getViewPortDimensions() {
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 	if (typeof window.innerWidth != 'undefined') {
    	viewportwidth = window.innerWidth,
    	viewportheight = window.innerHeight
	}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 	}
 
 	// older versions of IE
 	else {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
}

function setMargin() {
	if(!document.getElementById('container')) {return false;}
	var div = document.getElementById('container');
	div.style.marginTop = (viewportheight - 462) / 2 + 'px';
}

function setLink() {
	if(!document.getElementById('alink')) {return false;}
	var atag = document.getElementById('alink');
	var name = "alex";
	var server = "baseten.co.uk";
	atag.href = "mailto:" + name + "@" + server;
	
	atag.onfocus = function () {
		if(this.blur())this.blur();
	}
}

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", initDOM, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      initDOM(); // call the onload handler
    }
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      initDOM(); // call the onload handler
    }
  }, 10);
}

function initDOM() {
	// quit if this function has already been called
  	if (arguments.callee.done) return;

  	// flag this function so we don't do the same thing twice
  	arguments.callee.done = true;

  	// kill the timer
  	if (_timer) clearInterval(_timer);
	
	getViewPortDimensions();
	setMargin();
	setLink();
}

/* for other browsers */
window.onload = initDOM;

window.onresize = function () {
	getViewPortDimensions()
	setMargin();
}