$(document).ready(function() {

  $('.toggle-leader').click(function() {
    var d = $(this).attr('leader');
    var t1 = $(this).attr('textdown');
    if(!$('.toggle-content[leader=' + d + ']').is(":visible")) {
      $(this).addClass('down selected');
      $(this).removeClass('up');
      $(this).html(t1);
      $('.toggle-content[leader=' + d + ']').slideDown('fast');
    }else{
      var d = $(this).attr('leader');
      var t2 = $(this).attr('textup');
      $(this).html(t2);
      $(this).addClass('up');
      $(this).removeClass('down selected');
      $('.toggle-content[leader=' + d + ']').slideUp('fast');
    }
  });

  $('.dropbox-leader').click(function(event) {
    var x = $(this).attr('dropbox');
    $('#' + x + '-content').toggle();

    // Stop pagination in content. Meaning clicking in the content wont hide it.
    $('#' + x + '-content').click(function(event) {
      event.stopPropagation();
    });

    // Clicking anywhere in the body hides the content
    $('html').one('click', function() {
      $('#' + x + '-content').hide();
    });

    // Stop leader-clicks from hiding the content
    event.stopPropagation();
  });

  //$('.dropbox-content a').click(function(){
    //$(this).html('Updating...');
  //});
  
});

