
// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
	bubbling = bubbling || false;

	if(window.addEventListener)    { // Standard
			element.addEventListener(type, expression, bubbling);
			return true;
	} else if(window.attachEvent) { // IE
			element.attachEvent('on' + type, expression);
			return true;
	} else return false;
}

//This is what i want to do whenever someone clicks on the page
function itHappened(evt)
{

	//Get the clicket element
	var tg = (window.event) ? evt.srcElement : evt.target;
	//If it is an A element
	if(tg.nodeName == 'A'){
	//And it is not an internal link
		if(tg.href.indexOf(location.host) == -1){
			var staturl = tg.href;
			//Replace not needed http://
			staturl = staturl.replace(/http\:\/\//, "");
			//Replace all odd characters, so that it works with Analytics Navigation analysis
			staturl = staturl.replace(/[^a-z|A-Z]/g, "_");			
			
			var str = '/outgoing/' + staturl;
	
			try		{
			//Track it
			gaTracker._trackPageview(str);
			}
	
			catch(err){
			//alert('error: ' + err);
			}
		}
	}
}

//Add the click listener to the document
addListener(document, 'click', itHappened);
