$(document).ready(function(){
	$('body').addClass('JS').removeClass('NOJS');
	$('.b-search').find('.b-search-fld').focusout();
	if($('body').hasClass('in_')){
		if($('#main_showcase li').length > 1){
			$('#main_showcase .b-showcase').css({'border':'0','height':'420px','width':'632px'});
			$('#main_showcase').bxSlider({
				mode: 'horizontal',
				infiniteLoop: true,
				controls: false,
				auto: true,
				speed: 1000,
				pause: 5000,
				autoHover: true
			});	
		}
	}
})

$(window).resize(function() {
//	stickyFooter();
});

$(window).load(function() { 
 	correctBlocksHeight();
//	stickyFooter();
});


function stickyFooter(){
	var bodyHeight = $('body').height();
	var contentHeight = $('.h-wrapper').height();
	var footerHeight = $('.h-footer').height();
	if(bodyHeight > contentHeight+footerHeight){
		$('.h-footer').css({'bottom':'0','position':'absolute'})
	}
}

$(function(){
	$('.b-showhide').click(function(){
		var targetObjectId = $(this).attr('show');
		var targetObjectClass = $(this).attr('show_class');
		if(targetObjectId){
			var targets = $('#'+targetObjectId);
		} else if(targetObjectClass){
			var targets = $('.'+targetObjectClass);
		};
		if(targets.length > 0){
			targets.each(function(){
				if($(this).hasClass('b-js_hidden')){
					$(this).removeClass('b-js_hidden').hide().slideDown('fast', function() {});
				} else {
					$(this).slideUp('fast', function() {
						$(this).addClass('b-js_hidden')
					});
				};
			})
		};
		return false;
	});
})

function testForm(s_id){
	var formFields = $(s_id + ' *[required]');
	var submitForm = $(s_id + ' input[type=submit]');
	var bShowSubmit = 1;
	formFields.each(function(){
		if(!$(this).val()){
			bShowSubmit = 0;
		};
	});
	if(bShowSubmit){
		submitForm.removeAttr('disabled');
	} else {
		submitForm.attr('disabled','disabled');
	};
};

$(function(){
	$('#b-print').click(function(){
		window.print()
		return false;
	});
})


function correctBlocksHeight(){
	$('#b-products_section ul').each(function(){
		var iBlockHeight = 0;
		var iBlockMaxHeight = 0;
		var iPosition = 1;
		var iLine = 1;
		var itemsList = $(this).find('li');
		$(itemsList).each(function(){
			iPosition = $(itemsList).index(this)+1;
			iLine = Math.ceil(iPosition/5);
			$(this).siblings().filter('*[line='+iLine+']').each(function(){
				iBlockHeight = $(this).innerHeight();
				if(iBlockHeight > iBlockMaxHeight){
					iBlockMaxHeight = iBlockHeight;
				};
			})
			iBlockMaxHeight = iBlockMaxHeight-40;
			$(this).siblings().filter('*[line='+iLine+']').find('.wrap').height(iBlockMaxHeight).filter('.wrap:last-child').height(iBlockMaxHeight-2);
		});
	});
}

$(function(){
    if($('table.b-product-price').length > 0){
        $('table.b-product-price').each(function(){
            $(this).find('tbody tr:even').addClass('color_0');
            $(this).find('tbody tr:odd').addClass('color_1');
        });
    };
})


