$(document).ready(function(){

$(function() {
  var string = 3;
  var product_amount = $(".product").size();
  var product_height = $(".product").height();
  var height = parseFloat((product_amount/string));
  var height = Math.ceil(height);
  var list_height = product_height*height+30;
  $(".catalog_list").css("height", list_height);
});


$("a.fancybox").live("mousedown", function(){ 
	$(this).fancybox({
		'titlePosition'	: 'over',
		'overlayColor'	: '#444444',
		'overlayOpacity': 0.3		
		});
});


// Анимация дерева страниц

$("div.menu_left ul li.open a.open").toggle(function(){
		var open = $(this).next().attr("open");
		if (open != "active") {
		$(this).next().slideDown("slow");		
		$(this).next().attr("open", "active");		
		$(this).parent().addClass("show");
		$(this).addClass("active");		
		} else {
		$(this).next().slideUp("slow");
		$(this).next().attr("open", "");		
		$(this).parent().removeClass("show");
		$(this).removeClass("active");		
		}

	}, function(){
		var open = $(this).next().attr("open");
		if (open != "active") {
		$(this).next().slideDown("slow");		
		$(this).next().attr("open", "active");		
		$(this).parent().addClass("show");
		$(this).addClass("active");			
		} else {
		$(this).next().slideUp("slow");
		$(this).next().attr("open", "");		
		$(this).parent().removeClass("show");
		$(this).removeClass("active");		
		}	
	}
);	


// Анимация скрытых покатегорий страниц

$("div.menu_left ul div.more a").toggle(function(){
		var el = $(this);
		var id_more = $(el).attr("id_more");
		$("div.menu_left ul div.more_cat").each(function(){
			if ($(this).attr('id_more_cat') == id_more) {
				$(el).empty().append("Скрыть...");
				$(el).parent().addClass("show");				
				$(el).parent().addClass("close");
				$(this).slideDown();
			}
		});
	
	}, function(){
		var el = $(this);
		var id_more = $(el).attr("id_more");
		$("div.menu_left ul div.more_cat").each(function(){
			var el_cat = $(this);
			if ($(this).attr('id_more_cat') == id_more) {
				$(el).empty().append("Еще...");
				$(el).parent().removeClass("show");				
				$(el).parent().removeClass("close");
				$(el_cat).slideUp();
			}
		});
	}
);


// Анимация дерева каталога

	$("div.menu_top a").mouseover(function(){
		var submenu = $(this).next("ul");
		$(submenu).stop(true, true);		
		$(this).next("ul").show(); 
		
		$(this).hover(function() {
        }, function(){ 
			$(submenu).stop(true, true);		
            $(this).next("ul").hide();
        });
		
        $(submenu).hover(function() {
			$(submenu).stop(true, true);
			$(submenu).show();
        }, function(){
            $(submenu).hide();
        });		
	});


// Анимация скрытых покатегорий каталога

$("div.menu_top ul div.more a").toggle(function(){
		var el = $(this);
		var id_more = $(el).attr("id_more");
		$("div.menu_top ul div.more_cat").each(function(){
			if ($(this).attr('id_more_cat') == id_more) {
				$(el).empty().append("Скрыть...");
				$(el).parent().addClass("show");				
				$(el).parent().addClass("close");
				$(this).slideDown();
			}
		});
	
	}, function(){
		var el = $(this);
		var id_more = $(el).attr("id_more");
		$("div.menu_top ul div.more_cat").each(function(){
			var el_cat = $(this);
			if ($(this).attr('id_more_cat') == id_more) {
				$(el).empty().append("Еще...");
				$(el).parent().removeClass("show");				
				$(el).parent().removeClass("close");
				$(el_cat).slideUp();
			}
		});
	}
);


// Поиск по каталогу

$("a#search").live("click", function(){
	var attr = $(this).parent().attr("id");
	var word = $("input#word_search").val();
	var params = new Object();
	params.word = word;
	$.get('/search.php', params, function(data){
	if (attr == "top"){$.scrollTo( {top:320, left:0}, 800, function(){});}
		$("div.search#top").remove();
		$("div#content").empty().append(data).hide();
		$("div#content div#search_result").animate({opacity:"hide"}, 1200, function(){
		$("div#content").show();
		$("div#content div#search_result").hide();
		$("div#content div#search_result").animate({opacity:"show"}, 1200, function(){

		
		}); 		
		});
	});
	return false;
});


});	
