function showForm(appartment_name, bShowKatMed) {
	if (bShowKatMed) {
		$('#bronir_kategoriya_v_med_programmah').css('display', 'block');
	}
	$('#overlay').css('height',$(document).height());
	$('#overlay').css('opacity',0).fadeTo('slow', '0.7');
	$('.reserve .header .appartment_name').text(appartment_name);
	$('.reserve input[name="data\[new\]\[kategoriya\]"]').val(appartment_name);
	$('.reserve').css('visibility', 'visible').css('opacity',0).fadeTo('slow', '1');
	_centerPopin();
	$('#overlay, .reserve .header .close').click(function(){
		$('#overlay').fadeOut('slow');
		$('.reserve').fadeOut('slow');
		setTimeout(function(){$('.step1').css('display', 'block')}, 1000);
		setTimeout(function(){$('.step2').css('display', 'none')}, 1000);
	});

	function _centerPopin(){
		if ($.browser.opera) {
			windowHeight = window.innerHeight;
			windowWidth = window.innerWidth;
		}
		else {
			windowHeight = $(window).height();
			windowWidth = $(window).width();
		};

		projectedTop = ($(window).height()/2) - ($('.reserve').height()/2);
		if (projectedTop < 0) {
			projectedTop = 10;
		}

		$('.reserve').css({
			'top': projectedTop,
			'left': ($(window).width()/2) - ($('.reserve').width()/2)
		});
	};
}

function checkForm(s) {
	var res = true;
	if (s == 1) {
		res = checkInputText('data_zaezda');
		if (!$('.reserve input[name*="tip"]:checked').length) {
			$('.reserve input[name*="tip"]').parent('.float').nextAll('.error').css('display', 'block');
			res = false;
		}
		else {
			$('.reserve input[name*="tip"]').parent('.float').nextAll('.error').css('display', 'none');
		}
		if (res) {
			$('.step1').css('display', 'none');
			$('.step2').css('display', 'block');
		}
	}
	if (s == 2) {
		res = checkInputText('familiya');
		res = checkInputText('imya');
		res = checkInputText('otchestvo');
		if (res) {
			$('.reserve form').submit();
		}
	}
	return res;
	
	function checkInputText(name) {
		var res = true;
		if (!$('.reserve input[name*="' + name + '"]').val()) {
			$('.reserve input[name*="' + name + '"]').css('border-color', 'red');
			$('.reserve input[name*="' + name + '"]').parent('.txt_inpt').prev('.error').css('display', 'block');
			res = false;
		}
		else {
			$('.reserve input[name*="' + name + '"]').css('border-color', '#717171');
			$('.reserve input[name*="' + name + '"]').parent('.txt_inpt').prev('.error').css('display', 'none');
		}
		return res;
	}
}


$(document).ready(function(){	
	if ($("#edit").attr("class") != 'act') {
		$("a[rel^='prettyPhoto']").prettyPhoto({
			showTitle: false,
			theme: 'facebook' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		});
	
		$(".pp_hoverContainer").click(function(){
			$.prettyPhoto.close();
		});
	}

	$(".menu table tr td").click(function(event){
		event.preventDefault();
		href = $(this).find('a').attr('href');
		if (href) {
			window.location = href;
		}
	});


	$('.menu table tr td[class!="active"]').mouseover(function(event){
		event.preventDefault();
		rel = $(this).find('a').attr('rel');
		$(this).css('background-image', 'url(' + rel + ')');
		$(this).find('a').toggleClass('none');
	});
	$('.menu table tr td[class!="active"]').mouseout(function(event){
		event.preventDefault();
		$(this).attr('style', '');
		$(this).find('a').toggleClass('none');
	});

	$('td.buble').hover(function(event){
		$(this).find('.bubble').toggleClass('none');
	});


	$(".currency a").click(function(event){
		event.preventDefault();
		$(this).parent().parent().children().children().each(function(index, domEle){
			$(domEle).toggleClass('none');
		});
		$(this).parents('.table, .pass_price').find('tbody tr').toggleClass('none');
		
	});



    // Load the classic theme
    Galleria.loadTheme('/js/grand-marine/galleria.classic.js');
    // Initialize Galleria
	$(window).resize(function(){
		$('#main_body #galleria').galleria({
			preload: 3,
			autoplay: true,
			thumbnails:false,
			carousel: false,
			show_info:false,
			show_counter: false,
			height: 575,
			width: $(window).width(),
			image_crop: 'height',
			image_position: '0 0'
		});
	});
	$('#main_body #galleria').galleria({
		preload: 3,
		autoplay: true,
		thumbnails:false,
		carousel: false,
		show_info:false,
		show_counter: false,
		height: 575,
		width: $(window).width(),
		image_crop: 'height',
		image_position: '0 0'
	});

	$(window).resize(function(){
		$('#inner_body #galleria').galleria({
			preload: 3,
			autoplay: true,
			thumbnails:false,
			carousel: false,
			show_info:false,
			show_counter: false,
			height: 198,
			width: $(window).width(),
			image_crop: 'height',
			image_position: '0 0'
		});
	});
	$('#inner_body #galleria').galleria({
		preload: 3,
		autoplay: true,
		thumbnails:false,
		carousel: false,
		show_info:false,
		show_counter: false,
		height: 198,
		width: $(window).width(),
		image_crop: 'height',
		image_position: '0 0'
	});




	pause = false;
	$("#jCarouselLite").jCarouselLite({
		auto: 1000,
		speed: 1000,
		visible: 5
	});

	$("#jCarouselLite img").hover(function(){
		$(this).fadeTo('100', 0.33);
		pause = true;
	}, function(){
		$(this).fadeTo('100', 1);
		pause = false;
	});
	
	$(function() {
		$('.reserve input[name="data\[new\]\[data_zaezda\]"]').datepicker();
	});
	$(function() {
		$('.reserve input[name="data\[new\]\[data_vyezda\]"]').datepicker();
	});

	$(".dop_info a").click(function(event){
		event.preventDefault();
		$(this).parent().next().toggleClass('none');
	});

	$('.weather-body').html('<img style="margin-left:75px; margin-top:45px;" src="/img/ajax-loader.gif" alt="" />');
	$.post("/weather.php",
		function(data){
			$('.weather-body').html(data);
		}
	);
	
	$(".slide").each(function(){  
		$(".slide[rel='" + $(this).attr("rel") + "']").not(":first").remove()  
	});
	
	$('#slider').slides({
				preload: true,
				preloadImage: '/img/ajax-loader.gif',
				generatePagination: false,
				play: 5000,
				pause: 5000,
				hoverPause: true,
				// Get the starting slide
				start: 1
			});


});
