var UEL;
if (!UEL) UEL = {};
//..................................................................................:UEL.class_Stats
UEL.class_Stats = function () {
	
	this.Initialise();
	
	//create a stats image based on a protocol
	switch (this.Protocol) {
		case "http":	
		case "https":	
			//document.write(this.AsURL());
			document.write(this.AsImage());
			break;
		default:
			//document.write(this.AsURL());
			document.write(this.AsImage());
	}
}

//..................................................................................:
//properties
UEL.class_Stats.prototype.Tag = '';
UEL.class_Stats.prototype.Protocol = '';
UEL.class_Stats.prototype.ProtocolDelimiter = '://';
UEL.class_Stats.prototype.SubmissionLink = 'uk.sitestat.com/uel/uel/s?';

//..................................................................................:Initialise
UEL.class_Stats.prototype.Initialise = function () {
	// Retrieve document path, e.g. http://www.abc.uel.ac.uk/level/sublevel/page
	var DocumentPath = new String(document.URL);
	DocumentPath = DocumentPath.toLowerCase();
	
	// Find protocol and remove protocol from the path, e.g. www.abc.uel.ac.uk/level/sublevel/page
	var i = DocumentPath.indexOf(this.ProtocolDelimiter);
	if ( i>=0 ) {
		this.Protocol = DocumentPath.substr(0, i);
		DocumentPath =  DocumentPath.substr(i + this.ProtocolDelimiter.length);
	}
	
	//remove www from hostname, e.g. abc.uel.ac.uk/level/sublevel/page
	DocumentPath = DocumentPath.replace('www.', '');
	
	//remove domaing from the path, e.g. abc.level/sublevel/page
	//
	var Domain = 'uel.ac.uk/';
	var i = DocumentPath.indexOf(Domain);
	if ( i>=0 ) {
		DocumentPath = DocumentPath.substr(i + Domain.length);
	}
	
	//create a tag with special characters replaced
	var DocumentTag = DocumentPath;
	
	//global find / and change to .
	DocumentTag = DocumentTag.replace(/\//g, ".");
	//global find ... and change to .
	DocumentTag = DocumentTag.replace(/\.+/g, ".");
	//global find + and change to _
	DocumentTag = DocumentTag.replace(/\+/g, "_");
	//global find ? and change to _
	DocumentTag = DocumentTag.replace(/\?/g, "_");
	//global find & and change to _
	DocumentTag = DocumentTag.replace(/\&/g, "_");
	//global find = and change to _
	DocumentTag = DocumentTag.replace(/\=/g, "_");
	//global find %20 and change to _
	DocumentTag = DocumentTag.replace(/%20/g, "_");
	//global find # and change to _
	DocumentTag = DocumentTag.replace(/\#/g, "_");

	this.Tag = DocumentTag;
}
//..................................................................................:AsURL
UEL.class_Stats.prototype.AsURL = function () {
	return this.Protocol + this.ProtocolDelimiter + this.SubmissionLink + this.Tag;
}
//..................................................................................:AsImage
UEL.class_Stats.prototype.AsImage = function () {
	ns_l = this.AsURL();
	ns_l+='&ns__t='+(new Date()).getTime();
	ns_pixelUrl=ns_l;
	ns_0=document.referrer;
	ns_0=(ns_0.lastIndexOf('/')==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf('/'),0):ns_0;
	if(ns_0.length>0) ns_l+='&ns_referrer='+escape(ns_0);
	/*
	if(document.images){
		ns_1=new Image();
		ns_1.src=ns_l;
	}
	else document.write('<img src="'+ns_l+'" width="1" height="1" alt="">');
	*/
	return '<img src="'+ ns_l +'" width="1" height="1" alt="" />';
}
//..................................................................................:UEL.Stats
if (!UEL.Stats) UEL.Stats = new UEL.class_Stats();
