
  /* The first thing we need in our code is a function that will call the Google Analytics function on the DOM event of page load. There are lots of references out on the web detailing scripts which allow multiple onLoad functions to be called, and I believe that the one used here is based on Simon Willisons addLoadEvent script. This script is a function that that you can call, to in turn call other functions on page load: */

	/* Simplifies onload, you will no longer have to add an onload event call just call addLoadEvent */
	function addLoadEvent(func,arg) {
	
		if (!arg) {
		  var oldonload = window.onload;
		  if (typeof window.onload != 'function') {
		    window.onload = func;
		  } else {
		    window.onload = function() {
		      oldonload();
		      func();
		    }
			}
		} else { /*if the onload event has an argument/parameter cater for that*/
		  if (arg) {

		  	oldonload = window.onload;
		  	if (typeof window.onload != 'function') {
		    	window.onload = func(arg);
		  	}
		    window.onload = function() {
		    	oldonload();
		    	func(arg);
		    }

		  }

		}
		
	}
	
	/* Now we have a function which can call our analytics function on load we just need to convert the javascript to make it a littel less obtrusive. The more tricly bit involves loading the external js file which I mentioned earlier in part one. For this we create a function which appends the script to the head of the document. This script is called immediately */
	
	function loadGAScript(){
    /*Check browser for Dom compatibility*/
		if (!document.getElementsByTagName) return false;
			/*Determines whether the page is using a secure or unsecure protocol*/
			var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
			/*Writes in the script to the document head*/
			var gaScript = document.createElement("script");
			gaScript.setAttribute("src",gaJsHost +"google-analytics.com/ga.js");
			gaScript.setAttribute("type","text/javascript");
			var domHead = document.getElementsByTagName("head")[0]
			domHead.appendChild(gaScript);
  }

  loadGAScript();
	
	/*Calls the analytics function*/
	function callGA(){
		try {
		    var pageTracker = _gat._getTracker("UA-9002604-1");
			pageTracker._trackPageview();
		} catch (err) {}
	}
		
	addLoadEvent(callGA);