jQuery(document).ready(function() {
    jQuery('div.functions-filter').children('ul.tabs').children('li').children('a').click(function() {
        var oElement = jQuery(this);
        var sRel = oElement.attr('rel');
        oElement.parent().parent().children('li').removeClass('current');
        oElement.parent().addClass('current');
        jQuery('div.functions-group').hide();
        jQuery('div#'+ sRel).show();
        vCleanupAccordions();
        return false;
    });

    jQuery('a.accordion-button-open').click(function() {
        vCleanupAccordions();
        
        var oElement = jQuery(this);
        oElement.hide().parent().children('a.accordion-button-close').show();
        
        oElement.parent().parent().children('div.accordion').show();
        
        oElement.parent().children('div.functions-video').hide();
        
        return false;
    });
    
    jQuery('a.accordion-button-close').click(function() {
        vCleanupAccordions();
        return false;
    });
    
    var vCleanupAccordions = function() {
        //clean up all accordions
        jQuery('div.accordion').hide();
        jQuery('a.accordion-button-close').hide();
        jQuery('a.accordion-button-open').show();
        jQuery('div.functions-video').show();
    };
    
    // function for pre-select and change events
    var filterAwardsByProduct = function() {
        if(jQuery('div.awards-filter').children('select').length < 1)
        {
          return;
        }
        var sFilterValue = jQuery('div.awards-filter').children('select').attr('value');
        vCleanupAccordions();
        
        
        if(sFilterValue == 'all')
        {
          jQuery('div.awards-item').show();
        }
        else
        {
          var aItems = jQuery('div.awards-item').hide().filter('.'+sFilterValue);
          aItems.show();
        
          if(aItems.length < 1)
          {
            jQuery('div.awards-no-items').show();
          }
          else
          {
          jQuery('div.awards-no-items').hide();
          }
        }
        return false;
    }
    
    // change event for product dropdown
    jQuery('div.awards-filter').children('select').change(filterAwardsByProduct);
    filterAwardsByProduct();
});
