$(document).ready(function() {
	$('#rootSelected').next('ul').slideDown();
	$('#subSelected').parent('li').parent('ul').slideDown();
	
    $('#carted-cont').load('/bitrix/templates/.default/cart.php');
     $('.add2cart').click(function(){
      var id = $(this).attr('rel');
      $('.added').fadeIn('slow').delay(800).fadeOut('slow');
		 $.post("/bitrix/templates/.default/cart.php", { adding:'Y',PID:id },
				   function(data){
				     RefreshMiniCart();
		 });      
      
      return false;        
     });

     $('.lm-slide').click(function(){
     	if($(this).next('ul').is(':visible') == false) {
	     	$('.ul_lvl_1').each(function(i){
	     		if($(this).is(':visible') == true) {
	     			$(this).slideUp('slow');
	     		}
	     	});
	     	$(this).next('ul').slideDown('slow');
	     	$('.indexTop:gt(3)').fadeIn('slow');
     	} else {
     		$(this).next('ul').slideUp('slow');
     		$('.indexTop:gt(3)').fadeOut('slow');
     	}
     	return false;
     });

     
	if($('#gmodelVal').val() != '') {
		$('#gmodel li').each(function(i){
			if($(this).attr('rel') == $('#gmodelVal').val()) {
				$('#gmodelName div').html($(this).html());
			}
		});
	}
	if($('#gtypeVal').val() != '') {
		$('#gtype li').each(function(i){
			if($(this).attr('rel') == $('#gtypeVal').val()) {
				$('#gtypeName div').html($(this).html());
			}
		});
	}	
	if($('#gserialVal').val() != '') {
		$('#gserial li').each(function(i){
			if($(this).attr('rel') == $('#gserialVal').val()) {
				$('#gserialName div').html($(this).html());
			}
		});
	}	
	
    $('.g-filter td').hover(
            function() {
                $(this).find('ul').slideDown('100');
            },
            function() {     
                $(this).find('ul').slideUp('100');
            }
        );
    $('.g-filter td ul li').hover(
            function() {
                $(this).addClass('sel');
            },
            function() {     
            	$(this).removeClass('sel');
            }
        );
    $('.g-filter td ul li').click(function(){
			var uid = $(this).parent('ul').attr('id');
			var gval = $(this).attr('rel');
			var gname = $(this).html();
			$('#'+uid+'Val').val(gval);
			$('#'+uid+'Name div').html(gname);
			$(this).parent('ul').slideUp('100');
    });

    $('#gfind').click(function(){
			/*$('#g-form').submit();*/
    })     
     
});


			showMenu = function(){
				$li = $(this).parent();
				$id_link = $li.attr("id");
				
				if($li.hasClass("open")){
					$("li.pr_lvl_1").removeClass("open");
					$("li.pr_lvl_1").not(".open").find("ul").slideUp(300);
					//$.cookie("show_id","");
				}
				else{
					$("li.pr_lvl_1").removeClass("open");
					$li.find("ul").slideDown(300);
					$li.addClass("open");
					$("li.pr_lvl_1").not(".open").find("ul").slideUp(300);
					//$.cookie("show_id",id_link);
				}
			}
			
			$(".sl").find("li.pr_lvl_1 span").click(showMenu);


function RefreshMiniCart() {
	$("#carted-cont").load("/bitrix/templates/klimatikum/js/cart.php");
}


function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';ёёёёёёёёё
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}
