$(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();
	});
});
