//script from Rebecca Murphey
//http://blog.rebeccamurphey.com/
//with modifications by Ted Lawless
(function($) {
  $('document').ready(function() {
    var main_loc = $("td.bibInfoData").eq(0)
    $('a').each(function() {
      var $a = $(this);
      var href = $a.attr('href');
      if (!href) var href=""  //eliminates the possibility of undefined urls
      //below - check to see if link is external
      //all proxied urls included
      if ( ((href.match(/^http/)) && (! href.match(document.domain))
	      && (! href.match(/^.*jy2lg7py6p.*/)) && (! href.match(undefined))) 
	      ||(href.match(/^http:\/\/0-/)) ) {
            //add external link to proxied urls
	    //this is for pdf and new window icons
	    $a.attr({ target: "_blank" })
	    $("a[@href$=.pdf]")
	    	.removeClass('external')
		.addClass('pdf')
		.attr({ target: "_blank" })
	    //clean up urls
	    //first step - get rid of leading url characters
	    var re1 = /^http:\/\/www\.|^http:\/\/0\-|^http:\/\/|^https:\/\/www\.|^https:\/\/|/;
	    var ga_name = href.replace(re1, "");
	    //second step - remove proxy information
	    var re2 = /^(www\.|)(.*)\.pegasus\.law\.columbia\.edu(.*)/;
	    var ga_name = ga_name.replace(re2, "$2$3");
	    //console.debug(ga_name)	    
	    // if so, add the GA tracking code
	    $a.click(function() {
	       pageTracker._trackPageview('/ext/' + ga_name);
	       //for testing 
	       //console.debug("you justed clicked on " + ga_name)
	    });
  }
  });
 });
})(jQuery);

