var googleAnalytics = {

	fileDownloads : {

		/**

		 * @var string path google analytics special url

		 */

		path : '',

		/**

		 * starts the process

		 * @param string path google analytics special url

		 */

		init : function(path) {

			googleAnalytics.fileDownloads.path = path;

			$$('a').each(googleAnalytics.fileDownloads.filter);

		},

		/**

		 * identifies if this should attach the onclick event or not

		 * @param object e element preferibly an anchor with an href...

		 */

		filter : function(e) {

			var href = $(e).getProperty('href');

			if (!href) {

				return;

			}

			if (href.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {

				googleAnalytics.fileDownloads.attach(e);

			}

		},

		/**

		 * attaches the onclick event to the element

		 * @param object e element that is being tracked

		 */

		attach : function(e) {

			$(e).addEvent('click',googleAnalytics.fileDownloads.click);

		},

		/**

		 * event triggered when clicking the object

		 * @param event e event that was triggered (the element clicked is on 'this')

		 */

		click : function(e) {

			if (googleAnalytics.fileDownloads.path == '') {

				return;

			}

			var record = '/' + googleAnalytics.fileDownloads.path + '/' + $(this).getProperty('href');

			record = record.replace(/\/{2,}/,'/');

			googleAnalytics.track(e,record);

		}

	},

	externalLinks : {

		/**

		 * @var string path google analytics special url

		 */

		path : '',

		/**

		 * starts the process

		 * @param string path google analytics special url

		 */

		init : function(path) {

			googleAnalytics.externalLinks.path = path;

			$$('a').each(googleAnalytics.externalLinks.filter);

		},

		/**

		 * identifies if this should attach the onclick event or not

		 * @param object e element preferibly an anchor with an href...

		 */

		filter : function(e) {

			var href = $(e).getProperty('href');

			if (!href) {

				return;

			}

			if (!href.match(/^http\:\/\//i) && !href.match(/^https\:\/\//i)) {

				return;

			}

			var hostProtocol = window.location.protocol + '//' + window.location.host;

			var hrefHost = href.substring(0, hostProtocol.length);

			if (hrefHost.toLowerCase() == hostProtocol.toLowerCase()) {

				return;

			}

			googleAnalytics.externalLinks.attach(e);

		},

		/**

		 * attaches the onclick event to the element

		 * @param object e element that is being tracked

		 */

		attach : function(e) {

			$(e).addEvent('click',googleAnalytics.externalLinks.click);

		},

		/**

		 * event triggered when clicking the object

		 * @param event e event that was triggered (the element clicked is on 'this')

		 */

		click : function(e) {

			if (googleAnalytics.externalLinks.path == '') {

				return;

			}

			var record = '/' + googleAnalytics.externalLinks.path + '/' + $(this).getProperty('href');

			googleAnalytics.track(e,record);

		}

	},

	

	/**

	 * records something against google analytics (if analytics is available, of course).

	 * @param event e event that was triggered (the element clicked is on 'this')

	 * @param string record the path that should be recorded. It will be recorded as is

	 */

	track : function(e,record) {

//to debug

//e.stop();

//alert(record);

//return true;

		try {

			if (!pageTracker) {

				return;

			}

		} catch(e) {

			return;

		}

		pageTracker._trackPageview(record);

	}

}
