/**	gatrack.js */
/**
 *	v 1.0.1
 *	ref: http://davidwalsh.name/mootools-google-analytics-track-outbound-links
 *	api: http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
 */


if ( Math.round(window.MooTools.version.substr(0, 3)*10)/10 > 1.1 )
window.addEvent('load', function() {
	
	
	if (typeof _gaq != 'undefined') {
		gatrack('a[href^=http]', "Outgoing");
	}
		
	function gatrack (elements, path, onsite) {
		if (typeof elements == 'undefined') return;
		if (typeof path == 'undefined') var path = '/outgoing/';
		if (typeof onsite == 'undefined') var onsite = false;
		
		
		document.getElements(elements).each(function(el) {
			// build elements array
			if (onsite) {
				if (el.host != window.location.host) {
					el2 = el;
				}
			} else {
				el2 = el;
			};
			
			// el2.store('label', el2.get('href').replace('http://', ""));
			
			// assign event
			el2.addEvent('click', function() {
				// 	pageTracker._trackPageview(path + el2.get('href').replace('http://', ""););
				// pageTracker._trackEvent(path, "Open", 'Link', el2.get('href').replace('http://', ""));
				_gaq.push(['_trackEvent', path, "Open", el.get('href').replace('http://', "")]);
				// 			_trackEvent / category / "action" / "opt_label" / "opt_value" (integer)
				// ref: http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
				
			}.bind(this));
			
			// set properties
			el2.set({
				// title: "GA track",
				target: "_blank"
			});

		});
	};
	
});
