  $(document).ready(function(){
	var allRightTd = $(".tbl-head-td, .tbl-row-td");
	var allRightTdNo = $(".tbl-row-td-no");
	var openRow = $(".tbl-row-td-open").closest("tbody");
	var closeRow = $(".tbl-row-td-close").closest("tbody");
	allRightTd.hide();
	closeRow.hide();
	$(".tbl-row").hide();
	$(".tbl-head-td-open").click(function(){
		var $this = $(this);
		if($this.hasClass("tbl-head-td-close")){
			$this.removeClass("tbl-head-td-close").find("span").html("[+]");
			allRightTd.hide();
			allRightTdNo.show();
		}else{
			$this.addClass("tbl-head-td-close").each(function(){
				$(this).find("span").html("[-]");
			});
			allRightTd.show();
			allRightTdNo.hide();
		}
		return false;
	});
	$(".tbl-row-td-open").click(function(){
		var $this = $(this);
		var row = $this.closest("tbody");
		var content = row.next(".tbl-row");
		var tContent = content;
		while(tContent.next("tbody").hasClass("tbl-row")){
			content = content.add(tContent.next(".tbl-row"));
			tContent = tContent.next(".tbl-row");
		}
		row.hide();
		content.show();
		closeRow.show();
	});
	
	$(".tbl-row-td-close").click(function(){
		var $this = $(this);
		var row = $this.closest("tbody");
		var content = row.prev(".tbl-row");
		var tContent = content;
		while(tContent.prev("tbody").hasClass("tbl-row")){
			content = content.add(tContent.prev(".tbl-row"));
			tContent = tContent.prev(".tbl-row");
		}
		row.hide();
		content.hide();
		openRow.show();
	});
	
	$(".alterLinks a").alterLinks();
	
	var lng = $(".linc_block a.active").attr("href");
	
	$(".link-autoopen").autoopenLinks(lng);
	
	/*$(window).hashchange(function(){
		return false;
	});*/
	var mapImg = $("#map");
	$("#map-regions area").add(".price-regions dd a").mouseout(function(){
		mapImg.removeClass();
	}).mouseover(function(){
		var cssClass = $(this).attr("class");
		mapImg.removeClass();
		mapImg.addClass("map-"+cssClass);
	});
	
	$("a.catItem").catItemLinks();
	
	$(".faqContent dt a").faqLinks();

});

$.fn.autoopenLinks = function(lng) {
	var lng = lng;
	return this.each(function(index){
		var strRazver = "+ развернуть";
		var strSver = "- cвернуть";
		if(lng=="en"){
			var strRazver = "+ turn";
			var strSver = "- turn";
		}
		var $this = $(this);
		$this.append("<span>"+strRazver+"</span>");
		var thisLink = $this.find("span");
		var thisContent = $this.next(".block-autoopen");
		thisLink.click(function(){
			if($this.hasClass("link-autoopen-active")){
				$this.removeClass("link-autoopen-active");
				thisLink.html(strRazver);
				thisContent.slideUp();
			}else{
				$this.addClass("link-autoopen-active");
				thisLink.html(strSver);
				thisContent.slideDown();
			}
		});
	})
};

$.fn.alterLinks = function() {
	return this.each(function(index){
		var thisLink = $(this);
		var thisId = thisLink.attr("href").replace(/^(.*?)\#/, "");
		var thisContent = $("#"+thisId);
		var thisContainer = thisLink.closest(".alterLinks");
		thisLink.click(function(){
			if(!thisLink.hasClass("currentAlterLinks")){
				window.location.hash = "#"+thisId;
				thisContainer.find("a.currentAlterLinks").removeClass("currentAlterLinks");
				thisLink.addClass("currentAlterLinks");
				$(".alterLinksContent:visible").slideUp();
				thisContent.slideDown();
			}
			return false;
		});
		if(window.location.hash == "#"+thisId)
			thisLink.click();
		
	});
};

$.fn.catItemLinks = function() {
	return this.each(function(index){
		var thisLink = $(this);
		var thisId = thisLink.attr("id").replace(/^cat\_item\_/, "");
		thisLink.click(function(){
			window.location.hash = "#item_"+thisId;
			return showGood(thisId);
		});
		if(window.location.hash == "#item_"+thisId)
			thisLink.click();
		
	});
};
 
 $.fn.faqLinks = function() {
	return this.each(function(index){
		var thisLink = $(this);
		var thisId = thisLink.attr("href").replace(/^(.*?)\#/, "");
		var thisContainer = thisLink.closest("dt");
		var thisContent = thisContainer.next("dd");
		var isScrool = false;
		thisLink.click(function(){
			if(!thisContainer.hasClass("open")){
				window.location.hash = "#"+thisId;
				thisContainer.addClass("open");
				thisContent.slideDown("slow", function(){
					if(isScrool){
						isScrool = false;
						if($.browser.safari)
							$('body').animate( { scrollTop: thisContainer.offset().top }, 1100 );
						else
							$('html').animate( { scrollTop: thisContainer.offset().top }, 1100 );
					}
				});
			}else{
				thisContainer.removeClass("open");
				thisContent.slideUp();
			}
			return false;
		});
		if(window.location.hash == "#"+thisId){
			isScrool = true;
			thisLink.click();
		}
	});
};
