$(function () {
	$(document).ready(
	function() {
		var wholeHeight=document.getElementsByTagName('body')[0].offsetHeight-$('.b-header')[0].offsetHeight-$('.b-menu-container')[0].offsetHeight-
		$('.b-copyright')[0].offsetHeight-$('.b-footer')[0].offsetHeight-92;
		
		$('#allContent').css('min-height',wholeHeight+'px');
		if ($.browser.msie&&($.browser.version==6)) {
			$('#allContent').css('height',wholeHeight-2+'px');
			
		}
		$('.dealers-trademark').show();
	});
	$('table.dealers tbody tr:first-child')
		.addClass('first-child');
	$('table.dealers tbody tr:last-child')
		.addClass('last-child');
	
	$('table.dealers tr').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('.dealers-trademark h3 span.a')
		.addClass('link')
		.toggle(
			function() {
				$(this).addClass('active');
				$(this).parent().parent().children('.dealers-content').slideDown('slow');
			},
			function() {
				$(this).removeClass('active');
				$(this).parent().parent().children('.dealers-content').slideUp('slow');
			}
		);
	
	$('.dealers-trademark .dealers-content').hide();
	
//	$('.dealers-trademark:first h3 span.a').click();
	
	$('<p class="show-all"><span class="link">Показать всё</span></p>')
		.insertBefore('.dealers-trademark:first')
		.children('span').toggle(
			function() {
				$('.dealers-trademark h3 span.a').not('.active').click();
				$(this).html('Скрыть всё');
			}, function() {
				$('.dealers-trademark h3 span.a.active').click();
				$(this).html('Показать всё');
			});

	function t(element) {
		 $(element).click(function(){
					 if($(this).parent().next().is(':visible')) {
						$(this).parent().next().hide();
						$(this).css('border-bottom-width','1px');
					 }
					 else {
						$(this).parent().next().show();
						$(this).css('border-bottom-width','0');					
	
					 }
		 		});
	}
	function m(element) {
		 $(element).click(function(){
					 if($(this).parent().find('.b-video').is(':visible')) {
					 	
						$(this).parent().find('.b-video').hide();
					 }
					 else {
						$(this).parent().find('.b-video').show();				
					 }
		 		});
	}
	t('.video-list .b-video-theme span');
	m('.video-list img.l-block');
	$('.b-partner-materials').click(function(e){
		var sel=$(this).find('.b-materials-selection');
		if (sel.is(':visible')) {
			sel.slideUp(200);
		}
		else {
			sel.slideDown(200);
		}
		e.stopPropagation();
	});
	$('.b-partner-materials a').click(function(e){
		e.stopPropagation();
	}); 
	$('body').click(function(){
		if ($('.b-partner-materials .b-materials-selection').is(':visible'))
		$('.b-partner-materials .b-materials-selection').slideUp();
	});
	
	$('#seminar-form .b-btn-add-on').live('click',function() {
		var phoneItem=$("<div class='b-phone-item'>\
				<div class='l-block b-fields-group'>\
					+7 <input class='b-smallest-field-2' name='area_code[]' id='city-code-semin'>\
					<input class='b-medium-select' name='phone_number[]' id='phone-semin'>\
				</div>\
				<div  class='l-block b-btn-add-on'></div>\
				<div class='l-block b-btn-del-on'></div>\
				<div class='cl'></div>\
			</div>");
		$(this).removeClass('b-btn-add-on').addClass('b-btn-add-off');
		$(this).siblings('.b-btn-del-on').removeClass('b-btn-del-on').addClass('b-btn-del-off');
		$('.b-phone').append(phoneItem);
	});
	$('#seminar-form .b-btn-del-on').live('click',function(){
		$(this).parent().remove();
		$('.b-phone .b-phone-item:last-child').find('.b-btn-add-off').removeClass('b-btn-add-off').addClass('b-btn-add-on');
		if($('.b-phone .b-phone-item').length!=1){
		$('.b-phone .b-phone-item:last-child').find('.b-btn-del-off').removeClass('b-btn-del-off').addClass('b-btn-del-on');}
		
	});
	$("select#semin-place-field").change(function () {
		if ($(this).find("option:selected").index()) {
			$('#semin-place-field-add').show();
		} else {
			$('#semin-place-field-add').hide();
		}
	})
	if ($('.b-phone-table').length){
		$('.b-phone-table .country-code-link').click(function(){
			var countryInput=$(this).parents('.b-pt-country').find('input');
			if (countryInput.attr('value')!='+7')	countryInput.attr('value','+7')
			else countryInput.attr('value','');
			return false;
		})
	}
});

