﻿$(document).ready(function(){

/*
(function ($){
        var shObj = $('#slideshowHolder'),
                bnImg = /20\.jpg/, // file name of banner, in RE-notation
                hsSel = $('#hollywars1, #hollywars2'),
                alObj = true,
                tmInd = setInterval(function (){
                        var fn = bnImg.test(shObj.attr('style'));
                        if (alObj != fn){
                                alObj = fn;
                                hsSel[fn ? 'fadeIn' : 'fadeOut'](300);
                        }
                }, 500);
})(jQuery);
*/

	$.fn.alignCenter = function() {
 var marginLeft = Math.max(0, parseInt($(window).width()/2 - $(this).width()/2)) + 'px';
 var marginTop = Math.max(20, parseInt($(window).height()/2 - $(this).height()/2)) + $(window).scrollTop() + 'px';
 return $(this).css({'margin-left':marginLeft, 'margin-top':marginTop, 'top':0, 'left':0});
	};
	$(".phone-link").click(function () {
	$("#popup-contact").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".label").click(function () {
	$("#price-apartament").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".price").click(function () {
	$("#price-apartament").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".call-link").click(function () {
	$("#popup-call").fadeIn(700);
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item1").click(function () {
	$("#info1").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item2").click(function () {
	$("#info2").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item3").click(function () {
	$("#info3").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item4").click(function () {
	$("#info4").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item5").click(function () {
	$("#info5").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item6").click(function () {
	$("#info6").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item7").click(function () {
	$("#info7").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item8").click(function () {
	$("#info8").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	

		$(".item11").click(function () {
	$("#info11").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	
	
	$(".item12").click(function () {
	$("#info12").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item13").click(function () {
	$("#info13").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item14").click(function () {
	$("#info14").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item15").click(function () {
	$("#info15").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item16").click(function () {
	$("#info16").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item17").click(function () {
	$("#info17").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});
	$(".item18").click(function () {
	$("#info18").fadeIn(700).alignCenter();
	$('#opaco').height($(document).height());
	return false;
	});

	$(".close").click(function () {
		$(this).parent().fadeOut(500);
		$('#opaco').height(0);
		return false;
	}); 
	$("#opaco").click(function () {
		$(".popup-contact").fadeOut(500);
		$("#price-apartament").fadeOut(500);
		$(".popup-plan").fadeOut(500);
		$("#popup-call").fadeOut(500);
		$('#opaco').height(0);
		return false;
	});
    $(".gallery-nav a").click(function(){
        var largePath = $(this).attr("href");
        var largeAlt = $(this).attr("title");
        $(".largeImg").attr({ src: largePath, alt: largeAlt });
        $(".text-info").html( largeAlt );
		$(".gallery-nav li").removeClass("active");
		$(this).parent().toggleClass("active"); return false;
    });
    $(".nav-plan a").click(function(){
        var largePath = $(this).attr("href");
        $(".plan-img").attr({ src: largePath});
		$(".nav-plan li").removeClass("active");
		$(this).parent().toggleClass("active"); return false;
    });
	
	function sendFeedback(type, data, name, email, time){
			$.post("ajax_new.php", { type: type, data: data, name: name, email: email, time: time},
			function(){
				alert('Ваше сообщение отправлено. Мы обязательно вам ответим.');
				//evt.preventDefault();
				//return false;
			})	
	}	
	
	$('#popup-call form').submit(function(){
		var name = $('#name').val();
		var phone = $('#phone').val();
		var time = $('#time').val();
		var type = 'call';
		
		sendFeedback(type, phone, name, '', time);
		return false;
	})
	
	$('#ask-form').submit(function(){
		var name = $('#name').val();
		var email = $('#email').val();
		var data = $('#text').val();
		var type = 'ask';
		
		sendFeedback(type, data, name, email, '');
		return false;
	})	
	
	$('#zakaz-form').submit(function(){
		var name = $('#name').val();
		var email = $('#email').val();
		var data = $('#text').val();
		var type = 'zakaz';
		
		sendFeedback(type, data, name, email, '');
		return false;
	})	
	
	$('#show_add_content').click(function(evt){
		if($('#main_content').is(':visible')) {
			$('#main_content').hide();
			$('#show_add_content').text('читать полностью');
		} else {
			$('#main_content').show();
			$('#show_add_content').text('скрыть');			
		}
		evt.preventDefault();
		return false;		
	})
	
	$("#l1_a").click(function () {
		$("#l1").slideToggle();
		return false;
	});
	

})


