//..................................................................................:class_UEL
class_UEL = function() {

	this.Initialise();
	// @todo: add debug panel by trigger
	// @todo: add '_trace' method

	// create a stats image based on a protocol
	switch (this.Protocol) {
	case "http":
	case "https":
		if (this.isLive) {
			this.trace('Live', 'Server');
		} else {
			this.trace('Testing/Development', 'Server');
			this.trace(this.Tag, 'Page tag');
		}
		break;
	default:
		// document.write(this.AsURL());
		document.write(this.AsImage());
	}
};

// ..................................................................................:
// properties
class_UEL.prototype.Tag = '';
class_UEL.prototype.Protocol = '';
class_UEL.prototype.ProtocolDelimiter = '://';
class_UEL.prototype.isLive = true;

class_UEL.prototype.__debug = null;

// ..................................................................................:trace
class_UEL.prototype.trace = function(T, H) {
	this.__debug.append("<p>" + (!H ? '' : '<strong>' + H + '</strong>: ') + T
			+ "</p>");
};

// ..................................................................................:Initialise
class_UEL.prototype.Initialise = function() {
	// create debug output
	this.__debug = $('<div id="debug"></div>');

	// Retrieve document path, e.g. http://www.abc.uel.ac.uk/level/sublevel/page
	var DocumentPath = new String(document.URL);
	DocumentPath = DocumentPath.toLowerCase();

	// Add default index page after trailing slash
	var iL = DocumentPath.lastIndexOf('/');
	if (iL >= 0 && iL == (DocumentPath.length - 1)) {
		DocumentPath += 'index.htm';
	}

	// @todo: loop over UEL dev domains
	// @todo: highlight case of no www
	this.isLive = !(DocumentPath.indexOf("localhost") >= 0
			|| DocumentPath.indexOf("uel-iis-dev") >= 0 
			|| DocumentPath.indexOf("uel-cms") >= 0 
			|| DocumentPath.indexOf("staging") >= 0);

	// 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;

	// show only in non-live environments
	if (!this.isLive) {
		$('body').append(this.__debug);
	}
};
// ..................................................................................:UEL
var UEL;
if (!UEL) {
	UEL = new class_UEL();
}

