/* Automatically assign onclick omniture events to links using jQuery
   selectors to do so when the page is loaded
*/

$(document).ready(function () {

  default_linkTrackVars=",campaign,channel,hier1,eVar4,eVar12,eVar14,eVar15,eVar16,prop4,prop12,prop14,prop15,prop16,prop17";

  $("a.tk_fanclub").each(function() {
    $(this).click(function() {
      s.linkTrackVars='prop5' + default_linkTrackVars;
      s.prop5='exit: toby keith fan club';
      s.tl(this,'o',s.prop5);
      s.linkTrackVars='';
    });
  });
  $("a.tk_tour").each(function() {
    $(this).click(function() {
      s.linkTrackVars='prop5' + default_linkTrackVars;
      s.prop5='exit: toby keith tour dates';
      s.tl(this,'o',s.prop5);
      s.linkTrackVars='';
    });
  });

  /* sharethisbutton */
  $("#sharethis").click(function() {
    s.linkTrackVars='prop5' + default_linkTrackVars;
    s.prop5='fv: americastoughesttour: global: share this';
    s.tl(this,'o',s.prop5);
    s.prop5='';
    s.linkTrackVars='';
    return false;
  });

  /* !!! gallery image popups (BCS) */
  /* Technically, to Omniture, this is a PAGELOAD tag, that just so happens to
     occur because of a user clicking a button.  (NB) */
  $("a.galimg").each(function() {
    $(this).click(function() {
      // this event needs the image filename appeanded to the pageName var.  get it first
      url = this.href;
      if (url.indexOf("?") !== -1) { //If there is a query string involved
        // get rid of all arguments
        url = url.substr(0, url.indexOf("?"));
        // pop the last part of the path off, which should be the image filename
        url = url.split("/").reverse().shift();
      } else {
        url = 'unknown';
      }
      s.pageName='fv: americastoughesttour: gallery: image: ' + url;
      var s_code=s.t();if(s_code)$('#galimg_pageload').html(s_code);
      s.linkTrackVars='';
    });
  });

  /* On-click for Gallery Videos */
  $("a.galvid").each(function() {
    $(this).click(function() {
      // this event needs the video filename appeanded to the pageName
      // var, this can be grabbed from the "video" QS param.
      url = this.href;
      qs_params = new Array();
      if (url.indexOf("?") !== -1) { //If there is a query string involved
        // Process the QS
        qs_str = url.substr(url.indexOf("?"),url.length);                             //Stringified
        qs_ary = qs_str.substr(1,qs_str.length).split('&');                           //As array
        for(i in qs_ary) qs_params[qs_ary[i].split('=')[0]] = qs_ary[i].split('=')[1];//Finally - associative array
      } else {
        qs_params["video"] = 'unknown';
      }
      s.pageName='fv: americastoughesttour: gallery: video: ' + qs_params["video"];
      var s_code=s.t();if(s_code)$('#galimg_pageload').html(s_code);
      s.linkTrackVars='';
    });
  });

});