$(document).ready(function(){

	if ($("#ie6").length!=0) var global_IE6 = true; else var global_IE6 = false;
	if (global_IE6 || $("#ie7").length!=0  || $("#ie8").length!=0) var global_IE = true; else var global_IE = false;
	
	// Mainmenu
	$(".mainmenu li.cur").parents("li").addClass("cur").find(">a").wrap("<span></span>");
	$("#catalog_panel .switcher li.show a").click(function(){
		var li = $(this).parents("li");
		var lis = $(this).parents("ul").find("li");
		var panel = $("#catalog_panel");
		var panel_content = panel.find(".panel_content");
		var a_close = $("#catalog_panel .close");
		lis.removeClass("cur");
		li.addClass("cur");
		panel.addClass("active");
		panel.animate({width:"95%"},500,"easeOutCubic",function(){ panel_content.slideDown(500,function(){ a_close.show(); }); });
		return false;
	});
	$("#catalog_panel .switcher li.hide a").click(function(){
		var li = $(this).parents("li");
		var lis = $(this).parents("ul").find("li");
		var panel = $("#catalog_panel");
		var panel_content = panel.find(".panel_content");
		var a_close = $("#catalog_panel .close");
		a_close.hide();
		lis.removeClass("cur");
		li.addClass("cur");
		panel.removeClass("active");
		panel_content.slideUp(500,function(){ panel.animate({width:"215"},500,"easeOutCubic"); });
		return false;
	});
	$("#catalog_panel .close a").click(function(){
		var panel = $("#catalog_panel");
		var panel_content = panel.find(".panel_content");
		var a_close = $("#catalog_panel .close");
		$("#catalog_panel .switcher li").removeClass("cur");
		$("#catalog_panel .switcher .hide").addClass("cur");
		a_close.hide();
		panel.removeClass("active");
		panel_content.slideUp(500,function(){ panel.animate({width:"215"},500,"easeOutCubic"); });
		return false;
	});
	$("#catalog_panel .panel_content .part").each(function(){
		var part = $(this);
		var li_long = part.find("ul.temp>li").length;
		var li_temp = 0;
		
		$("<ul class='col_1'></ul><ul class='col_2'></ul><ul class='col_3'></ul><ul class='col_4'></ul><div class='clear'></div>").appendTo(this);
		part.find("ul.temp>li").each(function(){
			var li = $(this);
			var li_html = li.html();
			li_temp++;
			$("<li>"+li_html+"</li>").appendTo(part.find(".col_"+Math.ceil((li_temp/li_long)*4))[0]);
		});
		part.find("ul.temp").remove();
	});
	$("#catalog_panel .panel_content .part:last-child").addClass("last_part");
	if ($("#index_catalog .item").length!=0) {
		$("#index_catalog").scrollable({
			size: 1,
			horizontal:true,
			onSeek: function(){ $("#index_catalog").scrollable("refreshText"); },
			prev:'.prev',
			next:'.next'
		});
		$("#index_catalog").each(function(){
			var count = 0;
			$(this).find(".item").each(function(){count++;});
			if(count>1)$(this).find('.next').addClass('next_active');
		});
		$("#index_catalog *").disableTextSelect();
		$("#index_catalog").scrollable("seekTo",(Math.floor(Math.random()*($("#index_catalog .item").length-1+1)+1)),2000);
		$("#index_catalog").scrollable("refreshText");
	}
	$("#index_catalog .prev").mouseenter(function(){ $(this).addClass("prev_hover") }).mouseleave(function(){ $(this).removeClass("prev_hover") });
	$("#index_catalog .next").mouseenter(function(){ $(this).addClass("next_hover") }).mouseleave(function(){ $(this).removeClass("next_hover") });
	
	if ($(".product_gallery .item").length!=0) {
		$(".product_gallery").scrollable({
			size: 3,
			horizontal:true,
			onSeek: function(){  },
			prev:'.prev',
			next:'.next'
		});
		$(".product_gallery").each(function(){
			var count = 0;
			$(this).find(".item").each(function(){count++;});
			if(count>1)$(this).find('.next').addClass('next_active');
		});
		$(".product_gallery *").disableTextSelect();
	}
	$(".product_gallery .prev").mouseenter(function(){ $(this).addClass("prev_hover") }).mouseleave(function(){ $(this).removeClass("prev_hover") });
	$(".product_gallery .next").mouseenter(function(){ $(this).addClass("next_hover") }).mouseleave(function(){ $(this).removeClass("next_hover") });
	$(".product_gallery .items .item").mouseenter(function(){
		 $(this).addClass("item_hover");
		 $(this).find(".mark").css("left",($(this).find("td img").offset().left-$(this).offset().left+$(this).find("td img").width()-$(this).find(".mark").width()-4)+"px").css("top",($(this).find("td img").offset().top-$(this).offset().top+$(this).find("td img").height()-$(this).find(".mark").height()-4)+"px");
	}).mouseleave(function(){ $(this).removeClass("item_hover") });
	$(".product_gallery .item a.img").lightBox();
	$("#catalog_list dl:nth-child(3n-1)").next().addClass("clear");
	$(".text table").addClass("simple_table").attr("cellspacing","0").attr("cellpadding","0");
	var order_duration = 150;
	/*$(".simple_table tr").mouseenter(function(){
		var tds = $(this).find("td");
		if ($(this).parents("table").hasClass("order_table")) {
			$("<div class='buy'><a href=''>Купить со скидкой</a></div>").appendTo(tds[0]);
			var order_link = $(this).find(".buy");
			order_link.show();
		}
		tds.animate({backgroundColor:"#104656"},order_duration);
		
	}).mouseleave(function(){
		var tds = $(this).find("td");
		if ($(this).parents("table").hasClass("order_table")) {
			var order_link = $(this).find(".buy");
			order_link.hide();
			order_link.remove();
		}
		if ($(tds[0]).hasClass("odd"))
			tds.animate({backgroundColor:"#328ab2"},order_duration);
		else
			tds.animate({backgroundColor:"#0e769d"},order_duration);
	});*/
	$(".simple_table tr td:last-child, .simple_table tr th:last-child").css("border-right","0");
	$(".simple_table tr:last-child td").css("border-bottom","0");
	$(".simple_table tr:even td").addClass("odd");
	
	// AfterLoad
	var afterLoad = function(){
		
		if ($("#response li a").length!=0 && !global_IE6) {
			$("#response li a").lightBox();
		}
		
		return false;
	}
	var isChrome = function() {
		if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
			return true;
			chrome_version = navigator.userAgent.replace(/^.*Chrome\/([\d\.]+).*$/i, '$1')
		} else return false
	}
	if (isChrome()) $(window).load(afterLoad); else $(window).load(afterLoad());
	
});
