$j = jQuery.noConflict();

$j(document).ready(function(){

	$j("#frameset").css({left:""+ Move[4] +"px"})
	$j("#frameset").fadeIn("slow");
	
	/* обратная связь */
	$j("#feedback-show").click(function () {
                $j("#message-error").html("");
		$j("#feedback-form").show();
	});

	$j("#feedback-close").click(function () {
		$j("#feedback-form").hide();
                $j("#message-error").html("");
	});


	/* услуги */
	$j("#services div a:first").next(".desc").show();
	$j("#services div a, #services div h1").click (function () {
		$j(this).parent().parent().find('.desc').not($j(this).parent()).slideUp()
		$j(this).next(".desc").slideDown()
	});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Переключение между схемой проезда и обратной связью
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$j("#write").click(function(){
		if ($j(this).hasClass("span")) {
			$j(this).addClass("span-active").removeClass("span");
			$j("#map").addClass("span").removeClass("span-active");
			$j(".contacts-form").css("display","block");
			$j(".schema").css("display","none");
			}
		});
	$j("#map").click(function(){
		if ($j(this).hasClass("span")) {
			$j(this).addClass("span-active").removeClass("span");
			$j("#write").addClass("span").removeClass("span-active");
			$j(".schema").css("display","block");
			$j(".contacts-form").css("display","none");
			}
		}); 
//////////////////////////////////////////////////////////////////////////////////////
	/* обработчик преимуществ */
	var fadeTime=700;
	var t;
	
	$j("#slide-right").click (function () {
		
		var tid = parseInt($j("#adv-step").attr("tid"));
		var cnt = parseInt($j("#adv-cnt").attr("tid"));

		if (tid  >= cnt) {

			tid = 1;
			$j("#adv-step").attr("tid", tid)
		} else {
			tid = tid + 1;
			$j("#adv-step").attr("tid", tid)
		}
		var res = parseInt($j("#adv-step").attr("tid"));

		$j("#slide-desc").animate({opacity:0}, fadeTime);
		$j("#slide-caption").animate({opacity:0}, fadeTime);

		t=setTimeout("FadeInRes("+res+")", fadeTime);

	});

	$j("#slide-left").click (function () {

		var tid = parseInt($j("#adv-step").attr("tid"));
		var cnt = parseInt($j("#adv-cnt").attr("tid"));

		if (tid  < 2) {

			tid = cnt;
			$j("#adv-step").attr("tid", tid)
		} else {
			tid = tid - 1;
			$j("#adv-step").attr("tid", tid)
		}
		var res = parseInt($j("#adv-step").attr("tid"));

		$j("#slide-desc").animate({opacity:0}, fadeTime)
		$j("#slide-caption").animate({opacity:0}, fadeTime)
		t=setTimeout("FadeInRes("+res+")", fadeTime);

	});


	/*$j("h4.down").click (function () {
		$j("#desc_add").slideToggle("fast");
	});*/

	/* поиск */
	$j("#search-word").focus (function () {
		$j(this).val('');
	});
	
	/*$j("#cat-id, #sub-cat-id").val(0);
	$j("#cat-name, #sub-cat-name").val("");*/
	
	/* открытие списка */
	
	$j(".select-bg .exp,.select-b .exp-text").click(function(){
		
		if ($j(this).next().css("display")!="none") {
			$j(this).next().hide().find("div").not(":eq(0)").remove();
			return false;
		}
		
		$j(".select-bg .exp").each(function(){
			$j(this).next().hide().find("div").not(":eq(0)").remove();
		});
		
		var pid = 0;
		
		var mode = ($j(this).attr("id")=="load-sub-cats") ? "sub" : "parent";
		
		if (!mode)
			mode = ($j(this).attr("id")=="sub-cat-name") ? "sub" : "parent";
		
		if (mode=="sub") {
			
			if ($j("#cat-id").val()>0)
				pid = $j("#cat-id").val();
			else
				pid = -1;
		}
				
		if (pid >= 0) {
			
			$j.ajax({
				
				url: "/admin/modules/module/block/products/handler/get-cats.handler.php",
				dataType: "json",
				type: "POST",
				
				data: ({
					pid : pid
				}),
				
				success: function(response){
					
					if (response.result = "success") {
					
						switch (mode) {
							
							case "sub":
								
								$j.each(response.text, function(){
								
									$j(".sub-cat-item:first").clone(true).insertAfter(".sub-cat-item:last");
									$j(".sub-cat-item:last input:hidden").val(this.id);
									$j(".sub-cat-item:last span").text(this.name);
								});				
								
								$j("#sub-cat-select").show();
								break;
								
							case "parent":
								
								$j.each(response.text, function(){
								
									$j(".cat-item:first").clone(true).insertAfter(".cat-item:last");
									$j(".cat-item:last input:hidden").val(this.id);
									$j(".cat-item:last span").text(this.name);
								});								
								
								$j("#cat-select").show();
								break;
						}
					}
				}
				
			});
		}
		else {
			$j("#sub-cat-select").show();
		}
		
		return false;		
	});
	
	/* выбор из списка */
	
	$j(".field-expand div").live("click", function(){
		
		var id 		= $j("input:hidden", $j(this)).val();
		var name 	= $j("span", $j(this)).text();
		
		$j(this).parent().parent().find("> input:text").val(name);
		$j(this).parent().parent().find("> input:hidden").val(id);
		
		$j(this).parent().hide().find("div").not(":eq(0)").remove();
	});

	/* скачать прайс-лист */
	
	$j("#get-price").click(function(){
		
		var id = $j("#group-id").val();
		
		if (id!="")
			document.location = "/admin/modules/module/block/products/handler/get-price.handler.php?id="+id;
		else
			document.location = "/admin/modules/module/block/products/handler/get-price.handler.php";
			
	});
	
	$j("span#answer").click(function(){
	$j(".message").slideToggle("slow");
	});
/*---------------2.03----------------------*/
	/*$j("#header .navi #nav li").bind("mouseover",	function(){

		$j(this).find(".subnav").show().parent()

	});
	$j("#header .navi #nav li").bind("mouseout",function(){

		$j("#header .navi #nav li>a").parent().each(function(){

			if( $j(this).find("ul li>a").length == $j(this).find("ul li").length )

			$j(this).find(".subnav").hide().parent()

		});
	});*/

    $j("a.find").click(function(){
        $j("#filter").slideToggle("slow");
        $j(this).toggleClass("active"); 
		return false;
    });
	
	$j(".cat-item").click(function(){		
		if ($j.browser.msie)
			$j(".field1").show();
		else 		
			$j(".field1").fadeIn(500);	
			$j("html:not(:animated)"+( ! $j.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop:0});
	});	

		$j(".sub-cat-item").click(function(){		
		if ($j.browser.msie)
			$j(".field2").show();
		else 		
			$j(".field2").fadeIn(500);	
			$j("html:not(:animated)"+( ! $j.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop:0});
	});	
	
	var img_width = 74; 
	var amount = $j(".slider>div").length;
	
	$j(".right-arrow").bind("click" ,function(){
		
		//if($j(".slider").hasClass("blocked")) return false;
		if( (amount - Math.abs(parseInt($j(".slider").css("margin-left"))/img_width)) <= 4) return false;
		//$j(".slider").addClass("blocked");
		$j(".slider").stop().animate({"marginLeft" : "-=" + img_width + "px"}, "slow", function(){
			$j(".blocked").removeClass("blocked");
		});	
	});
	
	$j(".left-arrow").click(function(){
	
		if($j(".slider").hasClass("blocked")) return false;
			if( parseInt($j(".slider").css("margin-left")) >= 0 ) return false;
			$j(".slider").addClass("blocked");
			$j(".slider").stop().animate({"marginLeft" : "+=" + img_width + "px"}, "slow", function(){
			$j(".blocked").removeClass("blocked");
		});
	});
	
	$j(".slider>div").click(function(){
		$j(".img-wrap>img").attr("src",$j(this).children("img").attr("src"));
		return false;
	});
/*------------------------------------*/
});

var Move = new Array();
Move[1] = '-946';
Move[2] = '0';
Move[3] = '1450'
Move[4] = '2500';

function ObjectShow(id) {

	if(id == 4 )
	{
		$j("#frameset").css({left:""+ Move[3] +"px"})
		$j("#frameset").animate( { left:""+ Move[4] +"px"}, 1000 )
	}
	else
	$j("#frameset").animate( { left:""+ Move[id] +"px"}, 1000 )
	//$j("#frameset").animate( { right:""+ Move[id] +"px"}, 1000 )
	$j("#frameset .label-hide").show()
	$j("#services").animate({opacity:0},"slow")
	$j("#object-more-"+id+"").show("slow")
	$j("#more-hide").show("slow")

	if(id != 1) {
		$j("#frameset .label-hide").hide();
		$j("#frameset .label-show").hide();
	}

}

function ObjectList(id){

	$j("#object-more-list-"+id+"").slideToggle("fast");
}

function ObjectHide(id) {

	$j("#frameset").animate( { left:"-1450px"}, 1000 );
	$j("#frameset .label-hide").hide();
	$j("#services").animate({opacity:1},"slow");
	$j("#object-more-"+id+"").hide("slow");
	$j("#object-more-list-"+id+"").hide("slow");
	$j("#more-hide").hide("slow")

	if(id == 1) {
		$j("#frameset .label-show").show();
	}
}

function FadeInRes(res) {
	$j("#slide-caption").html($j("#adv-caption-"+ res +"").html()).animate({opacity:1}, "slow");
	$j("#slide-desc").html($j("#adv-text-"+ res +"").html()).animate({opacity:1}, "slow");
	return true;
}




