//=====================================================================================
// fsxTracker: javascript object for fsi/fpas tracking and analytics
//=====================================================================================
// properties:
//   pageName     (page title)
//   trackingPath (path used to track page, a.k.a. category)
//   author       (story author)
//   source       (story provider)
//   contentType
//-------------------------------------------------------------------------------------
// methods:
//   setPageName(pageName)               - sets page name
//   setTrackingPath(trackingPath)       - sets page tracking path
//   setValues(pageName,trackingPath)    - sets page name and page tracking path
//   sendInfo()                          - wrapper for call to sendPageView()
//   sendPageView()                      - sends trackingPath and pageName to account. Values are
//                                         taken from fsxTracker's pageName and trackingPath properties
//   sendPageView(pageName,trackingPath) - sends pageName and trackingPath to account. Uses values passed in
//   sendDownload()                      - sends a download event to account with using default download name
//   sendDownload(downloadName)          - sends a download event to account with using supplied download name
//   initOther()                         - sets properties and sends tracking data for secondary accounts (use on FoxSoccer)
//   init()                              - sets properties, sends tracking data on first load, and creates objects for all accounts
//=====================================================================================
var fsxTracker = {
  pageName:'',trackingPath:'',downLoadName:'unknown download (fsxTrkr)',
  site:'fse',contentType:'', source:'',author:'',
  googleAccount:'',_ga_fpas:'UA-4869874-1',_ga_fsc:'UA-4869874-2',
  _stripValue:function(a){a=a.replace(/\s+$/,'');a=a.split(",").join("");a=a.split("&").join("");a=a.split("'").join("");a=a.split("#").join("");a=a.split("$").join("");a=a.split("%").join("");a=a.split("^").join("");a=a.split("*").join("");a=a.split(":").join("");a=a.split("!").join("");a=a.split("<").join("");a=a.split(">").join("");a=a.split("~").join("");a=a.split(";").join("");a=a.split("\\").join("");a=a.split(" ").join("+");return a;},
  setPageName:function(ftPn){this.pageName=this._stripValue(ftPn);},
  setTrackingPath:function(ftTp){this.trackingPath=this._stripValue(ftTp);},
  setValues:function(ftPn,ftTp){this.setPageName(ftPn);this.setTrackingPath(ftTp);},
  sendPageView:function(ftPn,ftTp){
    (ftPn&&(ftPn=this._stripValue(ftPn)))||(ftPn=this.pageName);
    (ftTp&&(ftTp=this._stripValue(ftTp)))||(ftTp=this.trackingPath);
    _hbPageView(ftPn,ftTp);fsxGoogleTracker._trackPageview(ftTp);},
  sendDownload:function(ftDlName){ftDlName||(ftDlName=this.downLoadName);_hbDownload(ftDlName);fsxGoogleTracker._trackPageview(ftDlName);},
  sendInfo:function(){this.sendPageView();},
  _debug:function(){alert("trackingPath: "+this.trackingPath);alert("pageName: "+this.pageName);alert("site: "+this.site);alert("googleAccount: "+this.googleAccount);alert("author: "+this.author);alert("source: "+this.source);},
  initOther:function(){if(fsxPage.site){this.site=fsxPage.site;}if(this.site=='fsc'){this.googleAccount=this._ga_fsc;}else{this.googleAccount=this._ga_fpas;}fsxInitGoogle();},
  init:function(){if(fsxPage.name){this.pageName=this._stripValue(fsxPage.name);}if(fsxPage.path){this.trackingPath=this._stripValue(fsxPage.path);}
    if(fsxPage.site){this.site=fsxPage.site;}if(fsxPage.contentType){this.contentType=this._stripValue(fsxPage.contentType);}
    if(fsxPage.source){this.source=this._stripValue(fsxPage.source);}if(fsxPage.author){this.author=this._stripValue(fsxPage.author);}
    if(this.site=='fsc'){this.googleAccount=this._ga_fsc;}else{this.googleAccount=this._ga_fpas;}
    fsxInitHitbox();fsxInitGoogle();}
};

//-------------------------------
// fsxInitHitbox()
//-------------------------------------------
function fsxInitHitbox() {
  _pn          = fsxTracker.pageName;                      // sets the page name
  _mlc         = fsxTracker.trackingPath;                  // sets the tracking path
  hbx.pn       = fsxTracker.pageName;                      // sets the page name
  hbx.mlc      = fsxTracker.trackingPath;                  // sets the tracking path
  hbx.hc1      = fsxTracker.contentType +"|"+ fsxTracker.source;
  hbx.hc2      = fsxTracker.author      +"|"+ fsxTracker.pageName;
  var head     = document.getElementsByTagName('head')[0]; // get the header tag
  var script   = document.createElement('script');         // create a script tag
  script.type  = "text/javascript";                        // set the type
  script.src   = "/fe/js/hbx.js";                          // set the script source
  head.appendChild(script);                                // place the script on the page
}

//-------------------------------
// fsxInitGoogle()
//-------------------------------------------
var fsxGoogleTracker;
function fsxInitGoogle() {
  fsxGoogleTracker=_gat._getTracker(fsxTracker.googleAccount);
  fsxGoogleTracker._trackPageview(fsxTracker.trackingPath);
}
