/* APPLIES SI TRACKING PAGE HREFS */
si_impl = function(){
	var siLnx = document.getElementsByTagName("a"); 
	var siID = ""; // Site Intelligence link id
	for(siLnc=0;siLnc<siLnx.length;siLnc++){
		// Skip skipper links
		if(siLnx[siLnc].className != "skipper"){
			//Clear the siID
			siID = "";
			siID = getPID() + getCID(siLnx[siLnc]) + getLID(siLnx[siLnc]);	
			if(siID != "" && !siLnx[siLnc].id){
				siLnx[siLnc].id = siID;
				siLnx[siLnc].onclick = function(){
					if(typeof sitracker != 'undefined'){
						sitracker.trackExternalLink(this);
					}
				}				
			}
		}
	}
}
// Get Link ID
getLID = function(ele){
	var txtNodeIdx = -1;
	var imgNodeIdx = -1;
	var lid = "";
	if(ele.hasChildNodes()){
		for(i=0;i<ele.childNodes.length;i++){
			if( (ele.childNodes[i].nodeName == "#text") && ((ele.childNodes[i].nodeValue != " ") && (ele.childNodes[i].nodeValue != "")) ){txtNodeIdx = i;}
			if(ele.childNodes[i].nodeName == "IMG"){imgNodeIdx = i;}
		}
		if(txtNodeIdx != -1){
			lid = ele.childNodes[txtNodeIdx].nodeValue.toLowerCase().replace(/(^\s)|(\s$)/g,'');
		}else if(imgNodeIdx != -1){
			lid = ele.title.toLowerCase().replace(/(^\s)|(\s$)/g,'');
		}
		lid = lid.replace(/\s/g,'-');
	}
	return (lid != "") ? "." + lid : lid; 
}
// Get Container ID
getCID = function(ele){
	while(!ele.parentNode.id){
		ele = ele.parentNode;
	}
	return "." + ele.parentNode.id;
}
//Get Page ID
getPID = function(){
	var re = /\.com|\.co\.uk|C\:/g;
	var us = unescape(document.location.toString()).toLowerCase().replace(/\s/g,'-').split("/");
	var idx = 0;
	for(i=0;i<us.length;i++){
		if(re.test(us[i])){
			idx = i+1;
			break;
		}
	}
	var siPID = us.slice(idx, us.length).join(".");
	siPID = siPID.substring(0,siPID.lastIndexOf("."));
	return escape(siPID);
}
//Call si_impl function
window.addEvent('domready', function() {
	si_impl();
});