addLoadEvent(listHover);
addLoadEvent(addUTM);
addLoadEvent(assignLogGoal);

// standard - logs goals that use "this" as the value
function assignLogGoal(){
	if (!$('.logGoal')){ return; }
	var links = $('.logGoal');
	for (var i=0; i<links.length; i++){
		links[i].onclick = function(){
			logGoal(this);
			window.open(this, "link");
			return false;
		}
	}
}

function logGoal(a) {
	var u = document.location.pathname;
	var h = a.hostname;
	var t = a.text;
	if (t == undefined || t.length == 0) {
		t = a.hostname +  a.pathname;
	}
	var i = a.pagePosition;
	
	var sGoal;	
	sGoal = '/goal' + u;
	if (i != undefined) {
		sGoal += '/' + i;
	}
	sGoal += '/' + t;
	urchinTracker(sGoal);
	return true;
}
function getCookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return '';
}


function addUTM () {
	var a = document.links;
	var d = document.domain;
	var c = escape(getCookie("__utma") + "-" + getCookie("__utmb") + "-" + getCookie("__utmc"));
	var s = '?';
	var bShowLink = (document.location.search.indexOf('showlinknumber') >= 0);
	for (i=0;i<a.length;i++) {
		if ((a[i].protocol.substr(0,4) == 'http') && (d != a[i].hostname)) {
			//alert("i=" + i + "\ndomain=" + document.domain + "\nhref=" + a[i].href + "\nhost=" + a[i].host + "\nhostname=" + a[i].hostname + "\npathname=" + a[i].pathname);
			if (a[i].href.indexOf(s) > -1) {
				s = '&';
			} 
			else {
				s = '?';
			}
			a[i].href = a[i].href + s + 'sid=' + c;
		}
		a[i].pagePosition = i;
		if (bShowLink) {
			a[i].title += "Link #:" + i;
		}
	}
	return true;
}



function listHover(){
	var nav = document.getElementById('nav');
	var liList = nav.getElementsByTagName('li');
	for (var i=0; i<liList.length; i++){
		liList[i].onmouseover = function(){
			this.className = 'li_on';
		}
		liList[i].onmouseout = function(){
			this.className = 'li_off';
		}
	}

}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

