
	$(document).ready(function (){
		//Переключалка табов
		$('ul.type li').click(function (){
			$(this).parent().find('.selected').removeClass('selected');
			$(this).addClass('selected');
			index = $('ul.type li').index(this);
			$('table.dimension').addClass('none').eq(index).removeClass('none');
			$('#size_type').val($(this).text().indexOf('Дюймы') >= 0 ? 'i' : 'm');
		});

		//Добавление нового типразмера
		$('.addRow').click(function (){
			table = $(this).parent().parent().parent().parent();
			standart = table.find('tr').eq(table.find('tr').length - 1);
			newRow = standart.clone(true).appendTo(table);

			if($.browser.mozilla || $.browser.safari){
				standartSelects = standart.find('select');
				newSelects = newRow.find('select');
				newSelects.each(function (){
					index = newSelects.index(this);
					this.selectedIndex = standartSelects.eq(index).attr('selectedIndex');
				});
			}

            newRow.find('select').each(function (){
				this.name = this.name.replace(/\[\d\]/, '['+(table.find('tr').length-2)+']');
			});
			newRow.find('input').each(function (){
				this.name = this.name.replace(/\[\d\]/, '['+(table.find('tr').length-2)+']');
			});

			if(table.find('tr').length > 4) $(this).parent().html('&nbsp;');
			return false;
		});

		//Отображалка производителей
		$('.manufacturer .select').click(function (){
			but = $(this).parent();
			header = $('.manufacturer strong');
			but.toggleClass('close');
			but.hasClass('close') ? header.html('Поиск по всем производителям.') : header.html('Производители.');
			return false;
		});

		//Отмечалка производителей
		$('.getAll').click(function (){
			but = $(this);
			box = but.parent();
			flag = but.hasClass('all');
			but.toggleClass('all');
			but.html(flag ? 'выбрать все' : 'снять все');
			box.find('input').each(function (){
				this.checked = !flag;
			});
			return false;
		});

		$('.disk-manufacturer input').click(function (){
			collection = $(this).parent().find('select');
			collection.attr({'disabled':true});
			collection.filter('.' + this.id).attr({'disabled':!this.checked});
		});
	});