/* site specific scripts */

function siteInit(){
  // Called with the body onload event.
  // Customise according to site requirements.
  setLinkClicker();
}

function setLinkClicker() {
 // Function looks through all links on a page and a
 // javascript call to link_click function if external
 var link;
 var domain = document.domain;

 var ext = [".doc",".xls",".exe",".zip",".pdf", "downloadApplicationForm"];

 for(var i in document.links) {
   link = document.links[i];

   // Internet Explorer throws up a link that doesn't have
   // .hostname, which causes an error.
   // Set the target based on domain matching.
   if(link.hostname && link.hostname != domain) {
     // external
      addCrossBrowserEvent(link,['click','onclick'],link_ext_click,false);
   } else if (link.href) {
      if (link.href.indexOf('mailto')>-1) {
         addCrossBrowserEvent(link,['click','onclick'],link_mailto_click,false);
      } else {
         for (var i in ext) {
            if (link.href.indexOf(ext[i])>-1) {
               addCrossBrowserEvent(link,['click','onclick'],link_download_click,false);
            }
         }
      }
   }
  }
}

function link_ext_click() { linkTrack('external'); }
function link_download_click() { linkTrack('download'); }
function link_mailto_click() { linkTrack('mailto'); }

function linkTrack(category) {
    if (current_browser.isIE) {
        loc=window.event.srcElement.href;
    }
    else {
        loc=this.href;
    }
    urchinTracker ('/' + category + '/'+ loc);
}

