$(document).ready(function(){	
		
		/* FORMS */
		swapValue = [];
		$("[type=text]").each(function(i){
		swapValue[i] = $(this).val();
		$(this).focus(function(){
		  if ($(this).val() == swapValue[i]) {
			 $(this).val("");
		  }
		  }).blur(function(){
				if ($.trim($(this).val()) == "") {
				$(this).val(swapValue[i]);
				}
		  });
		});
						   
		/* TREE MENU */
		$(".product_list li span").click(function(){
			if ($(this).hasClass("closed")) {
				$(this).removeClass("closed");
				$(this).parent().find("ul").slideDown("fast");
				$(this).addClass("opened");
			}else
				if ($(this).hasClass("opened")) {
				$(this).removeClass("opened");
				$(this).parent().find("ul").slideUp("fast");
				$(this).addClass("closed");				
			}
		})
			$("#op_it").slideDown("fast");
		/* TABS */
	/*		var tabContainers = $('.tab_blk .item');
    	tabContainers.hide().filter(':first').show();
    $('.tab_blk ul.tab_navigation a').click(function () {
        	tabContainers.hide();
	        tabContainers.filter(this.hash).fadeIn("slow");
        	$('.tab_blk ul.tab_navigation a').removeClass('active');
        	$(this).addClass('active');
	        return false;
    	})*/
		
		/* IMAGE LIST */
		var i = 0;
		var current;
		var imgcollection = [];
		imgcollection = $(".image_list li");
		imgcollection.hide();
		$(".image_list li:first-child").show();
		$(".image_small_list li:first-child").addClass("active");
		$(".image_small_list li:last-child").addClass("last");
		$(".image_small_list li").each(function(){
			$(this).attr("title", i)
			i++;
		})		
		$(".image_small_list li a").click(function(){
			current = $(this).parent().attr("title");
			parseInt(current);
			imgcollection.hide();
			$(".image_small_list li").removeClass("active");
			$(this).parent().addClass("active");
			showImg();
			return false;			
		});
		function showImg(){
			var j = 0;
			$(".image_list li").each(function(){
				if(j == current) {
					$(this).fadeIn();
					
				}
				j++;
			})		
		}
		
		/* SIMILAR PRODUCTS SLIDING  1*/
		function slideImg1(){			
			var i = 0;
			var count = [];
			var last;
			count = $(".similar_products li");
			j = parseInt(count.length);
			last = count.length-1;
			var itemwidth = parseInt($(".similar_products ul li").width()) + 15;
			var ulwidth = count.length*itemwidth;
			$(".similar_products ul").css("width", ulwidth + "px");
			if(i == 0)		$("a.arrow_left").addClass("not_active");
			if(i == last)	$("a.arrow_right").addClass("not_active");
			if(count.length <= 3) { $("a.arrow_left").addClass("not_active"); $("a.arrow_right").addClass("not_active"); }
			$("a.arrow_right").click(function(){;
				if(i < last-2){
					i++;
					$("a.arrow_left").removeClass("not_active");
					$(".similar_products ul").animate({"left": "-=" + itemwidth}, 300);
				}
				if(i == last-2){ $("a.arrow_right").addClass("not_active"); }
			});
			$("a.arrow_left").click(function(){;
				if(i !=  0){
					i--;
					$("a.arrow_right").removeClass("not_active");
					$(".similar_products ul").animate({"left": "+=" + itemwidth}, 300);				
				}
				if(i == 0){ $("a.arrow_left").addClass("not_active"); }
			});
		}
		slideImg1();
		
		/* SIMILAR PRODUCTS SLIDING  2*/
		function slideImg2(){			
			var i = 0;
			var count = [];
			var last;
			count = $(".similar_products2 li");
			j = parseInt(count.length);
			last = count.length-1;
			var itemwidth = parseInt($(".similar_products2 ul li").width()) + 15;
			var ulwidth = count.length*itemwidth;
			$(".similar_products2 ul").css("width", ulwidth + "px");
			if(i == 0)		$("a.arrow_left2").addClass("not_active");
			if(i == last)	$("a.arrow_right2").addClass("not_active");
			if(count.length <= 3) { $("a.arrow_left2").addClass("not_active"); $("a.arrow_right2").addClass("not_active"); }
			$("a.arrow_right2").click(function(){;
				if(i < last-2){
					i++;
					$("a.arrow_left2").removeClass("not_active");
					$(".similar_products2 ul").animate({"left": "-=" + itemwidth}, 300);
				}
				if(i == last-2){ $("a.arrow_right2").addClass("not_active"); }
			});
			$("a.arrow_left2").click(function(){;
				if(i !=  0){
					i--;
					$("a.arrow_right2").removeClass("not_active");
					$(".similar_products2 ul").animate({"left": "+=" + itemwidth}, 300);				
				}
				if(i == 0){ $("a.arrow_left2").addClass("not_active"); }
			});
		}
		slideImg2();
		
		$("a.hide").click(function(){
			$(".search_option ul").slideUp("fast");
			$(this).hide();
			$("a.show").show();
			return false;
		})
		$("a.reg_info").click(function(){
			$(".info_reg").slideDown("fast");
			$("a.reg_info").hide();
			$("a.reg_info_open").show();
			return false;
		})
			$("a.reg_info_open").click(function(){
			$(".info_reg").slideUp("fast");
			$("a.reg_info").show();
			$("a.reg_info_open").hide();
			return false;
		})
		$("a.show").click(function(){
			$(".search_option ul").slideDown("fast");
			$(this).hide();
			$("a.hide").show();
			return false;
		})
		
		$("#bot_zakaz").click(function(){
			$("#forma_zakaza").show("slow");
			$(this).hide();
			$("#zak1").hide();
			ddaccordion.setCookie('link_form_z', '1');
			return false;
		})
		$("#link_form_zak").click(function(){
			$("#forma_zakaza").hide("slow");
			$("#zak1").show();
			$("#bot_zakaz").show();
			ddaccordion.setCookie('link_form_z', '0');
			return false;
		})
		
		/*----------for form order to open or close it--------------*/
		$("#refer_order").click(function(){
			ddaccordion.setCookie('link_form_z', '1');
			
		})
		
		if(ddaccordion.getCookie('link_form_z')==1)
		{
			$("#forma_zakaza").show("slow");
			//$("#link_form_zak").hide();
			$("#zak1").hide();
		}
		//alert(ddaccordion.getCookie('link_form_z'));
		/*--------------end------------------*/
		
		$("#garant_1").click(function(){
			document.getElementById('garant_1').style.display='none';
			$("#garant").show("slow");
			document.getElementById('garant_2').style.display='inline';
			return false;
		})
		$("#garant_2").click(function(){
			document.getElementById('garant_2').style.display='none';
			$("#garant").hide("slow");
			document.getElementById('garant_1').style.display='inline';
			return false;
		})
})
//callable from web page - bigger pictures
function ShowDiv(obj,url){
	if ( url != 0 )
	{var div =obj.width;	
		div = 200;		
		obj.width =div;
	}
	else
	{
	var div =obj.width;	
		div = 180;		
		obj.width =div;
	}

}
