/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
(function($){
  $(document).ready(function(){
    var trackDownloadExtensions = '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip';
    var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
    var isExternal = new RegExp("(^(https?):\/\/)|(^www\.)", "i");
    var isDownload = new RegExp("\\.(" + trackDownloadExtensions + ")$", "i");
    track_ga_popup_php = function(frame_id){
       var frame_url = frame_id.contentDocument.location.toString();
       if (!isDownload.test(frame_url)){
         frame_url = frame_id.src.toString();
       };
       if (isInternal.test(frame_url) && isDownload.test(frame_url)) {
         var extension = isDownload.exec(frame_url);
         //alert(extension[1].toUpperCase());
         _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), frame_url.replace(isInternal, '')]);
       }
    };
    $('a, area').click(function(event) {      
      if (isInternal.test(this.href)) {
        if (isDownload.test(this.href)) {
          // Download link clicked.
          var extension = isDownload.exec(this.href);
          _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
        }
      }else{
    	  var mailtoRE = /^mailto:/i;
    	  var javascriptRE = /^javascript:/i;
        if (this.href && mailtoRE.test(this.href)) {
          _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
        }else if (this.href && !javascriptRE.test(this.href) && isExternal.test(this.href)) {
          _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
          var _this = this;
          if(this.target && this.target=='_blank'){
        	  setTimeout(function(){
        		  window.open(_this.href);
        	  }, 100);
          }else{
        	  setTimeout(function(){
        		  document.location = _this.href;
        	  }, 100);
          }
          return false;
        }      
      }
    });
  });
})(voltimum.jQuery);
