var store_anonymous;

function episode_links(anonymous)
{
  store_anonymous = anonymous;
  
  $("#widget .outlink a").click(function(e)
  {
    /*
     * onclick for links out to watch episodes.
     *
     * We get the URL this link is supposed to go out to, then send that
     * as a parameter to /seen along with the episode ID
     */
    var href = $(this).attr('href');
                                
    if (store_anonymous)
    {
      document.location = href;
    }
    else
    {
      var ep_id = $(this).closest("td").attr('ep_id');    
      document.location = "/seen?" + jQuery.param({id: ep_id, next_url: href});
    }
    
    e.preventDefault();
  })
  
  $(".add_episode_onclick").click(function(e)
  {
    /*
     * use the onclick from the episode details for other elements in the row too
     *
     * We get the URL this link is supposed to go out to, then send that
     * as a parameter to /seen along with the episode ID
     */
    
    var that = $(this).parents("tr").find(".outlink a");
    var href = $(that).attr('href');
    if (store_anonymous)
    {
      document.location = href;
    }
    else
    {
      var ep_id = $(that).closest("td").attr('ep_id');
      document.location = "/seen?" + jQuery.param({id: ep_id, next_url: href});
    }
                                  
    e.preventDefault();
  })

  /* Remove channel 4 extra links */
  $(".double-chevron").empty().remove();              
}
                  

