// Tracking code customizations only

jQuery.noConflict();

var url = window.location.host;  			// http://xxxxx.eolts.encoretix.co.uk
url = url.replace("http://", "");   		// xxxxx.eolts.encoretix.co.uk
var urlExplode = url.split(".");        	// split . into an array
var serverName = urlExplode[0];  			// xxxxx
url = url.replace(urlExplode[0]+".", "");  	// eolts.deviant.encoretix.co.uk

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23404135-1']);
if(document.URL.indexOf("encoretix")>0) {
	_gaq.push(['_setDomainName', '.'+url]);
}else{
	_gaq.push(['_setDomainName', '.eolts.co.uk']);
}
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);
_gaq.push(['_trackPageview']);

/* Real Version */
(function() {
	var ga = document.createElement('script');
	ga.type = 'text/javascript';
	ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl'
			: 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(ga, s);
})();

/* Debug Version */
/*
 * (function() { var ga = document.createElement('script'); ga.type =
 * 'text/javascript'; ga.async = true; ga.src = ('https:' ==
 * document.location.protocol ? 'https://ssl' : 'http://www') +
 * '.google-analytics.com/u/ga_debug.js'; var s =
 * document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 * })();
 */

var replaceLinks = function() {
	/*
	 * var prot = document.location.protocol;
	 * 
	 * if ('https:' == prot ) { return; }
	 */
	jQuery('a').each(function() {

		/*
		 * var newprot = this.href.substr(0, 5);
		 * 
		 * if ( newprot != 'https') { return; }
		 */
		var mydomain = new RegExp(document.domain, 'i');
		var myprotocol = new RegExp(location.protocol, 'i');
		
		if (!mydomain.test(this.href)||!myprotocol.test(this.href)) {
			jQuery(this).click(function() {
				//alert("link clicked to: " + this.href);
				_gaq.push( [ '_link', this.href ]);
				return false;
			});
		}
	});
}

var replaceForms = function() { 
	jQuery('form').each(function() { 
		var mydomain = new RegExp(document.domain, 'i'); 
		if (!mydomain.test(this.action)) {
			jQuery(this).submit(function() { 
				//alert("form submitted to: " + this.action); 
				_gaq.push( [ '_linkByPost', this ]); 
			}); 
		}
	}); 
}

var replaceAll = function() {
	replaceLinks();
	replaceForms();
}

jQuery(document).ready(replaceAll);

