$(document).ready(function(){
	
	$(".hidden-text,.hidden-text-2").hide();
	$(".hidden-map").hide();
	
	$('.opening-title-2').click(
	   function(e)
	   {
			$('.opening-title-2').each(
			  function()
			  {
				$('.hidden-text-2').stop(true,true);
	      $('.opening-title-2').removeClass("active").parent().next('.hidden-text-2').slideUp(200);
			  }
			);
				var offset = $(this).closest(".chld-cat").find("h3.club").offset();
				$.scrollTo(offset.top +'px', 200, { axis:'y' }); 
				$('.hidden-text-2').find("ul").stop();
				map.redraw();
	   		var marginTop = - $(this).height() - 30 + 'px';
	   		var paddingTop =  $(this).height() + 30 + 'px';
				$(this).parent().next(".hidden-text,.hidden-text-2").css("padding-top",paddingTop);
				$(this).addClass("active").parent().next(".hidden-text,.hidden-text-2").animate({marginTop:marginTop}, 0).slideDown(700);
	   });

	$('.opening-title').toggle(
	   function()
	   {
	   		var marginTop = - $(this).height() - 40 + 'px';
	   		var paddingTop =  $(this).height() + 40 + 'px';
			$(this).parent().next(".hidden-text,.hidden-text-2").css("padding-top",paddingTop);
			$(this).addClass("active").parent().next(".hidden-text,.hidden-text-2").animate({marginTop:marginTop}, 0).slideDown(700);
	   },
	   function()
	   {
	      $(this).removeClass("active").parent().next(".hidden-text,.hidden-text-2").slideUp(500);
	   });
	
	$(".open-map").click(function(){
		$(this).toggleClass("active").parent().next(".hidden-map").slideToggle(700);
	})
	
	var randomBg = Math.floor(Math.random()*3);
	$(".header-bg").addClass("hbg" + randomBg);

	$(".location-table td").click(function(){
		if ($(this).text()) {
  		var col = $(this).parent().children().index($(this)); 
			var dayofweek = $(this).parent().parent().parent().children().find('th:eq(' + col + ')').text();
			var mytime = $(this).text();
			var myclub = $(this).closest(".chld-cat").find("h3.club").text();
			var mygim = $(this).closest(".hidden-text-2").prev("p").text();
			var club_phone = $(this).closest(".hidden-text-2").find(".club_phone").text();
			var club_email = $(this).closest(".hidden-text-2").find(".club_email").text();
			var club_address = $(this).closest(".hidden-text-2").prev("p").find(".club_address").text();
			var coords = $(this).closest(".hidden-text-2").find("input").val();
			/* код заполнения данными скрытых полей формы и отправки */
					$('#reg-form #myclub').val(myclub);
					$('#reg-form #mygim').val(mygim);
					$('#reg-form #dayofweek').val(dayofweek);
					$('#reg-form #mytime').val(mytime);
					$('#reg-form #club_phone').val(club_phone);
					$('#reg-form #club_email').val(club_email);
					$('#reg-form #club_address').val(club_address);
					$('#reg-form #coords').val(coords);
					$("form#reg-form").submit();
		}
	})
});

