$(document).ready(function(){
	
	$('.foo ul li').width($('.foo').width());
	
	
	$('#footer ul li:last').css({
		'padding-right':'0',
		'margin-right':'0',
		'background':'none'
	})
	
	// LOGIN FORM SHOW	
	$('.head .top li.login span a').click(function(){
		var login = $('li.login div.log');
		if($('li.login div.log').css('display')=='none') {
			login.fadeIn('fast');
			$(this).parent().addClass('active');
		}else{
			 login.fadeOut('fast');
			 $(this).parent().removeClass('active');
		}
	});
	
	// SUB FORM SHOW	
	$('.subscr a').click(function(e){
		e.preventDefault();
		var subs = $('.subscr div.sub');
		if(subs.css('display')=='none') {
			subs.fadeIn('fast');
			$(this).parent().addClass('active');
		}else{
			 subs.fadeOut('fast');
			 $(this).parent().removeClass('active');
		}
	});
	
	// MENU HEAD
	$(".head .menu li.mn1").hover(function(){
		$(this).children('ul').fadeIn(300);
		$(this).children('div.ug').fadeIn(300);
		$(this).addClass('active');
	},function(){
		$(this).children('ul').fadeOut(200);
		$(this).children('div.ug').fadeOut(200);
		$(this).removeClass('active');
	});
	$('.head .menu li.mn1:last').css('background','none');
	$('.head .menu li.mn1 ul').each(function(i){
		$(this).children('li:last').css('background','none');
		var wUL = 0;
		$(this).children('li').each(function(j){
			$(this).css('width',$(this).width()+'px');
			wUL = wUL + $(this).width();
		});
		//alert(wUL);
		$(this).css('width',wUL+5+'px');
	});
	$('.head .menu li.mn1 ul').hide();
	
	// SHOW MORE INF INDEX
	var nH = $('.news').height();
	$('.about_index .a_content span.more').click(function(){
		$('.about_index .a_hide').slideDown(400);
		//$('.news').animate({'height':'0px'},400);
		$('.news').slideUp(400);
		//$('.news').fadeOut(400);
		$('span.more').hide();
		$('span.hide_more').show();
	});
	$('.about_index .a_content span.hide_more').click(function(){
		$('.about_index .a_hide').slideUp(400);
		//$('.news').animate({'height':nH+'px'},400);
		$('.news').slideDown(400);
		//$('.news').fadeIn(400);
		$('span.more').show();
		$('span.hide_more').hide();
	});
	
	// FORM
	$('.form .input input,.form .input textarea').focus(function(){
		$(this).parent().addClass('focus');
	});
	$('.form .input input,.form .input textarea').blur(function(){
		$(this).parent().removeClass('focus');
	});
	
	// TABLE CATALOG
	$('.catalog_t tr').each(function(){
		$(this).children('td:last').css('border-right','2px solid #fff');
		$(this).children('td:first').css('border-left','2px solid #fff');
	});
	$('.catalog_t tr').mouseover(function(){
		$(this).addClass('hover');
		$(this).children('td:last').css('border-right','2px solid #ffa04d');
		$(this).children('td:first').css('border-left','2px solid #ffa04d');
	}).mouseout(function(){
		$(this).removeClass('hover');
		$(this).children('td:last').css('border-right','2px solid #fff');
		$(this).children('td:first').css('border-left','2px solid #fff');
	});
		
	// PRODUCT TAB IMG
	$('.tab img').hide();
	$('.tab h5').toggle(function(){
		$(this).parent().children('img').fadeIn(300);
		$(this).addClass('active');
	},function(){
		$(this).parent().children('img').fadeOut(300);
		$(this).removeClass('active');
	});

	// VKLADKI
	$('.v_desc').hide();
	$('.v_desc:first').show();

	$('ul.vkl li a').click(function(e){
		e.preventDefault();
		var num = $(this).attr('id').replace(/v/,"");
		if ($(this).parent('li').attr('class')=='active') $(this).parent('li').removeClass('active');
		else $(this).parent('li').addClass('active');
		var massDivCont = $('.v_desc');
		for(var i=0; i<massDivCont.length;i++){
			if (i==num){
				if ($(massDivCont[i]).css('display')=='none') $(massDivCont[i]).slideDown(400);
				else $(massDivCont[i]).slideUp(400);
			}
		}
	});

	$('ul.vkl li:first').attr('class','active');
	$('ul.vkl li:last').css('background','none');

	// TABLE STYLE
	$('.v_desc table tbody tr:first').addClass('title');
	$('.v_desc table tbody tr:not(.content table tbody tr:first):odd').addClass('next');

	//CATALOG LIST 2
	var $img = $('.catalog_list li');
	// ждем загрузки картинки браузером
	$img.load(function(){
		// удаляем атрибуты width и height
		$(this).removeAttr("width")
			   .removeAttr("height")
			   .css({ width: "", height: "" });
	 
		// получаем заветные цифры
		var width  = $(this).width();
		var height = $(this).height();
		//$(this).css({
		//	'margin-top':-(height/2)+'px',
		//	'margin-left':-(width/2)+'px'
		//});
	});
	
	$('.catalog_list li').each(function(){
		var descH = $(this).children('div.desc').height();
		var titH = $(this).children('div.tit').height();
		var imgH = $(this).children('div.img').height();
		var maxZ = Math.max.apply(null,$.map($(this).children('div'), function(e,n){
                return parseInt($(e).css('height'))||1 ;
           })
		);
		//alert(maxZ+'|'+titH+'|'+imgH+'|'+descH);
		$(this).children('div.img').css('padding-top',(maxZ-imgH)/2+'px');
		$(this).children('div.desc').css('padding-top',(maxZ-descH)/2+'px');
		$(this).children('div.tit').css('padding-top',(maxZ-titH)/2+'px');
	});
	
	$('.catalog_list li').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	
});
$(window).resize(function(){
	$('.foo ul li').width($('.foo').width());
	//location.reload();
	//location='';
});
