// $Id: track.js 16977 2009-10-26 20:48:50Z wil $

/* This variable is the EVENT TRACKING STRING MAPPER.
 * It takes an event such as "PROFILE EDIT" and returns
 * the url that should be tracked as a result.. in this case
 * '/profile/edit.'
*/

var event_ts_map = {
  PROFILE_EDIT:                 '/profile/edit',
  ICON_UPLOAD:                  '/profile/icon/edit',
  PHOTO_UPLOAD:                 '/profile/photo/edit',
  HOME:                         '/user/home',
  INVITE_CLICKED:               '/user/invites/clicked',
  INVITE_CLICKED_WL:            '/user/invites/clicked/from_waiting_list',
  INVITE_FULFILLED:             '/user/invites/fulfilled',
  INVITE_SENT:                  '/user/invites/sent/',
  INVITE_SENT_WL:               '/user/invites/sent/waiting_list/',
  LOGOUT:                       '/auth/logout',
  LOGIN:                        '/auth/login/success',
  PSET_UPLOAD_START:            '/photoset/upload/started',
  PSET_UPLOAD_COMP:             '/photoset/upload/completed',
  PSET_UPLOAD_VER:              '/photoset/upload/verified',
  MESSAGE_TO_USER:              '/messages/sent/to_user',
  MESSAGE_TO_PHOT:              '/messages/sent/to_photographer',
  MESSAGE_TO_MODEL:             '/messages/sent/to_model',
  MESSAGE_TO_FANS:              '/messages/sent/to_fans',
  MESSAGE_FROM_USER:            '/messages/view/from_user',
  MESSAGE_FROM_PHOT:            '/messages/view/from_photographer',
  MESSAGE_FROM_MODEL:           '/messages/view/from_model',
  FAN_MESSAGE_MODEL:            '/messages/view/fan_message_from_model',
  FAN_MESSAGE_PHOT:             '/messages/view/fan_message_from_photographer',
  FRIEND_FROM_USER:             '/friend/from_user',
  FRIEND_FROM_MODEL:            '/friend/from_model',
  FRIEND_FROM_PHOT:             '/friend/from_photographer',
  FRIEND_TO_USER:               '/friend/to_user',
  FRIEND_TO_MODEL:              '/friend/to_model',
  FRIEND_TO_PHOT:               '/friend/to_photographer',
  WWW_SIGNUP:                   '/www/signup',
  PURCH_VOTES_CLICK_PAYPAL:     '/purchases/buy_votes/clicked/paypal',
  PURCH_VOTES_CLICK_CC:         '/purchases/buy_votes/clicked/CC',
  PURCH_VOTES_COMPLETE_PAYPAL:  '/purchases/buy_votes/completed/paypal',
  PURCH_VOTES_COMPLETE_CC:      '/purchases/buy_votes/completed/CC'
};

/* This method will track a page view using google analytics.
 * It expects to receive an EVENT Constant - E.g. 'LOGIN'
 * It will use the event constant as input to the event_ts_map hash
 * and then track a page view to the resulting tracking string.
 * If there is a value passed into x_var then that value is appended at the end
 * of the track_string - e.g. track_page_view('INVITE_SENT', '4');
 * would result in tracking '/user/invites/sent/4' 
 * */
function track_page_view( event_const, n_var ) {
  // uses GA 2.0; if it's not included on this page, then don't do anything
  if (!window._gat) { return false; }
  track_string = event_ts_map[event_const];
  //track_string = (n_var === null) ? track_string : track_string + n_var;
  
  pageTracker._trackPageview( track_string );
}

/* This method simply tracks the string that is passed in.
 * It handles weird cases where the url is custom built such as
 * track_page_view_custom( '/' + page.artist_role + 's/' + page.artist + '/photosets/' + page.artist_pnum + '/vote'); 
 * */
function track_page_view_custom( custom_url ) {
  if (!window._gat) { return false; }
  pageTracker._trackPageview( custom_url );
}

function mail_link( e, s ) {
  track_page_view_custom( "/email/" + s );
  window.location = "mailto:" + e;
}