$(document).ready(function() {
  
  if($("#tab_container").length){
    var search_banner_no = $("#tab_container").attr("class").substr($("#tab_container").attr("class").length - 1, $("#tab_container").attr("class").length);
  }
  
  // Begin tabs for homepage
  // Hide all of them
  $("#tab_container .job_tab").hide();
  
  // Show the first one
  $("#tab_container .job_tab:first").show();
  
  // Add id as class
  var first_class = $("#tab_container .job_tabs_list li:first").attr('id');
  $("#tab_container .job_tabs_list li:first").addClass(first_class);

  // Pop a click handler on each link
  $("#tab_container ul.job_tabs_list li a").click(function() {
    // Get the id of the parent LI
    var li_id = $(this).parent().attr('id');
    
    // Remove _list from the id
    var id = li_id.substr(0, li_id.length - 5);
    
    // Hide them all again
    $("#tab_container .job_tab").hide();
    // Remove active class
    $("#tab_container .job_tabs_list li").removeClass();
    $("#tab_container").removeClass();
    
    // And finally show the one that links to the clicked thing
    $("#tab_container #" + id).show();
    // Plus add active class
    $("#"+li_id).addClass(li_id);
    // Change BG
    $("#tab_container").addClass(id + "_bg_" + search_banner_no);
    
    // Stop the event from propogating back, stop the link from being a link :)
    return false;
  });
  
  // Begin tabs for sidebar right
  // Hide all of them
  $("#right_tab_container .right_tab").hide();
  
  // Show the first one
  $("#right_tab_container .right_tab:first").show();
  
  // Add id as class
  var first_class = $("#right_tab_container .right_tabs_list li:first").attr('id');
  $("#right_tab_container .right_tabs_list li:first").addClass(first_class);

  // Pop a click handler on each link
  $("#right_tab_container ul.right_tabs_list li a").click(function() {
    // Get the id of the parent LI
    var li_id = $(this).parent().attr('id');
    
    // Remove _list from the id
    var id = li_id.substr(0, li_id.length - 5);
    
    // Hide them all again
    $("#right_tab_container .right_tab").hide();
    // Remove active class
    $("#right_tab_container .right_tabs_list li").removeClass();
    
    // And finally show the one that links to the clicked thing
    $("#right_tab_container #" + id).show();
    // Plus add active class
    $("#"+li_id).addClass(li_id);
    
    // Stop the event from propogating back, stop the link from being a link :)
    return false;
  });
  
  $(".profile_roll li dl").hide();
  $(".profile_roll li").click(function() {
    //$(this).children("dl").show();
    var profile = $(this).clone();
    profile.attr('title', profile.children('h3').text());
    profile.append('<p class="hidden closeWindow"><a href="">Close window</a></p>');
    profile.children('dl').show();
    profile.children('p.hidden').removeClass('hidden');
    profile.children('p.close-window a').click(function() {
      $(this).parent().parent().dialog('close');
      return false;
    });
    profile.dialog({modal: true, width: 500});
    //$(this).children("dl").hide();
  });
});

