function zoom() {
    window.location = "#zoom";
    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'facebook'
    });
}
$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'facebook'
    });
	dotsMenu('Food');
	
    //делаем верхнее меню
    $(".mainMenu ul ul").each(function () {
        widthUl=0;
        $(this).children().each(function () {
            widthUl = widthUl+$(this).width()+23;
        });
        $(this).width(widthUl+8);
	});

    //наводим на пукты меню
    $("#mainMenuUl").children('li').children().mouseover(function () {
        if ($(this).is(":first-child")) {
            $(".mainMenu ul ul").each(function () {
            $(this).css('visibility','hidden');
        });
        $("#mainMenuUl").children('li').children().each(function () {
            if ($(this).is(":first-child")) {
                $(this).removeClass('over');
                $(this).addClass('out');
            }
        });
        $(this).removeClass('out');
        $(this).addClass('over');
        $(this).next().css('visibility','visible');
        }
	});

    //нажимаем на контактную информацию
    $('.linkContact').click(
    function () {
        if($('#contactInfo').css("display")=='none') {
            $('#contactInfo').css("display","block");
            $('#formArmoring').css("display","none");
        }
        else{
        $('#contactInfo').css("display","none");
        $('#contactInfoAdd').css("display","none");
        }
    });

    //нажимаем на все телефоны
    $('.allPhoneLink span').click(
    function () {
        if($('#contactInfoAdd').css("display")=="none") $('#contactInfoAdd').css("display","block");
        else $('#contactInfoAdd').css("display","none");
    });

    //все категории
    $('#linkAllCategory').toggle(
            function(){
                $('.menuFoto ul.addCategory').css('display','block');
                $(this).children('span').empty()
                        .append('скрыть категории');
            },
            function(){
                $('.menuFoto ul.addCategory').css('display','none');
                $(this).children('span').empty()
                        .append('показать остальные категории');
            }
            );

    //меню, вина ресторана
    $('.menuRestaurant h2').click(
            function(){
                if($(this).attr('class')!='actTitle') {
                    classBlock = $('.menuRestaurant h2.actTitle').attr('id').substr(5);
                    $("."+classBlock).css('display','none');
                    $('.pdf'+classBlock).css('display','none');
                    classBlockAct = $(this).attr('id').substr(5);
                    $("."+classBlockAct).css('display','block');
                    $('.pdf'+classBlockAct).css('display','inline');
                    $('.menuRestaurant h2.actTitle').removeClass('actTitle');
                    $(this).addClass('actTitle');
                }
                dotsMenu(classBlockAct);
            }
            );
     //гости
	$('.blockGuestFoto a').click(function()
		{
			$('.blockGuestFoto a.guest_act').removeClass('guest_act');
			$(this).addClass('guest_act');
			path = $(this).children('img').attr('src');
			url = $(this).attr('href');
			lastSlash = path.lastIndexOf('/');
			lastUnderline = path.lastIndexOf('_');
			imgId = path.substr(lastSlash+1,lastUnderline-lastSlash-1);
			if(url.indexOf("/en/")==-1) lang="";
			else lang="/en";
			$.ajax({
				method: "get",url: lang+"/ajax/guests/"+imgId,
				success: function(html)
				{
					$(".leftColumnIn").html(html);
				}
			});
		return false;
         });


	   //номера
	$('.menuNumber a').click(function()
		{

			$('.menuNumber a.act').removeClass('act');
			$(this).addClass('act');

			url = $(this).attr('href');
			idRoom = $(this).attr('id').substr(1);
			if(url.indexOf("/en/")==-1) lang="";
			else lang="/en";
			$.ajax({
				method: "get",url: lang+"/ajax/rooms/"+idRoom,
				success: function(html)
				{
					$(".content").html(html);
				}
			});
			$.ajax({
				method: "get",url: lang+"/ajax/rooms_text/"+idRoom,
				success: function(html)
				{
					$("#a_text").html(html);
				}
			});
			$.ajax({
				method: "get",url: lang+"/ajax/rooms_scheme/"+idRoom,
				success: function(html)
				{
					$("#a_scheme").html(html);
				}
			});
			$.ajax({
				method: "get",url: lang+"/ajax/rooms_img/"+idRoom,
				success: function(html)
				{
					$(".blockLittleFoto").html(html);
					gallery();
				}
			});
                        zoom();
		return false;
         });

	   //что посмотреть в рязани
	   if($('.fotoToSee').length) {
			$(".dots a").each(function () {
                if (!$(this).is(":first-child")) {
                    $(this).children('img').css('opacity','0.5');
                }
                else $(this).css("cursor", "default")
							.addClass('act');
            });
	}
	$('.fotoToSee a').click(function()
		{
			$('.fotoToSee .act img').css('opacity','0.5');
			$('.fotoToSee .act').css('cursor','pointer')
								.removeClass('act');
			$(this).children('img').css('opacity','1');
			$(this).css('cursor','default')
					.addClass('act');
			idSee = $(this).attr("id").substr("3");
			$.ajax({
				method: "get",url: lang+"/ajax/ryazan/"+idSee,
				success: function(html)
				{
					$(".fotoText").html(html);
				}
			});
		return false;
         });

	//смена картинки на главной
	if($('#mainFlash').length) {
		k=1;
		r=0;
                setInterval
                (
                        function()
                        {

                                if(k==numFlash) n=1;
	else n=k+1;
	obj = $('#mainFlash .mainImg'+k);
	$('#mainFlash .mainImg'+n).css('left',0)
								.css('display','block');
	$('#mainFlash .mainImg'+n).css('opacity',1);

	obj.animate({"opacity": 0}, 1500,function(){
		obj.css('display','none')
			.css('zIndex','1');
		r=0;
		$('#mainFlash .mainImg'+n).css('zIndex','2');
	});
	if(k!=numFlash) k++;
	else k=1;
	
                        },
                       6000
                );
    }

    //лифт
    if($('#lift').length) {
        floor = 11;
        actArrowUp='liftButtonUpAct.gif';
        ArrowUp='liftButtonUp.gif';
        actArrowDown='liftButtonDownAct.gif';
        ArrowDown='liftButtonDown.gif';
        liftPath=$('#liftNumber').attr('src');
        fLiftPath = liftPath.substr(0,liftPath.lastIndexOf('/')+1);
        $('#liftButton img').click(function()
            {
                if($(this).attr('id')=='liftButtonUp') {
                    if(floor!=11) {
                        liftDirect=1;
                        arrow='liftArrowUp.gif';
                        floor=floor+liftDirect;
                        marginTop="+=248px";
                        liftPanorama(fLiftPath,floor,arrow,actArrowUp,ArrowDown,marginTop);
                    }
                }
                else {
                    if(floor!=1) {
                        liftDirect=-1;
                        arrow='liftArrowDown.gif';
                        floor=floor+liftDirect;
                        marginTop="-=248px";
                        liftPanorama(fLiftPath,floor,arrow,ArrowUp,actArrowDown,marginTop);
                    }
                }
             });
    }
    
    //формы бронирования
    $('#bronLink').click(function(){
    	/*if($(this).parents('.blockArmoring').hasClass('blockArmoring2')) $('.blockArmoring1 form').css('display','none');
    	else $('.blockArmoring2 form').css('display','none');
    	obj = $(this).parent().siblings();
    	if(obj.css('display')=='none') $(this).parent().siblings().css('display','block');
    	else $(this).parent().siblings().css('display','none');*/
        if($('#formArmoring').css('display')=='none') {
            $('#formArmoring').css('display','block');
            $('#contactInfo').css('display','none');
            $('#checkAmoring').css('display','none');
        }
        else $('#formArmoring').css('display','none');
    });

    //проверка бронирования
    $('#hArmoring').click(function(){
    	/*if($(this).parents('.blockArmoring').hasClass('blockArmoring2')) $('.blockArmoring1 form').css('display','none');
    	else $('.blockArmoring2 form').css('display','none');
    	obj = $(this).parent().siblings();
    	if(obj.css('display')=='none') $(this).parent().siblings().css('display','block');
    	else $(this).parent().siblings().css('display','none');*/
        if($('#checkAmoring').css('display')=='none') {
            $('#formArmoring').css('display','none');
            $('#contactInfo').css('display','none');
            $('#checkAmoring').css('display','block');
            $('#bronLink').css('visibility','hidden');
        }
        else {
	    $('#checkAmoring').css('display','none');
            $('#bronLink').css('visibility','visible');
	}
    });
	
    $('#formArmoring a').click(function(){
		//var rnd = Math.floor(Math.random( ) * 1000000);
		//alert(rnd);
    	$.ajax({
			url: "/ajax/booking/",
			global: false,
			type: "POST",
			data: $('#formArmoring').serialize(),
			dataType: 'json',
			success: function(j)
			{
				//$(".ar_s").removeClass('red');
				$(".ar_s").css('color','#333');
				for (var k = 0; k < j.length; k++) {
					if(j[k].optionId=='success')
					{
						$('#formArmoring').html('<div class="success_booking">Ваша заявка отправлена и ей присвоен номер ' + j[k].optionVal + '</div>')
					}
					else
					{
						//$("#f_" + j[k].optionId).addClass('red');
						$("#f_" + j[k].optionId).css('color','#f00');
					}
				}
			}
		});
		return false;
    });
    $('#checkAmoring_a').click(function(){
    	$.ajax({
			url: "/ajax/booking_check/",
			global: false,
			type: "POST",
			data: $('#checkAmoring').serialize(),
			dataType: "html",
			success: function(msg)
			{
				$("#check_result").html(msg);
			}
		});
		return false;
    });

    
    //схема
    /*
    $('.shema a').live("click",function(){
    	$("<img src='"+$(this).attr('href')+"' alt='' id='bigShema'>").appendTo("body");
	return false;
    });
    
    $('#bigShema').live("click",function(){
    	$(this).remove();
    });
                */
});

function liftPanorama(fLiftPath,floor,arrow,ArrowUp,ArrowDown,marginTop){
    $('#liftArrow').attr('src',fLiftPath+arrow);
    $('#liftButtonUp').attr('src',fLiftPath+ArrowUp);
    $('#liftButtonDown').attr('src',fLiftPath+ArrowDown);
    $("#panoramaImg div").animate({"marginTop": marginTop}, "slow",function(){
        $('#liftNumber').attr('src',fLiftPath+floor+'.gif');
        if(ArrowUp='liftButtonUpAct.gif') $('#liftButtonUp').attr('src',fLiftPath+'liftButtonUp.gif');
        if(ArrowDown='liftButtonDownAct.gif') $('#liftButtonDown').attr('src',fLiftPath+'liftButtonDown.gif');
    });
}

/*точки в меню*/
function dotsMenu(vineClass){
	$(".menuDots").each(function () {
		$(this).width('0');
	});
	
	if($('.leftColumnMenu').length) {
		widthLeft = 88;
		$(".leftColumnMenu td .menuDots").each(function () {
			widthDots = 330-($(this).offset().left-widthLeft);
			$(this).width(widthDots);
		});	
	}
	
	if($('.rightColumnMenu').length) {
		widthLeft = $('.'+vineClass+' .rightColumnMenu').offset().left+25;
		$(".rightColumnMenu td .menuDots").each(function () {
			widthDots = 330-($(this).offset().left-widthLeft);
			$(this).width(widthDots);
		});	
	}
}

function mainFlash(numFlash,k,s){
	if(k==numFlash && s==1) n=1;
	else {		
		if(k==1 && s==-1) n=numFlash;
		else n=k+s;
	}
	obj = $('#mainFlash .mainImg'+k);
	$('#mainFlash .mainImg'+n).css('left',0)
								.css('display','block');
	$('#mainFlash .mainImg'+n).css('opacity',1);

	obj.animate({"opacity": 0}, 1000,function(){
		obj.css('display','none')
			.css('zIndex','1');
		r=0;
		$('#mainFlash .mainImg'+n).css('zIndex','2');
	});
	
		/*
	obj.animate({"left": -942*s}, 1000,function(){
		obj.css('display','none')
			.css('zIndex','1');
		r=0;	
		$('#mainFlash .mainImg'+n).css('zIndex','2');
	});
	*/
	if(k!=numFlash) k++;
	else k=1;
	return n;
}

/*function mainFlash(numFlash,k){
	if(k==numFlash) n=1;
	else n=k+1;
	obj = $('#mainFlash .mainImg'+k);
	$('#mainFlash .mainImg'+n).css('top',0)
								.css('display','block');
	obj.animate({"top": 360}, 1500,function(){
		obj.css('display','none')
			.css('zIndex','1');
		$('#mainFlash .mainImg'+n).css('zIndex','2');
	});
	
	kTimer = k;
	if(k!=numFlash) k++;
	else k=1;
	
	
	myTimer = setTimeout("mainFlash("+numFlash+","+k+")", 3000);

	$('#mainFlash').toggle(
	  function () {
	    obj.stop();	
		obj.animate({"top": 0}, 500);
	    clearTimeout(myTimer);
	  },
	  function () {
	    myTimer = setTimeout("mainFlash("+numFlash+","+kTimer+")", 3000);
	  }
	);
}*/

/*function mainFlash(numFlash,k){
	$('#mainFlash img').animate({"opacity": 0.5}, 1500,function(){
	$('#mainFlash div').css('marginTop',-360*k);
	$('#mainFlash img').animate({"opacity": 1}, 1000,function(){
	});
});
	if(k!=numFlash-1) k++;
	else k=0;
myTimer = setTimeout("mainFlash("+numFlash+","+k+")", 3000);
}*/

/*function fillWorks(cnt) {
    $("#middle").append(
        "<div id='work_" + cnt + "' class='works_item'>Привет</div>"
    );
    $("#work_" + cnt).fadeIn('slow');
    cnt = cnt + 1;
    myTimer = setTimeout("fillWorks("+cnt+")", 1000);
}*/

/*min-width для ie*/
var d = document;
var winIE = (navigator.userAgent.indexOf('Opera')==-1 && (d.getElementById && d.documentElement.behaviorUrns)) ? true : false;

function bodySize(){
    if(winIE && d.documentElement.clientWidth) {
    sObj = d.getElementsByTagName('body')[0].style;
    sObj.width = (d.documentElement.clientWidth<1003) ? '1003px' : '100%';
    }
}

function init(){
    if(winIE) {bodySize();}
}
onload = init;
if(winIE) {onresize = bodySize;}
