var fRunOfScroll = true;
var errAutoris = false;
var bg = '';

var timer;

$(document).ready(function(){
	
	$('.left-bl a').hover(
		function (){
			$(this).children('img').attr('src', $(this).attr('hov'));
		},
		function (){
			$(this).children('img').attr('src', $(this).attr('rel'));
		}
	)
	
	// МИНУС В ЛЕТАЮЩЕМ ОКНЕ
	$(".cntBlock .minus").livequery('click', function(){
		$("input", $(this).parent())
		valOfFld = parseInt($("input", $(this).parent()).val());
		if ( valOfFld > 1 ) {
			$("input", $(this).parent()).val(valOfFld - 1);
			
			var id = $(this).parent().attr('id');
			
			$.get('/includes/ajax/inc_dec_basket_tmp.php', { id: id, action: 0 }, function(json){
				var node = parseJSON(json);
				//alert('hi');
				$('#all_'+node.id).text(node.price);
			});
		}
	});
	
	// ПЛЮС В ЛЕТАЮЩЕМ ОКНЕ
	$(".cntBlock .plus").livequery('click', function(){
		valOfFld = parseInt($(this).parent().children(".field").children(".fld1").children(".inp").val());
		
		$("input", $(this).parent()).val(valOfFld + 1);
		
		var id = $(this).parent().attr('id');
		
		$.get('/includes/ajax/inc_dec_basket_tmp.php', { id: id, action: 1 }, function(json){
			var node = parseJSON(json);
			//alert('hi2');
			$('#all_'+node.id).text(node.price);
		});
	});
	
	/*
	 * Изменение количества товара вручную (без нажатия на кнопки "+" и "-") 
	 * */
	$(".cntBlock .b_inp_count").livequery('keyup', function(){
		var count = $(this).attr('value');
		
		var id = $(this).parent().parent().parent().attr('id');
		
		$.get('/includes/ajax/count_basket_tmp.php', { id: id, count: count }, function(json){
			var node = parseJSON(json);
			//alert('hi2');
			$('#all_'+node.id).text(node.price);
		});
	});
	
	/*
	 * добавляем товар в корзину и остаемся на текущей странице
	 * */
	$('.addToFavBtn a').livequery('click', function(){
		var id = $(this).attr('id');
		var href = $(this).attr('href');
		
		$.get('/includes/ajax/add_basket.php', { id: id }, function(json){
			var node = parseJSON(json);
			
			window.location.href = href;
								
			return false;
		});
		
		return false;
	})
	
	/*
	 * добавляем товар в корзину и переходим к офформлению заказа
	 * */
	$('.buyBtn a').livequery('click', function (){
		var id = $(this).attr('id');
		
		$.get('/includes/ajax/add_basket.php', { id: id }, function(json){
			window.location.href = '/basket/';
			
			return false;
		});
		
		return false;
	})
	
	/*
	 * Если меняем размер в карточке
	 * */
	$('.type_size input:radio').livequery('click', function(){
		var id = $(this).attr('id');
		
		$.get('/includes/ajax/change_price.php', { id: id }, function(json){
			var node = parseJSON(json);
			
			$('#price_'+node.pid).html(node.price);
		});
	})
	
	/*
	 * занесение цвета в сессию
	 * */
	$('.r-color').livequery('click', function(){
		var id = $(this).attr('id');
		//alert(id);
		$.get('/includes/ajax/change_color.php', { id: id }, function(json){
			//alert('ok');
		});
 	})
 	
 	/*
	 * занесение размера в сессию
	 * */
	$('.r-size').livequery('click', function(){
		var id = $(this).attr('id');
		//alert(id);
		$.get('/includes/ajax/change_size.php', { id: id }, function(json){
			var node = parseJSON(json);
			//alert(node.price);
			
			$('.newPrice').html(node.price2);
			$('#all_'+node.id).text(node.allprice);
			$('#price2_'+node.id).text(node.price);
		});
 	})
 	
	
	//наведение мышки на галерею в коллекциях
	$(".small-pic").hover(
		function (){
			bg = $(this).css('border');
			
			//$(this).css('border', '1px solid #A7CF2F');
			$(this).addClass("hover-pic");
		},
		function (){
			$(this).css('border', bg);
			$(this).removeClass("hover-pic");
		}
	)
	
	$(".color").hover(
		function (){
			bg = $(this).css('border');
			
			//$(this).css('border', '1px solid #A7CF2F');
			$(this).addClass("hover-color");
		},
		function (){
			$(this).css('border', bg);
			$(this).removeClass("hover-color");
		}
	)
	
	//смена картинки и подписи в коллекциях
	$(".small-pic").click(function (){
		var id = $(this).attr('id');
		//alert(id);
		$.get('/includes/ajax/change_metka.php', { id: id }, function(json){
			var node = parseJSON(json);
			//alert(node.query);
			$('.bl-metka').html(node.metka);
			$('#price-metka').html(node.t_price);
			$('.list-elem').html(node.listpoint);
			
			metkaBlock();
		});
		
		$(".small-pic").each(function (){
			$(this).removeClass("active-pic");
			
			$(this).children('a').children('img').attr('src', $(this).children('a').attr('gray'))
		})
		
		var name_pic = $(this).children('a').attr('alt');
		
		if(name_pic != '') $('#name-pic-arr').css('display', 'block'); 
		else $('#name-pic-arr').css('display', 'none');
		
		$('#name-pic').text(name_pic);
		
		$('#src-pic').attr('src', $(this).children('a').attr('href'));
		
		$(this).children('a').children('img').attr('src', $(this).children('a').attr('rel'));
		
		$(this).addClass("active-pic");
		
		return false;
	})
	
	// Всплывающее меню
	$(".subMenuTable tr td .relBlock").hover(
		function(){
			if ( $(".flyBlock", this).length ) {
				//	 alert("OPA!!!");
				$("a:first", this).css("padding-bottom", "10px");
			}

			$("a:first", this).addClass("hov");

			$(".flyBlock", this).slideDown("fast");
			
			$this = $(this);
			
			clearTimeout(timer);
			
			
			if($this.children('.a_rel').children('.active').length == 0)
				$this.children('.a_rel').children('a').css('color', '#FFF');
			
			if($this.children('.submenu').length == 1){
				
				if($this.children('.a_rel').children('.active').length == 0){
					
					$this.children('.a_rel').children('a').css('border-right', '1px solid #FFF');
				}
				$this.css('background', '#1896DC');
			}	
			
			if($this.children('.a_rel').children('a').is('.act')){
				$this.children('.a_rel').children('a').css('color', '#FFF');
			}

			
			timer = setTimeout(function(){	
				$this.children('.a_rel').children('a').css('height', '42px');	
				$this.children('.submenu').show();
			}, 300);
		}, 
		function() {
			$("a:first", this).css("padding-bottom", "0");
			$("a:first", this).removeClass("hov");
			$(".flyBlock", this).slideUp("fast");	
			
			clearTimeout(timer);
			
			if($(this).children('.a_rel').children('.active').length == 0)
				$(this).children('.a_rel').children('a').css('color', '#47484A');
			
			if($(this).children('.submenu').length == 1){
				$(this).children('.submenu').hide();
				$(this).children('.a_rel').children('a').css('height', '32px');
				if($(this).children('.a_rel').children('.active').length == 0){
					
					$(this).children('.a_rel').children('a').css('border-right', 'solid 1px transparent');
				}
				$(this).css('background', 'none');
			}
			
			if($this.children('.a_rel').children('a').is('.act')){
				$this.children('.a_rel').children('a').css('color', '#FFF');
			}
		}
	);
	
	$('.project').click(function (){
		if($('.project-menu').css('display') == 'none'){
			$('.project-menu').css('display', 'block');
			$('.buttom-prj').css('display', 'none');
		}else{
			$('.project-menu').css('display', 'none');
			$('.buttom-prj').css('display', 'block');
		}
	})
	$('.project').hover(
		function (){
			//$('.project-menu').css('display', 'block');
		},
		function (){
			$('.project-menu').css('display', 'none');
			$('.buttom-prj').css('display', 'block');
		}
	)
	
	
	$('.type_user').livequery('click', function (){
		if($(this).attr('value') == '1'){
			$('#fiz_l').show();
		}else{
			$('#fiz_l').hide();
		}
	})
	
	
	/*
	 * При смене комплекта
	 * меняем большую фотографию
	 * меняем набор товаров
	 * меняем общуу сумму
	 * */
	$('.cvet a').livequery('click', function (){
		$('.cvet a').removeClass('active');
		
		$(this).addClass('active');
		
		$('.right-block img').attr('src', $(this).attr('href'));
		$('.right-block a').attr('href', $(this).attr('rel'));
		
		var id = $(this).attr('id');
		
		$.get('/includes/ajax/change_complect.php', { id: id }, function(json){
			var node = parseJSON(json);
			
			$('.list_tovar table tbody').html(node.text);
			$('.newPrice').html(node.price);
		});
		
		return false;
	})
	
	/*
	 * Меняем цену в зависимости от выбранного товара
	 * */
	$('.compl_tov').livequery('click', function (){
		//var id = $(this).attr('id');
		var data={}
		$( '.list_tovar table tbody input[type=checkbox]' ).each(function(){
			if($(this).attr('checked') == true){
				data[$(this).attr('id')] = $(this).attr('id');
			}
		});
		
		$.get('/includes/ajax/change_comp_price.php', { data: data }, function(json){
			var node = parseJSON(json);
			//alert(json)
			$('.newPrice').html(node.price);
		});
	})
	
	$(".right-block .birka a").fancybox({
		"hideOnContentClick": false,
		"titlePosition"  : "inside",
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	$(".c_left a").fancybox({
		"hideOnContentClick": false,
		"titlePosition"  : "inside",
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	$(".resultOrderTable .pic a").fancybox({
		"hideOnContentClick": false,
		"titlePosition"  : "inside",
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	$(".project .pr-img a").fancybox({
		"hideOnContentClick": false,
		"titlePosition"  : "inside",
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	$(".color a").fancybox({
		"hideOnContentClick": false,
		"titlePosition"  : "inside",
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	$(".color-2 a").fancybox({
		"hideOnContentClick": false,
		"titlePosition"  : "inside",
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	$("#bl_color a").fancybox({
		"hideOnContentClick": false,
		"titlePosition"  : "inside",
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	$('.photo a').livequery('click', function (){
		$('.photo a').removeClass('active');
		
		$(this).addClass('active');
		
		$('.c_left img').attr('src', $(this).attr('rel'));
		$('.c_left a').attr('href', $(this).attr('href'));

		return false;
	})
	
	$('.cvet-kr').livequery('click', function (){
		$('.cvet-kr').removeClass('cv-active');
		$('.cvet-kr').css('border', '1px solid #FFF');
		
		//bg = $(this).css('border', '1px solid green');
		//alert('hi');
		$(this).addClass('cv-active');
		$(this).css('border', '1px solid green');
		
		var id = $(this).attr('id');
		//alert(id)
		$.get('/includes/ajax/change_color_cr.php', { id: id }, function(json){
			var node = parseJSON(json);
			//alert(json)
			$('.newPrice').html(node.price);
		});
	})
	
	/*
	$('.cvet-kr').hover(
		function (){
			bg = $(this).css('border');
			if(!$(this).hasClass('cv-active'))
				$(this).css('border', '1px solid red');
		},
		function (){
			if(!$(this).hasClass('cv-active'))
				$(this).css('border', bg);
		}
	)
	* */
	
	$('#radio_region input:radio').click(function (){
		if($(this).attr('value') == 1){
			$('#russia_dost').show('slow');;
		}else{
			$('#russia_dost').hide('slow');
		}
	})
	
	$('#show_region').click(function (){
		if($('#region_list').css('display') == 'none'){
			$('#region_list').slideToggle();
		}else{
			$('#region_list').slideToggle();
		}
	})
	
	if(errAutoris){
		showUpLogin();
		onDarkBg(0.7);
	}
	
	init();
	
	$(".b_inp_count").change( function (){
		alert('hi');
		var val = $(this).attr('value');
		alert(val);
	})
	$(".cntBlock .b_inp_count").click(function (){
		alert('hi');
		var val = $(this).attr('value');
		alert(val);
	})
	
	$('.view_compl').hover(
		function (){
			$(this).next('div').show();
			
			return false;
		}, 
		function (){
			$(this).next('div').hide();
			
			return false;
		}
	)
	
	$('#alike').change(function (){
		var value = $(this).attr('value');
		var item = $('#item_id').text();
		var docs = $('#docs_id').text();
		
		var php_file;
		
		if(value == 1) php_file = 'alike_price.php';
		else  php_file = 'alike_param.php';
		//alert(php_file);
		$.get('/includes/ajax/'+php_file, { value: value, item: item, docs: docs }, function(json){
			//alert(json);
			$('.resultOfQuery').html(json);
		});
	})
	
	$('#sel_docs').change(function (){
		var value = $(this).attr('value');
		//alert('hi');
		$.get('/includes/ajax/chenge_docs.php', { value: value }, function(json){
			//alert(json);
			//var node = parseJSON(json);
			//alert(node.text);
			$('#div_brand').html(json);
			
			init();
		});
	})
	
	/*
	$('.buyButton').livequery('click', function (){
		var id = $(this).attr('id');
		var cvet = $('.kr_right .cv-active').attr('id');
		
		var fol_id = $('.zebraTable input:radio:checked').attr('id');
		if(fol_id){
			id = fol_id;
		}
		//alert(id);
		$.get('/includes/ajax/add_basket_tmp.php', { id: id, cvet: cvet }, function(json){
			//alert(json);
			$('.basket_tmp').html(json);
			//alert(id);
			$.get('/includes/ajax/add_basket_recom.php', { id: id }, function(json){
				//alert(json);
				//var text = eval(json.text);
				//var id = eval(json.id);
				
				
				
				if(json != '') $('.buyItToo').show();
				
				$('#scroll_ul').html('');
				$('#scroll_ul').html(json);
				//alert($('#scroll_ul').html());
				showFlyBacket();
				
				$.get('/includes/ajax/get_price_tovar.php', { id: id }, function(json){
					var node = parseJSON(json);
					
					$('#all_price').text(node.price);
					return false;
				});
				
				//init();
				
				
			});
		});
		
		return false;
	})
	* */
	
	$('.buyComplect').livequery('click', function (){
		//var id = $(this).attr('id');
		var id = $('.cvet .active').attr('id');
		
		//alert(id);
		
		var data={}
		$( '.list_tovar input[type=checkbox]' ).each(function(){
			if($(this).attr('checked') == true){
				data[$(this).attr('id')] = $(this).attr('id');
			}
		});
		
		$.get('/includes/ajax/add_basket_tmp_compl.php', { id: id, data: data }, function(json){
			//alert(json);
			var node = parseJSON(json);
			//alert(node);
			$('.basket_tmp').html(node.text);
			$('#all_price').text(node.price);
			//alert(node.text)
			showFlyBacket();
			//alert(id);
			/*
			$.get('/includes/ajax/add_basket_recom.php', { id: id }, function(json){
				//alert(json);
				//var text = eval(json.text);
				//var id = eval(json.id);
				var node = parseJSON(json);
				
				//$('#all_price').text(node.price);
				if(json != '') $('.buyItToo').show();
				
				$('#scroll_ul').html('');
				$('#scroll_ul').html(json);
				//alert($('#scroll_ul').html());
				showFlyBacket();
				
				/
				$.get('/includes/ajax/get_price_tovar.php', { id: id }, function(json){
					var node = parseJSON(json);
					alert(node.price);
					$('#all_price').text(node.price);
					return false;
				});
				
				//init();
				
				
			});
			*/
		});
		
		return false;
	})
	
	$('.buy .view_buy_div').livequery('click', function (){
		var id = $(this).attr('id');
		
		$.get('/includes/ajax/add_basket_tmp.php', { id: id }, function(json){
			//alert(json);
			$('.basket_tmp').html(json);
			
			$.get('/includes/ajax/add_basket_recom.php', { id: id }, function(json){
				//alert(json);
				//var text = eval(json.text);
				//var id = eval(json.id);
				
				
				
				if(json != '') $('.buyItToo').show();
				
				$('#scroll_ul').html('');
				$('#scroll_ul').html(json);
				showFlyBacket();
				
				$.get('/includes/ajax/get_price_tovar.php', { id: id }, function(json){
					var node = parseJSON(json);
					
					$('#all_price').text(node.price);
					return false;
				});
				
				//init();
				
				
			});
		});
		
		return false;
	})
	
	
	
	/*
	$('.addToFavBtn').livequery('click', function (){
		$.get('/includes/ajax/add_basket.php', { }, function(json){
			var node = parseJSON(json);
			
			$('#basket_count').text(node.basket_count);
			$('#basket_price').text(node.basket_price);
			
			$("#darkBg").fadeOut("fast");
			$("#flyBuy ").fadeOut("fast");
			
			$("#rArrow").unbind('click');
			$("#lArrow").unbind('click');
			$(".addToBuy").unbind('click');
			
			clear_tmp_basket();
			
			return false;
		});
		
		return false;
	})
	* */
	
	
	
	
	
});	

function metkaBlock (){
	$('.metka').hover (
		function (){
			var id = $(this).attr('id');
			
			$(this).children('.title-metka').css('display', 'block');
			
			$('#n_'+id).css('font-weight', 'bold');
			$('#n_'+id).css('color', '#1874C9');
		},
		function (){
			var id = $(this).attr('id');
			
			$(this).children('.title-metka').css('display', 'none');
			
			$('#n_'+id).css('font-weight', 'normal');
			$('#n_'+id).css('color', '#757575');
		}
	)
	
	$('.elem-point').hover (
		function (){
			var id = $(this).attr('id');
			
			id = id.substr(2);
			
			$('#'+id).children('.title-metka').css('display', 'block');
			$(this).css('font-weight', 'bold');
			$(this).css('color', '#1874C9');
		},
		function (){
			var id = $(this).attr('id');
			
			id = id.substr(2);
			
			$('#'+id).children('.title-metka').css('display', 'none');
			$(this).css('font-weight', 'normal');
			$(this).css('color', '#757575');
		}
	)
}

function parseJSON(text){
	if (text.replace(/\\./g, '@').
			replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
			replace(/(?:^|:|,)(?:\s*\[)+/g, '')) {

		j = eval('(' + text + ')');

		return typeof filter === 'function' ? walk('', j) : j;
    }else{
		return false;
	}
}

function clear_tmp_basket(){
	$.get('/includes/ajax/clear_basket_tmp.php', { }, function(json){
		
	});
}

function showFlyBacket() {
	// Отображаем темный прозрачный фон
	docHght = $(document).height();
	$("#darkBg").css("height", docHght);
	$("#darkBg").css("opacity", 0.7);
	$("#darkBg").fadeIn("normal");
	topH = $(document).scrollTop() + 20;
	$("#flyBuy").css("top", topH);
	$("#flyBuy").fadeIn("slow");
	
	$("#scroll").easySlider({
		controlsShow:	false,
		prevId: 		'lArrow',
		nextId: 		'rArrow'
	});
	
}
function onDarkBg(opac) {
		
	// Отображаем темный прозрачный фон
	docHght = $(document).height();
	$("#darkBg").css("height", docHght);
	$("#darkBg").css("opacity", opac);
	$("#darkBg").fadeIn("normal");
	
}

function hideUpLogin() {
		$(".inForUsers #userLogin").fadeOut("fast");
}

function showUpLogin() {
		$(".inForUsers #userLogin").fadeIn("normal");
}

function offDarkBg() {
	$("#darkBg").fadeOut("fast");
	hideUpLogin();
}
	
	
function init(){
	$('#sel_brand').change(function (){
		var value = $(this).attr('value');
		//var type = $('.type_tovar').attr('id');
		var type = $('#sel_docs').attr('value');
		//alert('hi');
		$.get('/includes/ajax/chenge_brand.php', { type: type, value: value }, function(json){
			//alert(json);
			//var node = parseJSON(json);
			//alert(node.text);
			$('#div_seria').html(json);
			$('#sel_seria').removeAttr("disabled");
		});
	})
	
	$('.fld input').click(function (){
		var id = $(this).attr('value');
		$('.vkl').hide();
		$('#adr_'+id).show();
		$('#address').attr('value', id);
		//$('.inpadr').attr('disabled', 'disabled');
		//$('#inp_'+id).removeAttr("disabled");
	});
	
	$('.menu li').click(function(){
		var id = $(this).attr('id');
		$('.menu li').removeClass('active');
		
		$(this).addClass('active');
		$('.contBlock').css('display', 'none');
		$('#dis_'+id).css('display', 'block');
	})
	
	$('.element .descr ul li a').hover(
		function (){
			var src = $(this).attr('title');
			var id = $(this).attr('class');
			
			$('#img_'+id).attr('src', '/files/item/value/'+src)
		},
		function (){
			
		}
	);
	
	// Вход для клиектов
	$("#inForUsers a.in").click(function(){
		showUpLogin();
		onDarkBg(0.7);
		//alert(1);
		return false;
	});
	
	
	
	
	
	
	
	//showFlyBacket();
	// Вылетающая корзина
	/*
	$(".m .header .backet .makeOrder").click(function(){
		showFlyBacket();
		return false;
	});
	*/
	// При клике по фону, все всплывшее убирается
	$("#darkBg").click(function(){ 
		offDarkBg();
		$(this).fadeOut("fast");
		$("#flyBuy").fadeOut("fast");
		
		$("#rArrow").unbind('click');
		$("#lArrow").unbind('click');
		$(".addToBuy").unbind('click');
		
		clear_tmp_basket();
	});
	$("#flyBuy .cont .closeButton").click(function(){ 
		$("#darkBg").fadeOut("fast");
		$("#flyBuy ").fadeOut("fast");
		
		$("#rArrow").unbind('click');
		$("#lArrow").unbind('click');
		$(".addToBuy").unbind('click');
		
		clear_tmp_basket();
	});
	
	// Подсветка пунктов главного меню при наведении
    $("#mainMenu li a").hover(function() {
		// Если это не активный раздел
		//alert($(this).parents("li").attr("class"));
		if ( $(this).parents("li").attr("class") != 'active' ) {
			$(this).parents("li").addClass("hov");
		}
			
	}, function() {
		// Если это не активный раздел
		if ( $(this).parents("li").attr("class") != 'active' ) {
			$(this).parents("li").removeClass("hov");
		}
	});
	
	// Разворачивание брендов
	$("#showAllBrendsReactor").click(function(){
		$(this).toggleClass("active");
		$("#allBrendsList").slideToggle();
	});
	
	// Разворачивание доп элементов расширенного поиска
	$(".megaFilter .extendFilter .extName").click(function(){
		$(this).toggleClass("active");
		$( ".hidBlock", $($(this).parent()) ).slideToggle();
	});
	
	function setWord(l, r, obj) {
		$(".inp1", $(obj).parent()).val(l);
		$(".inp2", $(obj).parent()).val(r);
	}
	if ( $('#priceBegunok1').length > 0 ) {
		$('#priceBegunok1').trackbar({
			// Этот кусок надо помещать внизу под бегунком, если заранее не известны все бегунки
			onMove : function() {
				obj = this;
				setWord(this.leftValue, this.rightValue, "#priceBegunok1");
			},
			width : 141,
			leftLimit : 1000, // unit of value
			leftValue : 6000, // unit of value
			rightLimit : 20000, // unit of value
			rightValue : 14000 // unit of value
		});
	}
	if ( $('#dlinaBegunok').length > 0 ) {
		$('#dlinaBegunok').trackbar({
			// Этот кусок надо помещать внизу под бегунком, если заранее не известны все бегунки
			onMove : function() {
				obj = this;
				setWord(this.leftValue, this.rightValue, "#dlinaBegunok");
			},
			width : 141,
			leftLimit : 1000, // unit of value
			leftValue : 6000, // unit of value
			rightLimit : 20000, // unit of value
			rightValue : 14000 // unit of value
		});
	}
	if ( $('#dlinaBegunok').length > 0 ) {
		$('#shirinaBegunok').trackbar({
			// Этот кусок надо помещать внизу под бегунком, если заранее не известны все бегунки
			onMove : function() {
				obj = this;
				setWord(this.leftValue, this.rightValue, "#shirinaBegunok");
			},
			width : 141,
			leftLimit : 1000, // unit of value
			leftValue : 6000, // unit of value
			rightLimit : 20000, // unit of value
			rightValue : 14000 // unit of value
		});
	}
	// ПОИСК
	$("form.search .inp").focus(function() {
		$(this).val("");
	});
	$("form.search .inp").blur(function(){
		//alert( $(this).val() );
		if ( $(this).val() == '' ) {
			$(this).val("поиск");
		}
	});
	
	// Гармошка в UL
	$(".garmoshkaType2 li a").click(function(){
		$("ul:first", $(this).parent()).slideToggle("fast");
		$(this).toggleClass("active");
		return false;
	});
	
	// Дополнительные цвета
	$("#showMoreColors").click(function(){
		if ( $("#otherColorList").css("display") != 'block' ) {
			$("#otherColorList").fadeIn("fast");
		} else {
			$("#otherColorList").fadeOut("fast");
		}
		
	});
	$("#yourMark .a1").hover(function(){
		$("#yourMark a").removeClass("active");
		$("#yourMark .a1").addClass("active");
	}, function() {
		$("#yourMark a").removeClass("active");
	});
	$("#yourMark .a2").hover(function(){
		$("#yourMark a").removeClass("active");
		$("#yourMark .a1").addClass("active");
		$("#yourMark .a2").addClass("active");
	}, function() {
		$("#yourMark a").removeClass("active");
	});
	$("#yourMark .a3").hover(function(){
		$("#yourMark a").removeClass("active");
		$("#yourMark .a1").addClass("active");
		$("#yourMark .a2").addClass("active");
		$("#yourMark .a3").addClass("active");
	}, function() {
		$("#yourMark a").removeClass("active");
	});
	$("#yourMark .a4").hover(function(){
		$("#yourMark a").removeClass("active");
		$("#yourMark .a1").addClass("active");
		$("#yourMark .a2").addClass("active");
		$("#yourMark .a3").addClass("active");
		$("#yourMark .a4").addClass("active");
	}, function() {
		$("#yourMark a").removeClass("active");
	});
	$("#yourMark .a5").hover(function(){
		$("#yourMark a").removeClass("active");
		$("#yourMark .a1").addClass("active");
		$("#yourMark .a2").addClass("active");
		$("#yourMark .a3").addClass("active");
		$("#yourMark .a4").addClass("active");
		$("#yourMark .a5").addClass("active");
	
	}, function() {
		$("#yourMark a").removeClass("active");
	});
	
	// УДАЛЕНИЕ ИЗ ЛЕТ ОКНА
	$("#flyBuy .cont .buyList .element .delButton").click(function() {
		var id = $(this).parent().attr('id');
		b = this;
		$(b).parents(".element:first").fadeOut("normal", function(){ $(b).remove(); });
		
		$.get('/includes/ajax/del_basket_tmp.php', { id: id }, function(json){
			var node = parseJSON(json);
			
			$('#all_price').html(node.price);
			
			return false;
		});
		
		return false;
	});
	// МИНУС В КОРЗИНЕ
	$(".backetBlock .resultOrderTable tr td .minus").click(function(){
		$("input", $(this).parent())
		
		valOfFld = parseInt($("input", $(this).parent()).val());
		if ( valOfFld > 1 ) {
			$("input", $(this).parent()).val(valOfFld - 1);
			var id = $(this).parent().attr('id');
			
			$.get('/includes/ajax/inc_dec_basket.php', { id: id, action: 0 }, function(json){
				var node = parseJSON(json);
				
				$('#all_price_'+node.id).html(node.price);
				$('#all_price2').html(node.all_price);
				$('#all_price1').html(node.all_price);
				$('#all_count1').html(node.all_count);
			});
		}
		//plusorMinus(-1, $(obj), 1);
		
	});
	
	/*
	 * Изменение количества товара вручную (без нажатия на кнопки "+" и "-") 
	 * */
	$(".backetBlock .inp").keyup(function(){
		var count = $(this).attr('value');
		
		var id = $(this).parent().parent().attr('id');
		//alert(id);
		//alert(count);
		$.get('/includes/ajax/count_basket.php', { id: id, count: count }, function(json){
			var node = parseJSON(json);
			
			$('#all_price_'+node.id).html(node.price);
			$('#all_price2').html(node.all_price);
			$('#all_price1').html(node.all_price);
			$('#all_count1').html(node.all_count);
		});
	});
	
	// ПЛЮС В КОРЗИНЕ
	$(".backetBlock .resultOrderTable tr td .plus").click(function(){
		valOfFld = parseInt($("input", $(this).parent()).val());
		//alert('hi');
		//alert(valOfFld);
		$("input", $(this).parent()).val(valOfFld + 1);
		//plusorMinus(+1, '.cntBlock .field input', 1);
		var id = $(this).parent().attr('id');
		//alert(id)
		$.get('/includes/ajax/inc_dec_basket.php', { id: id, action: 1 }, function(json){
			//alert(json)
			var node = parseJSON(json);
			
			$('#all_price_'+node.id).html(node.price);
			$('#all_price2').html(node.all_price);
			$('#all_price1').html(node.all_price);
			$('#all_count1').html(node.all_count);
		});
	});
	// УДАЛЕНИЕ
	$(".backetBlock .resultOrderTable tr td.del a").click(function() {
		b = this;
		c = $(".delimer", $(b).parents("tr:first").prev());
		$(b).parents("tr:first").fadeOut("normal", function(){
			$(b).remove();
			$(c).remove();
		});
		
		var id = $(this).attr('id');
		$.get('/includes/ajax/del_basket.php', { id: id }, function(json){
			var node = parseJSON(json);
			
			$('#all_price2').html(node.price);
			$('#all_price1').html(node.price);
			$('#all_count1').html(node.all_count);
			
			return false;
		});
	});
	$("#flyBuy .cont .buyList .element .delButton").click(function() {
		b = this;
		$(b).parents(".element:first").fadeOut("normal", function(){ $(b).remove(); });
	});
	// Увеличение и уменьшение
	function plusorMinus(to, obj, step) {
		
		alert(obj)
		
		
		//alert(valOfFld);
		if ( to > 0 ) {
			$(obj).val(valOfFld + 1);
		} else {
			if ( valOfFld > 1 ) {
				$(obj).val(valOfFld - 1);
			}
		}
	}
	
	// Гармошка тип 4
	$(".garmoshkaType4 .elt .reactorMain").click(function(){
		//alert(1);
		//alert( $(".hidBlock", $(this).parent()).attr("class") );
		//alert($(".megaFilterForm", $(this).parent()).css("display"));
		//if ( $(".megaFilterForm", $(this).parent()).css("display") != 'block' ) {
			//alert('ok');
			$(".garmoshkaType4 .elt .reactorMain").removeClass("active");
			$(this).addClass("active");
			$(".garmoshkaType4 .elt .megaFilterForm").slideUp("fast");
			$(".megaFilterForm", $(this).parent()).slideDown("fast");
		//}
		
		
	});
	$(".filterTd .garmoshkaType4 .elt .megaFilterForm:first").css("display", "block");
	$(".filterTd .garmoshkaType4 .elt .reactorMain:first").addClass("active");
	
	// Всплывающее меню
	$(".subMenuTable tr td .relBlock").hover(function(){
		if ( $(".flyBlock", this).length ) {
			//	 alert("OPA!!!");
			$("a:first", this).css("padding-bottom", "10px");
		}
		
		$("a:first", this).addClass("hov");
		
		$(".flyBlock", this).slideDown("fast");
		
	}, function() {
			$("a:first", this).css("padding-bottom", "0");
		$("a:first", this).removeClass("hov");
		$(".flyBlock", this).slideUp("fast");	
	});
	
	$(".popup_basket").fancybox({
		"frameWidth" : 400, 
		"frameHeight" : 800,
		"overlayOpacity": "0.7",
		"overlayColor": "black"
	});
	
	if ( $(".mainPic a").length != 0 )  {
		$(".mainPic a").fancybox({
			"hideOnContentClick": false,
			"titlePosition"  : "inside",
			"overlayOpacity": "0.7",
			"overlayColor": "black"
		});
		
		// Клик по маленьким иконкам
		$(".picGal .dopForPic .otherPics a").click(function(){
			$(".picGal .dopForPic .otherPics a").removeClass("active")
			$(this).addClass("active");
			path = $(this).attr("href");
			pathToVeryBig = $(this).attr("rel");
			$(".picGal .mainPic a").attr("href", pathToVeryBig);
			$(".picGal .mainPic a img").attr("src", path);
			//alert(1);
			return false;
		});
		
		$(".picGal .otherPicsPlace2 a").click(function(){
			$(".picGal .otherPicsPlace2 a").removeClass("active")
			$(this).addClass("active");
			path = $(this).attr("href");
			pathToVeryBig = $(this).attr("rel");
			$(".picGal .mainPic a").attr("href", pathToVeryBig);
			$(".picGal .mainPic a img").attr("src", path);
			//alert(1);
			return false;
		});
	}
}	


