






// Google analytics event tracking 

//=== add tracking definitions here =============
//
// Use switch-style conditionals; put high-frequency pages first

// View Item
if ( 'item' == current_page() ) {
  trackevent({id: '#vi_send_email', action: 'Email item'});
  trackevent({id: '#vi_share_this', action: 'Share item'});
  trackevent({id: '#vi_share_facebook', action: 'Share item'});
  trackevent({id: '#vi_share_myspace', action: 'Share item'});
  trackevent({id: '#vi_share_google', action: 'Share item'});
  trackevent({id: '#vi_share_twitter', action: 'Share item'});
  trackevent({id: '#show_trust_details_link', action: 'See details for trust provider'});
  trackevent({id: '#show_gp_details_link', action: 'Learn about goodprint'});
  trackevent({id: '#show_full_desc_link', action: 'Full description'});
  trackevent({id: '#vi_seller_other_item', action: 'Seller other items'});
  trackevent({id: '#btmbuynow_btn', action: 'Buy now bottom'});
  trackevent({id: '#topbuynow_btn', action: 'Buy now top'});
  trackevent({id: '#vi_contact_seller', action: 'Contact seller'});
  trackevent({id: '#vi_report_item', action: 'Report this item'});
 } else if ( 'list' == current_page() ) {
  $j( function () { // wait for page to load
      $j("#featured_products a").each( function() {
           var tid = '#' + this.id;
            //alert('id is ' + tid);
            trackevent({ id: tid, action: 'Featured Category Items' });
        } );

      trackevent({ id: '#recentimg-1_lnk', action: 'Recently Viewed Items' });
      trackevent({ id: '#recentimg-2_lnk', action: 'Recently Viewed Items' });
      trackevent({ id: '#recentimg-3_lnk', action: 'Recently Viewed Items' });
      trackevent({ id: '#recentimg-4_lnk', action: 'Recently Viewed Items' });
      trackevent({ id: '#recentimg-5_lnk', action: 'Recently Viewed Items' });
      trackevent({ id: '#recentimg-6_lnk', action: 'Recently Viewed Items' });
  });
 }

//========end click track registry ================

// public.  Call this directly from your page if you need to track dynamic content

function track(id, category, action, label) {
  $j(function () { // wait for page load
      try {
        $j(id).click(function () {
            pageTracker._trackEvent(category, action, label);
          });
      } catch( err ) {
        //alert(err.description);
      }
    });
} 


// trackevent()
// event tracker with defaults and named parameters
// Usage: trackevent( {id: '#my_element', category: 'my category', action: 'my action', label: 'my label'} );
// Arguments: all arguments except for id are optional.
//   category will default to the page name
//   action will default to the element id
//   label will default to the id.title attribute
function trackevent( args ) {
  var id = typeof args.id != 'undefined' ? args.id : "";
  var category = typeof args.category != 'undefined' ? args.category : "";
  var action = typeof args.action != 'undefined' ? args.action : "";
  var label = typeof args.label != 'undefined' ? args.label : "";
  
  if ( is_blank( id ) ) {
    alert('Invalid tracking request: id is missing!');
    return false;
  }
  
  if ( is_blank( category ) ) {
    category = current_page();
  }
  
  if ( is_blank( action ) ) {
    $j( function () {
        action = $j(id).attr('tracking_action') ? $j(id).attr('tracking_action') : "";
      });
  }
  
  if ( is_blank( label ) ) {
    $j( function () {
        label = $j(id).attr('tracking_label') ? $j(id).attr('tracking_label') : $j(id).attr('title');
      });
  }
  
  $j( function () { // wait for page load
      try {
        $j(id).click(function () {
            pageTracker._trackEvent(category, action, label);
          });
      } catch( err ) {
        //alert(err.description);
      }
    });
}

function current_page() {
  var paths = window.location.pathname.split('/');
  var i = paths.length - 1;
  var page = '';
  while ( i >= 0 && is_blank( page ) ) {
    page = paths[i];
    i = i -1;
  }
  if ( page == '' ) {
    page = 'home';
  }
  return page;
}

function is_blank( str ) {
  return str.replace(/\s/g,'') == '';
}
