 
// document.ready function that runs when the page has finished loading
// assumes the jQuery core library has been included on the page
$(function(){ 

     // create a wrapped set of all links in which the HREF ends in .pdf or .doc
     // add additional extensions by simply appending more .add() functions
    var $wrapped = $('a[href $= ".pdf"]')
                .add('a[href $= ".doc"]')
                ;
                
     // loop over the wrapped set with the each() function
     // $this will refer to the current element in the loop
    $wrapped.each(function(i) {
    
        // get the HREF attribute of the link
       //var href = $(this).attr('href');
	   var href = this.href;
       
         // remove hard-coded http://www.stratus.com in HREF if it exists
       href = href.replace(/^http:\/\/www\.stratus\.com/,'');
       
        // if the HREF begins with 'http' make no changes since it most likely an external link  
        // if the HREF does not begin with 'http' (meaning it is a local link)
       if ( ! href.match(/^http/) ) { 

            // remove the Eloqua redirect
           href = href.replace(/^.*\/elqNow\/elqRedir\.htm\?ref=/,'');
           
            // remove references to the /download/ handler (both methods: /index.cfm/path and /index.cfm?file=path
           href = href.replace(/^.*\/download\/index.cfm/,'');
           href = href.replace(/^.*\/download\/?\?file=/,'');
                       
            // save the cleaned up HREF to a variable since it should now contain the absolute path to the file
           var filepath = href;
           
            // add the Eloqua handler to the front of the path
            // only add it to links that begin with a forward slash(/)
            // if a link references a filename in the current folder or subfolder there is no way to determine the full path
           if (href.match(/^\//)) {
           
                // add the download handler in front of the path
               href = '/elqNow/elqRedir.htm?ref=' + href;
               
                // update the HREF on the link
               $(this).attr('href',href);
               
                // set the onClick handler and pass it the absolute path to the file
               $(this).click(function() {
                  logFileDownload(filepath);
               });
           
           }
                
      } // ...if the HREF still begins with HTTP
                          
    });  //... loop over the wrapped set
    
}); // ... document.ready function

// logFileDownload() will be set as the onClick handler for file download links
// Currently it will log the file download to Goggle Analytics
//   path = the absolute path to the file (example: /pdf/avance/AvanceDataSheet.pdf)

function logFileDownload(path) {

     // Google
     // use a try/catch block in case the Google pageTracker object does not exist
    try {

       // call the Google Analytics page tracker    
      pageTracker._trackPageview(path);
      
    } catch(err) { }

     // return true so that the default link 'click' action will be executed
    return true;
    
} // ... function logFileDownload()

