
(function addLinkerEvents() {
    var as = document.getElementsByTagName("a");

    //List of file extensions on your site. Add/edit as you require
    for (var i = 0; i < as.length; i++) {
    
        var gaq_classification = as[i].getAttribute("gaq_classification");
        //alert(gaq_classification);
        
        // if link is not classified => skip
        if (gaq_classification == null)
          continue;        
        
        // check if there is already onclick define, if it is, do not override it
        var current_onclick = as[i].getAttribute("onclick");
        if (current_onclick != null)
          continue;                                                    

        // skip javascripts, links without destination and mailto links
        if(!as[i].href || as[i].href.match(/^javascript:/g) || as[i].href.indexOf("mailto:") != -1) {
          //alert(as[i].href);
        	continue;
        }
        
        // we have to use closure to get the variable value of current context;
        // more here: http://stackoverflow.com/questions/3495679/passing-parameters-in-javascript-onclick-event
        as[i].onclick = function (cls) {
          return function() {
				    _gaq.push(['_trackEvent', 'link', 'click', cls]);
				    //alert(gaq_classification+".");
				  }
        }(gaq_classification);
    }
})();
