$j = jQuery.noConflict();

$j(document).ready(function(){

	/* обратная связь */
	$j("#feedback-show").click(function () {
		$j("#feedback-form").show();
	});

	$j("#feedback-close").click(function () {
		$j("#feedback-form").hide();
	});


	/* услуги */
	$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()
	});

	/* обработчик преимуществ */
	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";
			
	});
	
});

var Move = new Array();
Move[1] = '-946';
Move[2] = '0';
Move[3] = '1450'
Move[4] = '2500';

function ObjectShow(id) {

	$j("#frameset").animate( { left:""+ 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;
}
