$().ready(function() {

$(window).load(function () {
 $('.numRooms').change();
});

$('.searchTabs li a').click(function() {
  $('.searchForms').children('div').addClass("hidden");
  $('.searchForms').children('div#' + $(this).parent().attr("id") + 'Form').removeClass("hidden");
});


$('.numRooms').change(function() {

  var numRooms = this.value;						   
 $(this).parent().parent().children("li.roomsListing").children("ul").children("li").each(function(i){
    if (i >= numRooms)
		{
		  $(this).addClass('hidden');
		  resetRoom(this);
		}
		else 
		{
		  $(this).removeClass('hidden');
		  $('.numInfants').change();
		  $('.numChildren').change();
		}
      });
});


//TJH control number of infant ages displayed
$('.numInfants').change(function() {
								 
  var numPax = this.value;

  if(this.value > 0) {showAgeInfo($(this).parent().children(".ageDetails").children(".infantAges"),numPax);}
  else {hideAgeInfo($(this).parent().children(".ageDetails").children(".infantAges"));}
});
  
//TJH control number of child ages displayed
$('.numChildren').change(function() {
  var numPax = this.value;
  if(this.value > 0) {showAgeInfo($(this).parent().children(".ageDetails").children(".childAges"), numPax);}
  else {hideAgeInfo($(this).parent().children(".ageDetails").children(".childAges"));}
});




function resetRoom(room)
{
  $(room).children(".numAdults").val(2);
  $(room).children(".numChildren").val(0);
  $(room).children(".numInfants").val(0);
}
  
function showAgeInfo(className, numPax)
{
  className.css("display", "block");

  className.children("select").each(function(i){
									 
    if (i >= numPax) {$(this).addClass("hidden");}
    else {$(this).removeClass('hidden');}
  });
}
  
function hideAgeInfo(className)
{
  className.css("display", "none");
}
	
});
			
