$j(function() {
  // Hook up guest follow button as inline register
  $j('#guest_follow_button, .join-link').click(function(e) {
    e.preventDefault();

    $j('#lightbox-register script').remove();
    var ht = $j('#lightbox-register').html();
    showLightbox(ht, {title: "Follow Member", width: 540, table_class: 'lightbox-signup lightbox-blue-bkg'});

    $j.getScript('/javascripts/molt/register.js', function() {
      animateRegisterLabels();
    });
  });

  $j('#follow_button, #unfollow_button').click(function() {
    $j('#follow_button, #unfollow_span').fadeTo('fast', 0.3);
    
    var data = {id: profile_user_id};
    var url = '/account/toggle_follow';

    $j.post(url, data, function(res) {
      if (res == '0') {
        track_event('/profile/unfollow');
        $j('#follow_button').css('display', 'inline');
        $j('#unfollow_span').css('display', 'none');
      } else {
        track_event('/profile/follow');
        $j('#follow_button').css('display', 'none');
        $j('#unfollow_span').css('display', 'block');
      }
      
      $j('#follow_button, #unfollow_span').fadeTo('fast', 1);
    });
  });
  
  var params = {id: profile_user_id};
  
  $j.getJSON(stats_url, params, function(data) {
    $j('#monthly_views').text(data.monthly_views);

    $j('#graph').height(100);

    var graph_data = data.graph_data;

    var options = {
      points: {show:false},
      lines: {show:true},
      xaxis: {ticks: 2, mode: 'time'},
      yaxis: {ticks: 1},
      grid: {borderWidth:0}
    };

    $j.plot($j("#graph"), [{color: '#00adef', shadowSize:0, data:graph_data}], options);
  });
  
  expandableList($j('#expand_vodspots_link'));
  expandableList($j('#expand_collections_link'));
  
  track_event('/profile');
  
//   $j('#user-feed').infiniteScroll('/user/get_activity', {user_id: profile_user_id})
});

expandableList = function(link) {
  link.click(function() {
    link.parent('li').siblings().show();
    link.parent('li').remove();
    return false;
  });
}