	var interval = 7000;
	var fade_timer = 2000;

	function change_first()
	{
		if ($('.first').size() > 1)
		{
			var current = $('.first:visible:last');
			if (!$(current).prev('.first').is(':visible'))
			{
				$('.first:last').fadeIn(fade_timer, function()
				{
					$('.first').show();
				});
			}
			else
			{
				$(current).fadeOut(fade_timer);
			}
		}
		
		if ($('.third').size() > 1)
		{
			timer = setTimeout(change_third, interval);
		}
		else if ($('.fourth').size() > 1)
		{
			timer = setTimeout(change_fourth, interval);
		}
		else
		{
			timer = setTimeout(change_first, interval);
		}
	}
	
	function change_third()
	{
		if ($('.third').size() > 1)
		{
			var current = $('.third:visible:last');
			if (!$(current).prev('.third').is(':visible'))
			{	
				$('.third:last').fadeIn(fade_timer, function()
				{
					$('.third').show();
				});
			}
			else
			{
				$(current).fadeOut(fade_timer);
			}
		}
		
		if ($('.fourth').size() > 1)
		{
			timer = setTimeout(change_fourth, interval);
		}
		else if ($('.first').size() > 1)
		{
			timer = setTimeout(change_first, interval);
		}
		else
		{
			timer = setTimeout(change_third, interval);
		}
	}
	
	function change_fourth()
	{
		if ($('.fourth').size() > 1)
		{
			var current = $('.fourth:visible:last');
			if (!$(current).prev('.fourth').is(':visible'))
			{
				$('.fourth:last').fadeIn(fade_timer, function()
				{
					$('.fourth').show();
				});
			}
			else
			{
				$(current).fadeOut(fade_timer);
			}
		}
		
		if ($('.first').size() > 1)
		{
			timer = setTimeout(change_first, interval);
		}
		else if ($('.third').size() > 1)
		{
			timer = setTimeout(change_third, interval);
		}
		else
		{
			timer = setTimeout(change_fourth, interval);
		}
	}
	
$(document).ready(function()
{
	change_first();

	$('#date_in').datetimepicker({ showButtonPanel: true, showOn:focus, dateFormat: 'yy-mm-dd', timeFormat: ' hh:ii:ss' });
	$('#date_out').datetimepicker({ showButtonPanel: true, showOn:focus, dateFormat: 'yy-mm-dd', timeFormat: ' hh:ii:ss' });
	$('#date_in').change(function(e)
	{
		var text = $(this).val();
		$('#date_in_link').html(text);
//		$(this).siblings('em').text($(this).val());
	});
	$('#date_out').change(function(e)
	{
		var text = $(this).val();
		$('#date_out_link').html(text);
//		$(this).siblings('em').text($(this).val());
	});
	$("#date_in_link").live("click", function(e)
	{ 
		e.preventDefault();
		$("#date_in").datetimepicker('show'); 
	});
	$('#sel_change').change(function(e)
	{
		$('#cat_txt').text($('#txt_'+$('#sel_change').val()).text());
	});
	$('#do_submit').click(function(e)
	{	
		e.preventDefault();
		var flag = false;
		$.each($('.required'), function(key, value) 
		{ 
			if (!$(value).val())
			{
				flag = true;
			}
		});
		if (!flag)
		{
			if ($("#agreement_flag:checked").val() == "on") {
				document.forms[0].submit();
			} else {
				alert('Вы должны согласиться с условиями бронирования');
			}
		}
		else
		{
			alert('Вы не заполнили все обязательные поля');
		}
	});
	$("#date_out_link").live("click", function(e)
	{ 
		e.preventDefault();
		$("#date_out").datetimepicker('show'); 
	});
	$('.list li').mouseover(function(e)
	{
		$(this).siblings('li').children('p').hide();
		$(this).children('p').show();
	});
	$('.list').mouseleave(function(e)
	{	
		$(this).children('li').children('p').hide();
		$(this).children('li.active').children('p').show();
	});
	$('.list li').click(function(e)
	{
		e.preventDefault();
		$(this).siblings().removeClass('active');
		$(this).addClass('active');
		$(this).parent().children('#val').val($(this).children('p').text());
	});
	$('.i-select:not(#sel_change)').change(function(e)
	{
		if ($(this).val() == 1)
		{
			$('#card_num').slideDown();
		}
		else
		{
			$('#card_num').slideUp();
		}
	});
});
