if (typeof MooTools == 'object') {

	/**
	 * Replaces the tt_news back link with history.back() and changes the according link text
	 */
	function replaceNewsBackLink(){
		$$('.tx_ttnews-newsbacklink a').each(function(el){
			el.setProperty('href', 'javascript:history.back();');
			myText = el.getText();
			if (myText && myText.indexOf(String.fromCharCode(32)) > 0) {
				el.setText(myText.substring(0, myText.indexOf(String.fromCharCode(32))));
			}
		});
	}

		/**
		 * Adds the google analytics tracking code to all download links
		 */
		function addGaDownloadTracking() {
			$$('.tx_ttnews_downloads-filelink a').each(function(el){
				el.addEvent('click', function(){
					pageTracker._trackPageview('/download_files/' + escape(el.getText()));
				});
			});
		}
		
		/**
		 * Adds the google analytics tracking code to all outgoing links
		 */
		function addExternalPageTracking(){
			$$('a').each(function(el){
				var href = el.getProperty('href');
				
				if (href && (href.match(/^http/)) && (!href.match(document.domain)) && (!href.match(/http:\/\/www.health-and-beauty.com\/(ads|phpmv2)\//))) {
					el.addEvent('click', function(){
						href = escape(href.replace('http://', ''));
						pageTracker._trackPageview('/external/' + href);
					});
				}
			});
		}
		
		/**
		 * Searches for the registrationforms or the thankyou page and then tracks the state of the
		 * registration process in google analytics
		 */
		function trackRegistrationProcess() {
			if ($$('.registrationform').length > 0) {
				pageTracker._trackPageview('/registration_start/' + document.title);
			} else if ($$('.previewform').length > 0) {
				pageTracker._trackPageview('/registration_preview/' + document.title);
			} else if ($defined($('thankyou'))) {
				pageTracker._trackPageview('/registration_thankyou/' + document.title);
			}
		}
		
		/**
		 * Tracks clicks on each lightbox image with google analytics
		 */
		function trackLightboxClick(){
			$each(document.links, function(el){
				if (el.rel && el.rel.test(/^lightbox/i)) {
					var href = el.href;
					href = escape(href.replace('http://' + document.domain + '/', ''));
					el.addEvent('click', function(){
						pageTracker._trackPageview('/lightbox/' + href);
					});
				}
			});
		}
	if (typeof load_method != 'string') {
		load_method = window.ie ? 'load' : 'domready';
	}
	
	window.addEvent(load_method, function(){
		try {
			replaceNewsBackLink();
			if (typeof pageTracker != 'undefined') {
				trackLightboxClick();
				trackRegistrationProcess();
				addExternalPageTracking();
				addGaDownloadTracking();
			}
		} catch (e) {}
	});
}