function preloadImages( imageRoot ){
 if (document.images) {  

    preloadPics(imageRoot,
        'logo-jetstyle', 'logo-jetstyle-'
         );

    preloadPics(imageRoot+'meta/',
        'home', 'home-',
        'mail', 'mail-',
        'map', 'map-'
         );

  }

  preloadFlag = true;
}

var needResize = false;
$(function(){
	$(window).bind('resize', function(){
		if ($('.b-main').find('#googleMap').size() > 0 || needResize) {
			var counted_height = $(window).height() - $('.b-main').offset().top - 56; // 56 - столько пикселей даём футеру
			$('.b-main').height((counted_height > 600?counted_height:600)+"px");
			needResize = true;
		}
	}).resize();
	
	
	$('.b-settings-form ul li input.checkbox').each(function(){
		$(this).click(function(){
			if ($(this).attr('checked')) {
				var radio = $(this).siblings('input.radio'); 
				radio.show();
				
				if ($('.b-settings-form ul li input.radio:checked:visible').size() == 0) {
					radio.attr('checked', 'checked');
				}
			}
			else {
				var radio = $(this).siblings('input.radio'); 
				radio.hide();
				
				if (radio.attr('checked')) {
					$($('.b-settings-form ul li input.radio:visible').get(0)).attr('checked', 'checked');
				}
			}
		});
		
		if ($(this).attr('checked')) {
			$(this).siblings('input.radio').show();
		}
		else {
			$(this).siblings('input.radio').hide();
		}
	})
	
	var el = ($('.l-content__r-w').size() > 0 ? 
			$('.l-content__r-w') : 
			($('.l-columns_r-w').size() > 0 ? $('.l-columns_r-w') : $('.b-main .right-'))
		);
	el.css('overflow', 'hidden')
	el.find('>*').each(function(){
		$(this).attr('wHeight', $(this).height());
	});
	var eHeight = el.height();
		
	setInterval(function(){
		el.find('>*').each(function(){
			if ($(this).height() != $(this).attr('wHeight')) {
				$(window).resize();
				$(this).attr('wHeight', $(this).height());
			}
		});
	}, 1000);
	
	$(window).bind('resize', function(){
		el.css('height', 'auto');
		var counted_height2 = el.height();
		//console.log(counted_height2);
		el.height(($(window).height()-140) > el.height() ? ($(window).height() - 140 - parseInt(el.css('padding-top')) - parseInt(el.css('padding-bottom'))) + "px" : "auto");
		
		// Фикс для баннера в IE6, пока не придумал ничего оригинальнее
		if ($.browser.msie && $.browser.version < 7) {
			$('.cols2 .left- .pad .banner').css('border', '1px solid green');
			$('.cols2 .left- .pad .banner').css('border', 'none');
		}
	}).resize();
	
	
	// Замена инпут-радио на кнопки
	$('.js-pseudo-radio').each(function(){
		// Скрываем контейнер, но не display: none, чтобы данные передались
		$(this).css({'position': 'absolute', 'visibility': 'hidden'});
		
		var pRadioContainer = $('<div></div>').addClass('b-pseudo-radio-type__w');
		$(this).after(pRadioContainer);
		
		var radios = $(this).find('input:radio');
		var i = 0;
		var size = radios.size();
		
		radios.each(function(){
			var el = $('<span></span>').addClass('b-pseudo-radio-type');
			var this_radio = $(this);
			
			if ($(this).attr('checked'))
			{
				el.addClass('b-pseudo-radio-type-active');
			}
			el.html('<ins class="c c-tl g-png24"></ins><ins class="c c-tr g-png24"></ins>'+(this_radio.next().text())+'<ins class="c c-bl g-png24"></ins><ins class="c c-br g-png24"></ins>')
			el.click(function(){
				$(this).siblings().removeClass('b-pseudo-radio-type-active').end().addClass('b-pseudo-radio-type-active');
				this_radio.attr('checked', 'checked').click();
			})
			
			if (i == size - 1) {
				el.addClass('b-pseudo-radio-type-last');
			};
			
			el.appendTo(pRadioContainer);
			i++;
		});
	})
})
