/* #############################################################################

NS: trk
	static: yes

dependancies:
	TESCODIRECT.lib.cookies
	TESCODIRECT.lib.event
	TESCODIRECT.lib.DOM.node
	
############################################################################# */

var trk = {
	trkCookieName : "si-trk",
	trkCookieAttribute : "siTrk",

	record : function(el) {
		if (el) {
			var useId = (el && el.id);
			var valueToRecord = useId ? el.id : TESCODIRECT.lib.DOM.node.getTextValue(el);
			var siTrk = el[this.trkCookieAttribute];
			if (siTrk && siTrk.node) {
				var containerId = siTrk.node.id;
				if (containerId) valueToRecord = containerId + "-" + valueToRecord;
			}
			new TESCODIRECT.lib.cookies.set(new TESCODIRECT.lib.cookies.cookie(this.trkCookieName, valueToRecord));
		}
	},
	
	handleRecordRequest : function(event) {
		var srcA = this;
		if (srcA) {
			trk.record(srcA);
		}
	},
	
	recordingObject : function(node) {
		RecordingObject = function(node) {
			this.node = node;
		}
		return new RecordingObject(node);
	},

	recordGroup : function(id) {
		if (id) {
			var node = document.getElementById(id);
			if (node) {
				if (node.hasChildNodes()) {
					var anchors = node.getElementsByTagName("a");
					if (anchors) {
						var numAnchors = anchors.length;
						for (var i = 0; i < numAnchors; i++) {
							var anchor = anchors[i];
							if (anchor) {
								anchor[this.trkCookieAttribute] = new this.recordingObject(node);
								TESCODIRECT.lib.event.attach(anchor, "click", this.handleRecordRequest);
							}
						}
					}
				}
			}
		}
	}
}


