﻿

$(document).ready(function() {

  if ($('.HideShowButton').length > 1) {  // only show if there is more than one section

    // create show all and hide all buttons
    $('#MetaStockTrainingVideos p#firstPara').after('<div id="ShowAllHideAll" style="padding: 0 0 5px 20px;"></div>');
    $('<span id="hideAll" class="button copy" style="text-decoration: underline; cursor: pointer; padding: 0 0 0 15px;" title="Click to hide all videos">hide all videos</span>').appendTo('#ShowAllHideAll');
    $('<span id="showAll" class="button copy" style="text-decoration: underline; cursor: pointer; padding: 0 0 0 15px;" title="Click to display all videos">show all videos</span>').appendTo('#ShowAllHideAll');

    // close up extra space - cursor to pointer over buttons - hide tables
    $('.TabbedPanelsContent table').css("margin-bottom", 3);
    $('.HideShowButton').css("cursor", "pointer").next().hide();

    // toggle button clicks
    $('.HideShowButton').toggle(function() {
      $(this).addClass("plus").removeClass("minus").next().fadeOut(300);
    }, function() {
      $(this).addClass("minus").removeClass("plus").next().fadeIn("normal");
    });

    // all tables hidden - add plus class - click Basic Training videos open  
    $('.HideShowButton').addClass("plus").trigger("click");
    $('.HideShowButton').next().hide();
    $('.HideShowButton:first').trigger("click");

    // show all videos
    $('#showAll').click(function(event) { $('.plus').trigger('click'); });

    // hide all videos
    $('#hideAll').click(function(event) { $('.minus').trigger('click'); });

    var $totalVideos = $('.HideShowButton').length;
    // console.log($totalVideos);
    if ($('.HideShowButton').length < 2) $('.HideShowButton').removeClass("plus").removeClass("minus").css("cursor", "default").unbind();

    // zebra stripe tables
    $('table.zebra tr:odd').addClass('odd');
    $('table.zebra tr:even').addClass('even');

  };
});

