$(document).ready(function(){
  $("#hps a").bind("click", function(){

    // get id of selected hp
    var hp = $(this).attr('rel');
    var parent = $(this).parent();

    // remove selected advertorials class
    $("#hps.advertorials .col").each(function() {
        $(this).removeClass('selected');
    });

    // hide each advertorial content + toggle chosen advertorial
    $(".hp").each(function() {
      if ($(this).attr('id') == hp)
      {
        $(this).toggle();

        if (($(this).attr('style') == 'DISPLAY: none') || ($(this).attr('style') == 'display: none;'))
        {
          parent.removeClass('selected');
        }
        else
        {
          parent.addClass('selected');
        }
      }
      else
      {
        $(this).hide();
      }
    });

    return false;
  });

  $("#tools a").bind("click", function(){

    // get id of selected hp
    var tool = $(this).attr('rel');
    var parent = $(this).parent();

    // remove selected advertorials class
    $("#tools.advertorials .col").each(function() {
      $(this).removeClass('selected');
    });

    // add selected advertorial
    $(this).parent().addClass('selected');

    // hide each advertorial content + toggle chosen advertorial
    $(".tool").each(function() {
      if ($(this).attr('id') == tool)
      {
        $(this).toggle();

        if (($(this).attr('style') == 'DISPLAY: none') || ($(this).attr('style') == 'display: none;'))
        {
          parent.removeClass('selected');
        }
        else
        {
          parent.addClass('selected');
        }
      }
      else
      {
        $(this).hide();
      }
    });

    return false;
  });
});
