(function($) {

	/**  Google Analytics */
	
	var googleAnalytics = {
	  initialize: function() {
	    
	    this.check = false;
	    this._trackDownloads();
	    this._trackPrintPage();
	    this._trackExternalLinks();
	    this._trackEmailThisPage();
	    this._trackGlossary();
	  },
	  
	  _trackDownloads: function() {    
	    $('a[target="_blank"]').click(function(e) {
	      if($(this).attr('href').match(/\.(?:doc|eps|jpg|png|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 ($(this).attr('href').match(/\.(?:pps|ppt)($|\&|\?)/)) {
	        googleAnalytics.trackMediaDownload(this.rel || this.title,'slide deck');
	      }
	    });
	  },
	  
	  _trackPrintPage: function() {
	    $('a.print-page').click(function (e) {
	      _gaq.push(['_trackEvent','Global Features','Print Page',window.location.pathname]);
	    });
	  },
	  
	  _trackEmailThisPage: function() {
	    $('a.email-page').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() {
	    $('div#glossary-toggle').children('a').click(function (e) {
	      var value = $(this).attr('class');
	      if (value === "on") {
	        _gaq.push(['_setCustomVar', 2, 'glossary-on', 2]);
	      } else if (value === "off") {
	        _gaq.push(['_setCustomVar', 2, 'glossary-off', 2]);
	      }
	    });
	  },
	  
	  _trackExternalLinks: function() {
	    $('a').filter(function(index) { return (location.hostname!=$('a')[index].hostname && 
	      $('a[href!=""')[index] &&
				$('a[href!="javascript:"]')[index] && 
	      $('a[href!="mailto:"]')[index] && 
	      $('a[class!="email"]')[index] &&
				$('a[class!="jakebox"]')[index] &&
	      $('a[class!="ppt-view-btn"]')[index])}).click(function(e) {
	        var path = '/vpv/outbound/' + $(this).attr('href');
	        _gaq.push(['_trackPageview',path]);
	    });
	  },
	  
	  trackSlideDeck: function(action, label) {
	    _gaq.push(['_trackEvent','slide deck',action,label]);
	  },
	  
	  trackVideo: function(clipUrl, clipEvent) {
	    var title = ($('a[href^='+clipUrl+']').attr('rel') != undefined)? $('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]);
	    }
	  },
	  
	  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]);
	  }
	}
	
	$(window).load(function() {
	   googleAnalytics.initialize();
	});

})(jQuery);
