/*
Cufon.replace('.cufon.nilland-black', { fontFamily: 'Nilland-Black' });
Cufon.replace('.cufon.nilland-bold', { fontFamily: 'Nilland-Bold' });
Cufon.replace('#addto h3', { fontFamily: 'Nilland-Black', textShadow: 'rgba(0,0,0,0.5) 1px 1px 0'});
Cufon.replace('#dyna-tabs a', { fontFamily: 'Nilland-Black', hover: true });
Cufon.replace('#merchant-info p', { fontFamily: 'Nilland-Bold' });
Cufon.replace('#dyna-tabs a span', { fontFamily: 'Nilland-Bold', hover: true });
*/

var rcstats_custom = {};
//rcstats_custom.advanced_disable = 1;
rcstats_custom.timer = 100;

if (afp == 1) {
  var date = new Date();
  date.setTime(date.getTime()+(cxp*1000));
  var expires = date.toGMTString();
};

function swapTabs(swapto){
  $('#dyna-tabs li').each(function(){
    if ($('a',this).hasClass(swapto)) {
      $(this).addClass('current');
    } else {
      $(this).removeClass('current');
    };
  });

  //Cufon.replace('#dyna-tabs a', { fontFamily: 'Nilland-Black', hover: true });

  $('#dyna .swap').each(function(){
    if ($(this).attr('id') == swapto) {
      $(this).show();
    } else {
      $(this).hide();
    };
  });
  // log it
  rcstats.log('#hub/#tabs/'+swapto);
}

$(function(){
  
  // Hide not-first tabs
  $('#dyna #readers.swap').hide();
  
  // Hide the thickbox overlays
  $('.overlay').hide();

  // Manually scale the font-size of the merchant name, based on length
  // 60px max (holds 6 characters)
  // 38px min (good for line breaks)
  // if (Math.round($('#merchant-info h2').text().length) <= 8) {
  //   $('#merchant-info h2').css('font-size','68px');
  // } else if (Math.round($('#merchant-info h2').text().length) >= 18) {
  //   $('#merchant-info h2').css('font-size','38px');
  // };
//  Cufon.replace('#merchant-info h2', { fontFamily: 'Nilland-Black', textShadow: 'rgba(0,0,0,0.5) 2px 2px 0'});
  
  // Stats hooks for AddTo buttons
  $('a.addto').click(function(){
    // log the click
    rcstats.log('#hub/#addto/'+$(this).text());
    // complete the goal
    //rcstats.goal(314);
  });
  
  // Stats hooks for Item clicks
  $('#items-list a.reveal').click(function(){
    // Set the cookie for a clickopen
    document.cookie = "hub_clickopen_"+cid+"=true; expires="+expires+"; path=/; domain="+cdm;
    // Log this in the stats
    rcstats.log('#hub/#items/'+$(this).attr("title"));
  });
  
  // Stats hooks for Video clicks
  $('#reader-split a.watch').click(function(){
    rcstats.log('#hub/#videos/'+$(this).attr("title"));
  });

  // Attach the tabswap function to the tabs
  $('#dyna-tabs li a').click(function(){
    swapTabs($(this).attr('class'));
    return false;    
  });

  // Also attach the tab swap to the top nav link
  $('#header .buttons').find('a.readers, a.shop, a.about, a.contact').click(function(){
    swapTabs($(this).attr('class'));
    return false;
  });
  
  // Also attach the tab swap to the top nav link
  /*
  $('#header .buttons .goback').click(function(){
    // if they came from the merchant's site, send them right back...
    if (document.referrer) {};
    history.back();
    return false;
  })
  */

  // Put us on the shop tab
  //swapTabs('shop');
  
  // Remove breaks from top of price block
  $('.item .prices').each(function(){
    $('br:lt(2)',this).remove();
  });

});