/* 
	file:	yinbe.form.js
	purpose: file contains code for the health score form
	author:	Parag Jagdale (www.un-identified.com)
*/

$(function(){
  $('input.subfieldTrigger').change(function(){
    if($(this).is(':checked')){
      var elementClassToOpen = $(this).attr('data');
      if(elementClassToOpen != undefined){
        elementClassToOpen = "." + elementClassToOpen;
        var elementToShow = $(this).closest('div.field').find(elementClassToOpen);
        if(elementToShow.hasClass('subfield')){
          $(elementToShow).addClass('show');
        }
      }else{
        // If elementClassToOpen is undefined, then just close every subfield
        var elementsToHide = $(this).closest('div.field').find('.subfield');
        $(elementsToHide).each(function(){
          if($(elementsToHide).hasClass('show')){
            $(elementsToHide).removeClass('show');
          }
        });
      }
    }
  });

  $('a.addmeal').click(function(e){
    var showedTime = $(this).closest('.fields').find('li.show').next();
    var numberHiddenTimes = 0;
    showedTime.addClass('show');
    $(this).closest('.fields').find('li').each(function(){
      if(!$(this).hasClass('show')){
        numberHiddenTimes++;
      }
    });
    if(numberHiddenTimes == 0){
      $(this).hide();
    }
    e.preventDefault();
  });

  $('a.testimonial').click(function(e){
    e.preventDefault();
    $(this).closest('div.testimonials').find('blockquote').removeClass('show');
    var testimonialId = $(this).attr('id');
    $(this).closest('div.testimonials').find('blockquote.' + testimonialId).addClass('show');
    $(this).parent().siblings().removeClass('current');
    $(this).parent().addClass('current');
  });

  
});


