if(typeof jQuery == 'function'){

	function gaLinkerClick() {
		this.href = pageTracker0._getLinkerUrl(this.href);
        //pageTracker0._link(this.href);
		//return false;
	}
	function gaLinkerSubmit() {
		pageTracker0._linkByPost(this);
	}
	function addNavigationOverlay(debug) {
		if (debug=='popup') {
			var popup = window.open("","window","");
			popup.document.write('<B>Navigation Overlay</B><BR/>');
		}

		trackedDomains = "*.wengo.fr *.wengo.es *.wengo.pt *.wengo.com *.wengomeeting.com *.wengophone.com *.wengovisio.com *.openwengo.org *.wengophone.fr *.openwengo.com *.astrofame.fr";

		// unbind all previous gaLinker events
		jQuery("a").unbind('click', gaLinkerClick);
		jQuery("form").unbind('submit', gaLinkerSubmit);

		// handle A:HREF links except div.popup nav links
		if (debug=='popup') popup.document.write("<U>Links</U><BR/>");
		jQuery("a:not(.open_intradiv_nohijack):not(.open_intradiv):not(.intradiv_nav)").each(
			function() {
				var u = jQuery(this).attr('href');
				if (needsLinker(trackedDomains, u?u:'')) {
					if (debug=='popup') popup.document.write(jQuery(this).html()+' - <SPAN style="color:#FF0000;font-weight: bold;">'+u+'</SPAN><BR/>');
					if (debug=='console') console.log('****** A - '+u);
					jQuery(this).bind('click',gaLinkerClick);
				} else {
					if (debug=='popup') popup.document.write(jQuery(this).html()+' - <SPAN>'+u+'</SPAN><BR/>');
					if (debug=='console') console.log('A - '+u);
				}
			}
		);

		// handle FORM:ACTION links except div.popup nav forms
		if (debug=='popup') popup.document.write("<BR/><BR/><BR/><BR/><U>Hijacked Submits</U><BR/>");
		jQuery("form:not(.submit_intradiv_post)").each(
			function() {
				var u = jQuery(this).attr('action');
				//console.log(u);
				if (needsLinker(trackedDomains, u?u:'')) {
					if (debug=='popup') popup.document.write('<BR/>'+jQuery(this).html()+' - <SPAN style="color:#FF0000;font-weight:bold;">'+u+'</SPAN><BR/>');
					if (debug=='popup') popup.document.write('<HR/>');
					if (debug=='console') console.log('****** FORM - '+u);
					jQuery(this).bind('submit',gaLinkerSubmit);
				} else {
					if (debug=='popup') popup.document.write('<BR/>'+jQuery(this).html()+' - <SPAN>'+u+'</SPAN><BR/>');
					if (debug=='popup') popup.document.write('<HR/>');
					if (debug=='console') console.log('FORM - '+u);
				}
			}
		);
	
		if (debug=='popup') popup.document.close();
	}

  function extractRealDomain(d) {
    if (d == null) return '';
    var dp = d.split('.');
    if (dp[dp.length-1] == 'localdev-2' || (dp[dp.length-1] == 'com' && dp[dp.length-2] == 'geekic')) {
      dp = dp.slice(0, dp.length-2);
    }
    return dp.join('.');
  }

	function needsLinker(tracked, u) {
		// avoid basic cases
		if ( u.indexOf('mailto:') == 0 ) return false;
		if ( u.indexOf('javascript:') == 0 ) return false;
		if ( u.indexOf('http://') == 0 || u.indexOf('https://')==0) {
			var regex_uparts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?");
			var uparts1 = regex_uparts.exec(u);
			if (uparts1 == null) return false;
			var lparts1 = regex_uparts.exec(location.href);

			//var regex = /^([^\/\.]*\.([^\/\.]*\.[^\/\.]*)[^\/\?]*)/i;
			if (uparts1[3] == lparts1[3]) return false;
			
			var regex = new RegExp("([^.]*.[^.]*)$");
			uparts = regex.exec(extractRealDomain(uparts1[3]));

			if (uparts == null) return false;
			lparts = regex.exec(extractRealDomain(lparts1[3]));
			//if (uparts[1] == lparts[1]) return false;
			if (tracked.indexOf('*.'+uparts[1]) != -1) {
				return true;
			}
			return false;
		
		}
		return false;
	}


	addNavigationOverlay('');

}
