/**
* Metrics class
*/

var Metrics = {
initialize: function() {
  if (Metrics.s) {
    this.active = true;
  } else if (s) {
    this.s = s;
    this.active = true;
  } else {
    this.s = '';
    this.active = false;
  }

  // attach image metrics to photos
  $('#photos ul li a').click(function() {Metrics.ImageView();});
},
PageView: function(pagename) {
  pagename = this.distillName(pagename);
  // Omniture page tracking
  if (this.active == true) {
    // prepend cheerleaders
    var ompagename = 'cheerleaders:'+pagename;
    this.TrackPage(ompagename);
  }
  // google analytics tracking
  var pageurl = '/'+pagename;
  this.TrackGooglePage(pageurl);
},
ImageView: function() {
  // only google analytics
  this.TrackEvent('photo','view');
},
ImageDisplay: function(url) {
  this.TrackEvent('photo','display',url);
},
TrackPage: function(pagename) {
    this.s.pageName = pagename;
    this.s.events = '';
    this.s.t();
},
TrackExit: function(url) {
  var link = this.replaceURL(url);
  // omniture
  this.TrackExitLink(link);
  // google
  var exit_link = '/exit/' + link;
  this.TrackGooglePage(exit_link);
},
TrackGooglePage: function(page_url) {
    pageTracker._trackPageview(page_url);
},
StartVideo: function(video_name) {
  // omniture
  this.TrackVideoStart('cheerleaders',video_name);
  // google
  this.TrackEvent('video','start',this.distillName(video_name));
},
CompleteVideo: function(video_name) {
  // omniture
  this.TrackVideoComplete('cheerleaders',video_name);
  // google
  this.TrackEvent('video','complete',this.distillName(video_name));
},
TrackEvent: function(category,action,label) {
    if (category && action && label) {
      pageTracker._trackEvent(category,action,label);
    }
    else if (category && action) {
      pageTracker._trackEvent(category,action);
    }
    else {
      pageTracker._trackEvent(category);
    }
},
TrackExitLink: function(link) {
  link = this.distillName(link);
  this.s.tl(this,'e',link)
},
TrackVideoStart: function(category,title) {
  category = this.distillName(category);
  title = this.distillName(title);

  this.s.linkTrackVars = "eVar8,events";
  this.s.linkTrackEvents = "event7";

  if(category != "") {
    this.s.eVar8 = category.toLowerCase() + "-" + title.toLowerCase();
  } else {
    this.s.eVar8 = title.toLowerCase();
  }

  this.s.events = "event7";
  this.s.tl(this,'o','video_start')
  this.s.linkTrackVars = this.s.linkTrackEvents = this.s.eVar8 = this.s.events = "";
},
TrackVideoComplete: function(category,title) {
  this.s.linkTrackVars = "eVar8,events";
  this.s.linkTrackEvents = "event23";

  if(category != "") {
    this.s.eVar8 = category.toLowerCase() + "-" + title.toLowerCase();
  } else {
    this.s.eVar8 = title.toLowerCase();
  }

  this.s.events = "event23";
  this.s.tl(this,'o','video_complete')
  this.s.linkTrackVars = this.s.linkTrackEvents = this.s.eVar8 = this.s.events = "";
},
distillName: function(string) {
  return string.replace(/[^a-zA-Z0-9]/g,'-');
},
replaceURL: function(URL) {
  var string = URL.replace(/^http:\/\//,'');
  return string;
},
zzz: function(){}
};


