/**  Google Analytics */

var googleAnalytics = {
  initialize: function() {
    
    this.check = false;
    this._trackDownloads();
    this._trackPrintPage();
    this._trackExternalLinks();
    this._trackEmailThisPage();
    this._trackGlossary();
  },
  
  _trackDownloads: function() {    
    jQuery('a').click(function(e) {
      try {
				if (jQuery(this).attr('href').match(/\.(?:doc|eps|svg|xls|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&|\?)/)) {
					if (this.href.match(/\.(?:pdf)($|\&|\?)/)) {
						if (this.rel !== "") {
							_gaq.push(['_trackEvent', 'Downloads', 'PDF', this.rel]);
						}
						else 
							_gaq.push(['_trackEvent', 'Downloads', 'PDF', this.title]);
					}
					else {
						_gaq.push(['_trackEvent', 'Downloads', 'File', this.title]);
					}
				}
				else 
					if (jQuery(this).attr('href').match(/\.(?:pps|ppt)($|\&|\?)/) && jQuery(this).attr('class') !== 'jakebox') {
						googleAnalytics.trackMediaDownload(this.rel || this.title, 'slide deck');
					}
			} catch(error) {
				//Do nothing
			}
    });
  },
  
  _trackPrintPage: function() {
    jQuery('#toolbar li.print a').click(function (e) {
      _gaq.push(['_trackEvent','Global Features','Print Page',window.location.pathname]);
    });
  },
  
  _trackEmailThisPage: function() {
    jQuery('#toolbar li.email a').click(function (e) {
      _gaq.push(['_trackEvent','Global Features','Email Page Open',window.location.pathname]);
    });
  },
  
  trackEmailThisPage: function(value, href) {
    _gaq.push(['_trackEvent','Global Features',value,href]);
  },
  
  _trackGlossary: function(value) {
      if (value === "on") {
        _gaq.push(['_setCustomVar', 2, 'glossary-on', 2]);
      } else {
        _gaq.push(['_setCustomVar', 2, 'glossary-off', 2]);
      }
  },
  
  _trackExternalLinks: function() {
    jQuery('a').filter(function(index) {
      $this = jQuery(this);        
     if (location.hostname !== this.hostname && 
        !(this.href.indexOf("javascript:") > -1 || 
        this.href.indexOf("mailto:") > -1 ||
        this.href === "" ||
        this.href === "#" ||
        $this.hasClass("email") ||
			  $this.hasClass("print-page") ||
        $this.hasClass("jakebox") ||
        $this.hasClass("ppt-view-btn"))
      ) {
        return true;
      } else {
        return false;
      }
    }).click(function(e) {
        var path = '/vpv/outbound/' + jQuery(this).attr('href');
        _gaq.push(['_trackPageview',path]);
    });
  },
  
  trackSlideDeck: function(action, label) {
    _gaq.push(['_trackEvent','slide deck',action,label]);
    //console.info(action+ ' -- '+label);
  },
  
  trackVideo: function(clipUrl, clipEvent) {
    var title = (jQuery('a[href^='+clipUrl+']').attr('rel') != undefined)? jQuery('a[href^='+clipUrl+']').attr('rel') : clipUrl;
    _gaq.push(['_trackEvent','video',clipEvent,title]);
  },
  
  trackVideo: function(clipUrl, clipEvent, clipTitle) {
    _gaq.push(['_trackEvent','video',clipEvent,clipTitle]);
  },
  
  trackMediaDownload: function(title,type) {
    _gaq.push(['_trackEvent', type,'download', title]);
  },
  
  trackGlossary: function(isOn) {
    if(isOn) {
      _gaq.push(['_setCustomVar', 2, 'glossary-on', 2]);
    } else {
      _gaq.push(['_setCustomVar', 2, 'glossary-off', 2]);
    }
    //alert(isOn);
  },
  
  trackClinicalTrials: function(tumorType) {
      _gaq.push(['_trackEvent','Interactive Feature','Clinical Trials Search',tumorType]);
      //alert(tumorType + " tracked");
    },
  
  trackZoom: function(index)
  {
    var value;
    switch(index)
    {
      case 0:
        value = "text-small";
        break;
      case 1:
        value = "text-normal";
        break;
      case 2:
        value = "text-large";
        break;
      case 3:
        value = "text-largest";
        break;
      default:
        value = "";
    }
    _gaq.push(['_setCustomVar', 1, value, 2]);
    //alert(value);
  },
  
  trackShareClick: function(shareName) {
    _gaq.push(['_trackEvent', 'shareClick', shareName]);
  }
}

jq$(document).ready(function() {
  googleAnalytics.initialize();  
});
 
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-291924-27']);
_gaq.push(['_trackPageview']);

_gaq.push(['t2._setAccount', 'UA-6139708-1']); 
_gaq.push(['t2._trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
