$(document).ready(function(){
	// ie grid fix
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$(".col1of2>.inside").css("padding","0 9px 0 0");
		$(".col2of2>.inside").css("padding","0 0 0 9px");

		$(".col1of3>.inside").css("padding","0 12px 0 0");
		$(".col2of3>.inside").css("padding","0 6px");
		$(".col3of3>.inside").css("padding","0 0 0 12px");
		$(".col12of3>.inside").css("padding","0 6px 0 0");
		$(".col23of3>.inside").css("padding","0 0 0 6px");

		$(".col1of4>.inside").css("padding","0 12px 0 0");
		$(".col2of4>.inside").css("padding","0 6px");
		$(".col3of4>.inside").css("padding","0 6px");
		$(".col4of4>.inside").css("padding","0 0 0 12px");
		$(".col12of4>.inside").css("padding","0 12px 0 0");
		$(".col23of4>.inside").css("padding","0 6px");
		$(".col34of4>.inside").css("padding","0 0 0 12px");
		$(".col123of4>.inside").css("padding","0 6px 0 0");
		$(".col234of4>.inside").css("padding","0 0 0 6px");
		
		$(".col1of5>.inside").css("padding","0 12px 0 0");
		$(".col2of5>.inside").css("padding","0 6px");
		$(".col3of5>.inside").css("padding","0 6px");
		$(".col4of5>.inside").css("padding","0 6px");
		$(".col5of5>.inside").css("padding","0 0 0 12px");
		
		$(".col12of5>.inside").css("padding","0 12px 0 0");
		$(".col123of5>.inside").css("padding","0 12px 0 0");
		$(".col1234of5>.inside").css("padding","0 6px 0 0");
		$(".col23of5>.inside").css("padding","0 6px");
		$(".col234of5>.inside").css("padding","0 6px");
		$(".col2345of5>.inside").css("padding","0 0 0 12px");
		$(".col34of5>.inside").css("padding","0 6px");
		$(".col345of5>.inside").css("padding","0 0 0 12px");
		$(".col45of5>.inside").css("padding","0 0 0 12px");
	};
	//eq height
	function equalHeight(group) {
		var tallest = 0;
		group.each(function(){tallest = Math.max($(this).height(), tallest);});
		group.height(tallest);
	};
	equalHeight($("#footer .height-helper"));
	
	//tabs
	$(".tabbed-selection-menu li").click(function() {
		var attr = $(this).find("a").attr("href");
		$(".tabbed-selection-menu li").removeClass("active");
		$(this).addClass("active");
		$(".tabbed-selection-content").hide();
		$(attr).fadeIn();
		return false
	});
	
	subRegionsListInit();
	subRegionDirectionsInit();
	
	var tabItemWidthSum = 0;
	$(".tabs ul").each(function() {
		$(this).children("li").each(function(i) {
			tabItemWidthSum += $(this).outerWidth()
		});
		var next = $(this).prev(".tabs-overflow").find(".next");
		var prev = $(this).prev(".tabs-overflow").find(".prev");
		var tabLiWidth = $("li",$(this)).outerWidth();
		var outerWidth = $(this).parent(".tabs").outerWidth();
	});
	$(".tabs ul").css("width",tabItemWidthSum);
	
	// editable overlay
	// function showEdiableOverlay () {
	// 	$(".editable").each(function() {
	// 		var editableHeight = $(this).height()-2;
	// 		var editableWidth = $(this).width()+8;
	// 		$(".edit-overlay",$(this)).css({
	// 			"height":editableHeight,
	// 			"width":editableWidth
	// 		})
	// 	});	
	// }
	// showEdiableOverlay()
	// $(window).resize(function() {
	// 	showEdiableOverlay()
	// });
	// $("#show-settings-overlay").click(function() {
	// 	$(".edit-overlay,.settings-menu").toggle();
	// });
	// $(".close-overlay").click(function() {
	// 	$(this).parents(".edit-overlay,.settings-menu").fadeOut()
	// 	return false
	// });
	
	// search box
	var filterBox = $("#nav .filter-box");
	var filterLink = $("#nav .search");
	filterLink.click(function() {
		$(this).toggleClass("active");	
		filterBox.toggle();
		$(".edit-overlay").hide();
		return false
	});
	
	// navigation
	$("#nav .close").click(function() {
		if ($.browser.msie && $.browser.version.substr(0,1)<8) {
			$("#nav .filter-box").hide();
		} else {
			$("#nav .filter-box").slideUp("fast");
		}
		$("#nav .search").removeClass("active");
	});
	
	// hidden ad
	 if ($.browser.msie) {
	 	$(".hidden-ad").delay(2000).hide();
	 	$(".hidden-ad-trigger").hover(function() {$(".hidden-ad").show()}, function() {});
	 	$(".hidden-ad-box").hover(function() {$(this).show()}, function() {$(".hidden-ad").hide()});
	 } else {
	 	$(".hidden-ad").delay(2000).fadeOut();
	 	$(".hidden-ad-trigger").hover(function() {$(".hidden-ad").fadeIn()}, function() {});
	 	$(".hidden-ad-box").hover(function() {$(this).show()}, function() {$(".hidden-ad").fadeOut()});
	 }
	
	// tabs
	$('.tabs ul li').click(function(){ 
		$(this).parent("ul").find("li").removeClass("active");
		$(this).addClass('active'); 
		var currentTab = $("a",$(this)).attr('href'); 
		$(this).parents(".tabbed-box").find('.tabbed-content').hide();
		$(currentTab).fadeIn();
		return false;
	});
	
	$(".filter-menu li").click(function() {
		$(".filter-menu li").removeClass("active");
		//$(".filter-submenu li:first").addClass("active");
		$(this).addClass("active");
		var currentLink = $("a",$(this)).attr('href');
		$(this).parents(".filter-menu").next(".filter-submenus").find(".filter-submenu").hide();
		$(currentLink).fadeIn();
		$(this).parents(".filter-menu").next(".filter-submenus").next(".filters-forms").find(".filters-form").hide();
		$(this).parents(".filter-menu").next(".filter-submenus").next(".filters-forms").find(".filters-form:first").fadeIn();
		searchTypeSwitcherCallback(this);
		return false
	});
	$(".filter-submenu li").click(function() {
		$(this).addClass("active");
		$(this).nextAll("li").removeClass("active");
		$(this).prevAll("li").removeClass("active");

		searchFormSwitcherCallback(this);

		//var currentLink = $("a",$(this)).attr('href');
		//$(this).parents(".filter-submenus").next(".filters-forms").find(".filters-form").hide();
		//$(currentLink).fadeIn();

		//$('#customSearchFields').hide();
		return false
	});
	$(".rooms li").click(function() {
		$(this).toggleClass("selected");
		return false
	});
	$("#nav .attach").click(function() {
		if (window['attachFormFlag'] === undefined) window['attachFormFlag'] = false;
		$("#nav .filter-box").show();
		$("#nav .filter-box").toggleClass("attached");
		$("#nav .search").addClass("active");

		if (window['attachFormFlag'])
		{
			$("#nav .filter-box-foot,#nav .filters").slideDown("fast");
			this.innerHTML = 'Свернуть';
		}
		else
		{
			$("#nav .filter-box-foot,#nav .filters").slideUp("fast");
			this.innerHTML = 'Развернуть';
		}
		window['attachFormFlag'] = !window['attachFormFlag'];
	})
	
	// input focus blur
	
	$('input[type=text],input[type=password],input[type=search],textarea').focus(function() {
		if(this.value == this.defaultValue){this.value='';}
		if(this.value != this.defaultValue){this.select();}
	});
	$('input[type=text],input[type=password],input[type=search],textarea').blur(function() {
	    if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	
	// 	modal bosex
	if (jQuery('.modal-gallery').length>0) {
		jQuery('.modal-gallery').jqm({trigger: '.modal-gallery-trigger'});	
	};
    $(".modal-gallery-trigger").click(function(){
        $("img[src1]").each(function(){
            this.src=$(this).attr('src1'); // отложенная загрузка изображений
    });
    });
	if (jQuery('.modal-city-selection').length>0) {
		jQuery('.modal-city-selection').jqm({trigger: '.city-selection-trigger'});
	};
	if (jQuery('.modal-subway-selection').length>0) {
		jQuery('.modal-subway-selection').jqm({trigger: '.subway-selection-trigger'});
	};
	if (jQuery('.modal-columnisty-settings').length>0) {
		jQuery('.modal-columnisty-settings').jqm({trigger: '.modal-columnisty-settings-trigger'});
	};
	if (jQuery('.modal-map').length>0) {
		jQuery('.modal-map').jqm({trigger: '.modal-map-trigger'});	
	};
	if (jQuery('.modal-bonus').length>0) {
		jQuery('.modal-bonus').jqm({trigger: '.modal-bonus-trigger'});
	};
	if (jQuery('.modal-abuse').length>0) {
		jQuery('.modal-abuse').jqm({trigger: '.modal-abuse-trigger'});
	};
    if (jQuery('.modal-lowcost').length>0) {
		jQuery('.modal-lowcost').jqm({trigger: '.modal-lowcost-trigger'});
	};
    if (jQuery('.modal-noobject').length>0) {
		jQuery('.modal-noobject').jqm({trigger: '.modal-noobject-trigger'});
	};	
    if (jQuery('.modal-notfiz').length>0) {
		jQuery('.modal-notfiz').jqm({trigger: '.modal-notfiz-trigger'});
	};
    if (jQuery('.modal-honest').length>0) {
		jQuery('.modal-honest').jqm({trigger: '.modal-honest-trigger'});
	};
	if (jQuery('.modal-compare').length>0) {
		jQuery('.modal-compare').jqm({trigger: '.modal-compare-trigger'});
	};
	if (jQuery('.modal-compare-if').length>0) {
		jQuery('.modal-compare-if').jqm();
	};
	if (jQuery('.modal-notepad').length>0) {
		jQuery('.modal-notepad').jqm({trigger: '.modal-notepad-trigger'});
	};
	

	if (jQuery('.modal-advup').length>0) {
		jQuery('.modal-advup').jqm({trigger: '.modal-advup-trigger'});
	};
	if (jQuery('.modal-advpick').length>0) {
		jQuery('.modal-advpick').jqm({trigger: '.modal-advpick-trigger'});
	};
	if (jQuery('.modal-advdt').length>0) {
		jQuery('.modal-advdt').jqm({trigger: '.modal-advdt-trigger'});
	};
	if (jQuery('.modal-advup-result').length>0) {
		jQuery('.modal-advup-result').jqm({trigger: '.modal-advup-result-trigger'});
	};
	if (jQuery('.modal-advdt-result').length>0) {
		jQuery('.modal-advdt-result').jqm({trigger: '.modal-advdt-result-trigger'});
	};
	
	$(".popup-cat-selection-trigger").click(function() {
		if ($.browser.msie) {
			$(".popup-cat-selection-box").show();
		} else {
			$(".popup-cat-selection-box").fadeIn("fast");
		}
		return false
	});
	$(".popup-cat-selection-box .close-trigger").click(function() {
		if ($.browser.msie) {
			$(".popup-cat-selection-box").hide();
		} else {
			$(".popup-cat-selection-box").fadeOut("fast");
		}
		return false
	});
	
	// $(".popup-cat-menu li").click(function() {
	// 	var t = $(this);
	// 	var text = t.children().text();
	// 	$(".popup-cat-menu li").removeClass("selected");
	// 	t.addClass("selected");
	// 	$(".popup-cat").children().html(text);
	// 	return false
	// });

	$(".tabs-menu li").click(function() {
		var tab = $(this);
		var attr = tab.find("a").attr("href");
		tab.nextAll().removeClass("active");
		tab.prevAll().removeClass("active");
		tab.addClass("active");
		$(attr).fadeIn();
		$(attr).nextAll(".tabs-content").hide();
		$(attr).prevAll(".tabs-content").hide();
		return false
	});
	$(".tabs-menu-safe li").click(function() {
		var tab = $(this);
		var attr = tab.find("a").attr("href");
		tab.nextAll().removeClass("active");
		tab.prevAll().removeClass("active");
		tab.addClass("active");
		$(attr).removeClass("safe-hide");
		$(attr).nextAll(".tabs-content-safe").addClass("safe-hide");
		$(attr).prevAll(".tabs-content-safe").addClass("safe-hide");
		return false
	});
	
	/*if ($(".featured-offer-item").length>4) {
		$(".featured-offers-control").show()
	};*/
	
	// regions list
	$(".region-list").each(function() {
		var t = $(this);
		t.find("li:gt(9)").hide()
		if (t.find("li").length>10) {
			t.after('<div class="show-all-regions"><a rel="nofollow" href="#">Раскрыть полностью</a></div>')
		};
		$(".show-all-regions").toggle(function() {
			var t = $(this);
			t.prev(".region-list").find("li").fadeIn();
			t.find("a").html("Скрыть")
			return false
		}, function() {
			var t = $(this);
			t.prev(".region-list").find("li:gt(9)").hide();
			t.find("a").html("Раскрыть полностью")
			return false
		});
	});
	
	$(".show-all-regions").click(function() {
		
	});
	
	$(".consult-content .dt,.consult-content .dd").live('click', function(){
		if($(".hellip",$(this)).is(":visible")) {
				$(".hellip",$(this)).addClass("hide")
				$(".full",$(this)).fadeIn()
				$(".short",$(this)).addClass("expanded")
		}else {
				$(".hellip",$(this)).removeClass("hide")
				$(".full",$(this)).hide()
				$(".short",$(this)).removeClass("expanded")
		};
	});
	$(".consult-content .dt,.consult-content .dd").each(function() {
		if ($(".full",$(this)).length>0) {
			$(".full",$(this)).parent().find(".short").addClass("has-full")
		};
	});
	
	// 
	$(".ad-photo-body a").hover(function() {
		$(this).find(".ad-photo-overlay").fadeIn()
	}, function() {
		$(this).find(".ad-photo-overlay").fadeOut()
	});
	
	// count photos
	$("#ad-photo-count").text($("#ad-photo-slider img").size())
	
	// 
	$(".more-link").toggle(function() {
		t = $(this);
		t.prev(".more-text").fadeIn("fast")
		t.text("Скрыть")
		return false
	}, function() {
		t = $(this);
		t.prev(".more-text").hide()
		t.text("Описание полностью")
		return false
	});
	$(".more-link").toggle(function() {
		t = $(this);
		t.prev(".more-ad-text").fadeIn("fast")
		t.text("Скрыть")
		return false
	}, function() {
		t = $(this);
		t.prev(".more-ad-text").hide()
		t.text("Далее")
		return false
	});
	//
	$(".agent-consults .question").click(function() {$(this).parent("dt").next("dd").slideToggle("fast");return false});
	$(".agent-consults .answer").click(function() {$(this).parent("dd").slideUp("fast");return false});
	//
	$(".order-subject-selection li").click(function() {
		$(this).toggleClass("selected");
		if ($(".order-subject-selection .selected").length>0) {
			$(".order-service *[disabled]").removeAttr("disabled");
		} else if($(".order-subject-selection .selected").length == 0) {
			$(".order-service input,.order-service textarea").attr("disabled","disabled");
		};
		return false
	});
	$(".order-subject-selection li:nth-child(4n+5)").before("<li class='clearing'></li>");
	
	$(".currency-type").click(function() {
		t = $(this)
		$(".currency-type").removeClass("active-type")
		t.addClass("active-type")
		a = t.attr("id");
		$(".currency-summ").removeClass("active-summ");
		$("#"+a+"-summ").addClass("active-summ");
		$(".currency-price-per-unit").removeClass("active-price-per-unit");
		$("#"+a+"-per-unit").addClass("active-price-per-unit");
		
	});
	
	function fullSearchResultsItemWidth() {
		fullSearchResultsWidth = $(".full-width-results .search-results-list").width()
		liWidth = fullSearchResultsWidth/6;
		$(".full-width-results li").css("width",liWidth)
		li = $(".full-width-results li")		
		// $(".full-width-results li:nth-child(6n+6)").css({
		// 	"width":liWidth-12,
		// 	"overflow":"hidden"
		// })
	}
	fullSearchResultsItemWidth()
	$(window).resize(function() {
		fullSearchResultsItemWidth()
	});
	// side menu
	$("li.has-sub-menu>a").click(function() {
		t = $(this).parent("li");
		t.nextAll().removeClass("expanded")
		t.prevAll().removeClass("expanded")
		t.toggleClass("expanded")
		return false
	});
	//
	$(".fixed-shadow-box .more").click(function() {
		box = $(this).parents(".fixed-shadow-box");
		$(".shadow",box).toggle();
		box.toggleClass("fixed-box-height");
		$("span",this).text($("span",this).text() == 'Показать все' ? 'Скрыть' : 'Показать все');
		return false
	});
});

(function($) {
    $.fn.toggleDisabled = function() {
		return this.each(function() {
            var $this = $(this);
            if ($this.attr('disabled')) $this.removeAttr('disabled');
            else $this.attr('disabled', 'disabled');
				});
	};
})(jQuery);
$(function() {
    $('input:button').click(function() {
        $('input:text').toggleDisabled();
	});
});

var z = 999;
checkExternalClick = function(event) {
	if ($(event.target).parents('.activedropdown,.popup-cat-selection-box').length === 0) {
		$('.activedropdown').removeClass('activedropdown');
		$('.options,').slideUp();
		$('.popup-cat-selection-box').hide()
	}
};
$(document).ready(function() {
	$(document).mousedown(checkExternalClick);
	$('select.custom').each(function() {
		if(!$(this).parent().hasClass('enhanced')) {
			targetselect = $(this);
			targetselect.hide();
			// set our target as the parent and mark as such
			var target = targetselect.parent();
			target.addClass('enhanced');
			// prep the target for our new markup
			target.append('<dl class="dropdown"><dt><a rel="nofollow" class="dropdown_toggle" href="#"><i class="overflow-bg"></i></a></dt><dd><div class="options"><ul class="ulWrapper"></ul></div></dd></dl>');
			target.find('.dropdown').css('zIndex',z);
			z--;
			// we don't want to see it yet
			target.find('.options').hide();
			// parse all options within the select and set indices
			
			if (targetselect.attr("multiple") == true) {
				var i = 0;
				targetselect.find('option').each(function() {
					// add the option
					target.find('.options ul').append('<li><a rel="nofollow" href="#"><span class="value">' + $(this).text() + '</span><span class="hide index">' + i + '</span></a></li>');
				i++;	
				});
				targetselect.parent().find('a.dropdown_toggle').append('<i class="default-selection">Выбрать&hellip;</i>');
			} else {
				var i = 0;
				targetselect.find('option').each(function() {
					// add the option
					target.find('.options ul').append('<li><a rel="nofollow" href="#"><span class="value">' + $(this).text() + '</span><span class="hide index">' + i + '</span></a></li>');
					// check to see if this is what the default should be
					if($(this).attr('selected') == true) {
						targetselect.parent().find('a.dropdown_toggle').append('<span></span>').find('span').text($(this).text());
					}
					i++;
				});	
			};
		}
	});
	// let's hook our links, right?
	$('a.dropdown_toggle').live('click', function() {
		var theseOptions = $(this).parent().parent().find('.options');
		if(theseOptions.css('display')=='block') {
			$('.activedropdown').removeClass('activedropdown');
			theseOptions.slideUp("fast");
		} else {
			theseOptions.slideDown("fast");
			theseOptions.parent().parent().addClass('activedropdown');
			
		}
		return false;
	});
	// bind to clicking a new option value
	$('.options a').live('click', function(e) {
		$('.options').slideUp("fast");
		var enhanced = $(this).parent().parent().parent().parent().parent().parent();
		var realselect = enhanced.find('select.custom');
		enhanced.find('.activedropdown').removeClass('activedropdown');
		// set the proper index
		realselect[0].selectedIndex = $(this).find('span.index').text();

		if (customSelectCallback) customSelectCallback(realselect[0].id, realselect[0].options[realselect[0].selectedIndex].value);
		// update the pseudo selected element
		enhanced.find('.dropdown_toggle').empty().append('<span></span>').find('span').text($(this).find('span.value').text());
		return false;
	});
});
/*
	***** Carousels *****
*/
function f_initCallback (carousel) {
	/*$('.featured-offers-control .next').bind('click', function() {
		carousel.next();
		return false;
	});
	$('.featured-offers-control .prev').bind('click', function() {
		carousel.prev();
		return false;
	});*/
};

function adviceSliderInitCallback (carousel) {
	function advicesBoxHeight() {
		height = $(".advice-slider").height();
		$('.advice-slider .jcarousel-next,.advice-slider .jcarousel-prev').css("height",height)
	}
	advicesBoxHeight()
	$(window).resize(function() {
		advicesBoxHeight()
	});
};
function mycarousel_initCallback(carousel, state) {
    var b = $(".consult-bubble").width()
	var li = $(".consult-carousel li")
	li.css("width",b-36);
};
$(document).ready(function() {
	$(".consult-bubble li .consultant-name").each(function(i) {
		$(this).appendTo("#consultant").attr("id","cons-"+i+"").addClass("hide");
		$("#cons-0").show();
	});
});
function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
    if (state == 'init')
        return;
};
function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	i = idx-1;
	$("#cons-"+i+"").show().nextAll().hide();
	$("#cons-"+i+"").show().prevAll().hide();
};
function mycarousel_reloadCallback(carousel,state) {
	var b  = $(".consult-bubble").width();
	var li = $(".consult-carousel li");
	li.each(function(i) {
		$(this).css({
			"width":b-36
		})
	});
};
function place_fadeout (carousel) {
	$(".tabs-carousel").parents(".jcarousel-clip-horizontal").after('<div class="fadeout"></div>')
}
function consult_loadajax (carousel, state){
		if(state=='next'){
				$.ajax({
					url:'/cons/conswidget_ajax.php',
					data:{cat:0},
					dataType: 'json',
					success:function(m){
							var size = carousel.last+1;
							carousel.add(size, m[0].answ);
					
					  }
				});

		}
}

$(document).ready(function() {
	if ($('.consult-carousel').length>0) {
		$('.consult-carousel').jcarousel({
			scroll:1,
			visible:1,
			reloadCallback: mycarousel_reloadCallback,
			initCallback:   mycarousel_initCallback,
			itemVisibleInCallback: {
				onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
				onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
			}
			//itemLoadCallback: consult_loadajax
		});	
	};
	/*if ($('#featured-offers-list').length>0) {
		$('#featured-offers-list').jcarousel({
			visible:4,
			scroll:4,
			initCallback:f_initCallback,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			wrap:"both",
			itemFirstInCallback : so_itemFirstInCallback
		});	
	};*/
	if ($('#featured-offers-list-2').length>0) {
		$('#featured-offers-list-2').jcarousel({
			visible:4,
			scroll:4,
			initCallback:f_initCallback,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			wrap:"both"
		});
	};
	if ($('#featured-offers-list-6').length>0) {
		$('#featured-offers-list-6').jcarousel({
			visible:6,
			scroll:6,
			initCallback:f_initCallback,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			wrap:"both"
		});	
	};
	if ($('#advices').length>0) {
		$('#advices').jcarousel({
			visible:1,
			scroll:1,
			initCallback:adviceSliderInitCallback,
			wrap:'circular'
		});	
	};
	
	if ($('#carousel').length>0) {
		$('#carousel').jcarousel({scroll:5});	
	};
	if ($('.tabs-carousel').length>0) {
		$('.tabs-carousel').jcarousel({scroll:2,initCallback:place_fadeout});
	};
	if ($('#quotepad-carousel').length>0) {
		$('#quotepad-carousel').jcarousel({
			visible:1,
			scroll:1,
			initCallback:quotepadSliderInitCallback
		});
	};
	if ($("#companies-rating-carousel").length>0) {
		$("#companies-rating-carousel").jcarousel({
			scroll:5,
			visible:5
		});
	};
	// compare table
	if ($('#fixed-col').length>0) {
		$('#fixed-col').fixer({fixedcols:1,height:"auto"});
	};
	
	// photo gallery
	if ($('#ad-photo-slider').length>0) {
		$('#ad-photo-slider').loopedSlider({
			addPagination: true
		});
	};

	$(".mag-image .thickbox").append('<span class="zoom">Увеличить</span>')
	$(".consult-bubble .jcarousel-prev,.consult-bubble .jcarousel-next").click(function() {
		$(".consult-bubble .hellip").removeClass("hide");
		$(".consult-bubble .full").hide();
		$(".consult-bubble .short").removeClass("expanded");
	});
	
});
$(window).load(function() {
	$(".plan-thumbs .th-overlay").each(function() {
		overlay = $(this)
		th = overlay.parent(".plan-th")
		planThHeight = th.height()+6
		planThWidth = th.width()+6
		overlay.css({
			"height":planThHeight,
			"width":planThWidth
		})
	});
});
subRegionsListInitialized = false;
function subRegionsListInit()
{
    if(subRegionsListInitialized) return;
    subRegionsListInitialized = true;
	$(".subway-list-selection li").live('click',function() {
       	$(this).toggleClass("active");
		checkSubRegion(this);
		return false;
	});
}

function subRegionDirectionsInit()
{
	$(".subway-lines-menu li").click(function() {
		$(this).find("img").toggleClass("active");
		return false;
	});
}

function setCookie(name, value, props)
{
	props = props || {}
	var exp = props.expires
	if (typeof exp == "number" && exp) {
		var d = new Date()
		d.setTime(d.getTime() + exp*1000)
		exp = props.expires = d
	}
	if(exp && exp.toUTCString) {props.expires = exp.toUTCString()}

	value = encodeURIComponent(value)
	var updatedCookie = name + "=" + value
	for(var propName in props){
		updatedCookie += "; " + propName
		var propValue = props[propName]
		if(propValue !== true){updatedCookie += "=" + propValue}
	}
	document.cookie = updatedCookie;
}
$(function(){
    $(".popupRegistration").submit(function(){
          var data = $(this).serialize();
         thisForm = this;
         $.post(
            '/yadoma/register.php',
             $(thisForm).serialize(),
             function(m){
                 console.log(typeof m.errors);
                 console.log(m.errors);
                 if(typeof m.errors == 'object'){
                    $(thisForm).find("input").nextAll("b").html("");
                     for(key in m.errors){
                         $(thisForm).find("input[name="+key+"]").nextAll("b").html("<br>"+m.errors[key])
                     }
                 } else {
                     if(m.cookie !== undefined){
                         setCookie('yadoma_cookie', m.cookie, {expires: 3600*24*31*12, path:"/"});
                         location.reload();
                     }
                 }
             },
             'json'
         );
        location.reload();
        return true;
    });
     $(".popupRegistrationNoReload").submit(function(){
        var datas = $(this).serialize();
        $.ajax({ 
            method: "get",
            data: datas,
            url: "/yadoma/register_self.php",
            success: function(m){ 
                if(m!='0')
                    alert(m);
                else{
                    regis=1;
                    $(".similar-results-link").click();
                    $(".modal-regis").find(".jqmClose").click();
                    $(".modal-logining").find(".jqmClose").click();
                }
            }
        });
        return false;
    });
});

$(document).ready(function(){
    $(".csl-rooms td").click(function() {
        $(this).toggleClass("current");
        return false
    });
});
$(document).ready(function() {
    var current_attr = $("#csl-menu li.current a").attr("href");
    if (current_attr)
    {
	    $(current_attr).show().next().hide().end().prev().hide();
	    $(current_attr).find("li:first-child").addClass("current");
	    var current_attr_form = $(current_attr).find("li:first-child a");
	    searchFormSwitcherCallbackSimple(current_attr_form);
    }
    
    $("#csl-menu li a").click(function() {
        var attr = $(this).attr("href");
        $("#csl-menu li").removeClass();
        $(this).parent("li").addClass("current");
        $(attr).show().next().hide().end().prev().hide();
        elem = $(attr).find("li:first-child a");
        $(elem).parent().addClass("current");
        searchFormSwitcherCallbackSimple(elem);
        return false
    });

    $(".csl-menu-2 li a").click(function() {
        var attr = $(this).attr("href");
        $(".csl-menu-2 li").removeClass();
        $(this).parent("li").addClass("current");
        searchFormSwitcherCallbackSimple(this);
         return false
    });
    
    

});
$(document).ready(function() {
    $(".cottage-search-title").click(function() {
        $(".cottage-search-selection").toggle();
        return false
    });
});

