/*
-----------------------------------------------
Daniel Bulli
http://www.nuff-respec.com/technology/google-track-outbound-links-automatically

This is dependent on mootools, but can be re-written not to use it

history:
03-04-08	dbulli	host test versus http test based on 
					remy's advice (http://remysharp.com/)
					
----------------------------------------------- */


function google_track_links()
{
	//no tracker then quite
	if(!pageTracker) return;

	var host = window.location.host.toString();
	
	//alert(host);
	
	//go thru each link
	$$('a').each(function(el)
	{
		//if rel tag is google
		if(el.rel && el.rel.test(/^google/i))
		{
			el.addEvent('click',function()
			{
				var track_id = this.rel.match(/^google\[(.*)\]$/);
				if(track_id)
				{
					//console.log('tracked: '+track_id[1]);
					pageTracker._trackPageview(track_id[1]);
				}

			});
		}
		else if(null == el.href.match(/insiderjob\.co\.uk/))	
		{
			//console.log(el.href);
			if (el.title != ""){
				el.title = el.title + " - link opens in a new window";
			}else{
				el.title = "link opens in a new window";
			}
			el.addEvent('click',function(event)
			{
				
				var track_id = this.href.match(/^http:\/\/(.*)/);
				if(track_id)
				{
					//console.log('tracked: outgoing/'+track_id[1]);
					pageTracker._trackPageview('outgoing/'+el.href);
					var e = new Event(event);
					e.stop();
					
					window.open(this.href);
				}

			});
		}
	});
}

window.addEvent('domready', function() {
	google_track_links();
});