$(document).ready(function() {
	fast_choice();
	certificates();
	new_goods();
	$(".top_nav li").append('<div class="nib"></div>');
	$(".top_nav li").not("li.active").hover(
		function(){$(this).addClass("hover")},
		function(){$(this).removeClass("hover")}
	);
	
	$(".logo").after('<div class="logo_line"></div>');
	
	$(".index_image_block .coda-slider").codaSlider({dynamicArrows: false})
	$(".index_new_goods .coda-slider").codaSlider({dynamicArrows: false})
	$(".index_right_column .coda-slider").codaSlider({dynamicArrows: false})

	if ($(".trail a").length>0){$(".trail a").not(".trail ul li:last-child a").after("&nbsp;&nbsp;/&nbsp;");}
	$(".trail li:last-child").addClass("last");

	$(".inner_container").parent().css("backgroundPosition","center 200px");

	$(".our_managers .item:odd").not(".our_managers .item:last-child").after('<br clear="all" />');
	$(".our_managers_hd").click(function(){$(".our_managers").slideToggle(400); return false;});

	$(".accordeon .trigger").click(function(){$(this).parents(".accordeon").toggleClass("ready");$(this).toggleClass("trigger_expanded").next(".collapsable").slideToggle(400); return false;});
	
	$(".collapsable").each(function(){
		$(this).children(".certificate_item:odd").addClass("certificate_odd_item").not($(this).children(".certificate_item:last")).after('<br clear="all" />');
	});
	
	$(".certificate_popup .close").click(function(){$(this).parent().slideUp(400, function(){$(".shade").fadeOut(400); $(".container").animate({paddingBottom:'0px'}, 400)}); return false;});
	
	$(".dropdown .selected").wrapInner('<div class="wrapper"></div>');
	$(".dropdown").click(
		function(){$(this).toggleClass("dropped").children(".popup").slideToggle(200)}
	);
	
	$(".two_cols li:odd").not(".two_cols li:last-child").css("float","right").after('<li class="closer"></li>');
	$(".new_goods .coda-slider").codaSlider({dynamicArrows: false})
	$(".new_goods .panel").each(function(){
		$(this).children(".item:last").addClass("last_item");
	});
	$(".new_goods .item").hover(
		function(){$(this).css("zIndex",'200').addClass("item_hover");},
		function(){$(this).css("zIndex",'100').removeClass("item_hover");}
	);

	$(".compare tr:odd").addClass('odd');
	$(".compare tr").not(".compare tr:first-child").hover(
		function(){$(this).addClass("item_hover");},
		function(){$(this).removeClass("item_hover");}
	);
	$(".compare .coda-slider").codaSlider({dynamicArrows: false})
	
	$(".separated_trigger_bullet").click(
		function(){$(this).parent().nextAll(".anti_series_list").slideToggle(300).next(".series_list").slideToggle(300); return false}
	);
});

function certificates(){
					$(".certificate_item .zoom_link").click(function(){
						d_pic = $(this).parents(".certificate_item").find(".detail_picture").html();
						if($(this).parents(".certificate_item").find(".detail_text")) d_text = $(this).parents(".certificate_item").find(".detail_text").html();
						h = $(this).parents(".certificate_item").find(".detail_picture img").attr("height");
						w = $(this).parents(".certificate_item").find(".detail_picture img").attr("width");
						$(".certificate_popup .pic_d").html(d_pic);
						if(d_text) {$(".certificate_popup .descr_d").html(d_text);$(".certificate_popup .descr_d").css("display","block");} else $(".certificate_popup .descr_d").css("display","none");
						$(".certificate_popup").css("width",w+"px");						
						$(".shade").fadeTo(400, 0.7, function(){
							var new_pad_bot = 0;
							if ($(window).scrollTop()+$(".certificate_popup").height()>$(document).height()){$(".container").animate({paddingBottom:$(window).scrollTop()+$(".certificate_popup").height()-$(document).height()+80+'px'},400);}
							t = $(window).scrollTop()+(($(window).height()-h)/2)+50;
							$(".certificate_popup").css({top:t+'px', left:($('body').width()-$(".certificate_popup").width())/2+'px'}).slideDown(400);
						});
						return false;
					})	
	}
	
function new_goods(){
		$(".new_goods a.item").click(function(){
			if($(this).find(".detail_picture").length){
				d_pic = $(this).find(".detail_picture").html();
				h = $(this).find(".detail_picture img").attr("height");
				$(".certificate_popup .pic_d").html($(this).find(".detail_picture").html());
							
				$(".shade").fadeTo(400, 0.7, function(){
				var new_pad_bot = 0;
				if ($(window).scrollTop()+$(".certificate_popup").height()>$(document).height()){$(".container").animate({paddingBottom:$(window).scrollTop()+$(".certificate_popup").height()-$(document).height()+80+'px'},400);}
				t = $(window).scrollTop()+(($(window).height()-h)/2)+50;
				$(".certificate_popup").css({top:t+'px', left:($('body').width()-$(".certificate_popup").width())/2+'px'}).slideDown(400);
				});
				return false;	
			}
		});
	}
	
function fast_choice(){
		 $(".fast_choice select.fc_brand").change(function(){
				brand_id = $(this).val();
				$.get("/include/ajax.php",{ type: "fast_choice", brand_id: brand_id}, function(data){
				if(data) $(".fast_choice .select").html(data);
				else $(".fast_choice .select").html("");
				});	
			});	
	}
