jQuery(document).ready(function(){

//	jQuery('.b-filter_form').hide();
	jQuery(".b-filter_toggle").click(function () {
		jQuery('.b-filter_form').slideToggle("slow", function(){
			if(jQuery('.b-filter_toggle span').hasClass('active')){
				jQuery('.b-filter_toggle span').removeClass('active')
			} 
			else {
				jQuery('.b-filter_toggle span').addClass('active')
			}			
		});
	});
	
	jQuery(".b-callorder").click(function () {
		jQuery('.b-call-form').slideToggle("slow", function(){
			if(jQuery('.b-callorder').hasClass('active')){
				jQuery('.b-callorder').removeClass('active')
			}
			else {
				jQuery('.b-callorder').addClass('active')
			}
		});
	});
	/*jQuery('.b-call-form input:text').focus(function(){
		jQuery(this).val('');
	});
	jQuery('.b-call-form textarea').click(function(){
		jQuery(this).val('');
	});*/
	
	/** setting input checked on startup */
	jQuery(".b-comparison li>a").each(function(){
		jQuery('input[name=' + jQuery(this).attr("href") + ']').attr('checked', 'checked');
	});
	/**/

	
	jQuery('.b-filter select').selectbox();
	jQuery('.b-comparison_table input:checkbox').click(function(){
	
		input_index = jQuery('.b-comparison_table input:checkbox').index(this);
		
		/** adding and removing to compare block */
		a = jQuery(this).parent().next();
		var _href = jQuery(a).attr('href');
		if(jQuery(this).is(":checked")) {
			jQuery('.b-comparison ul').append('<li></li>');
			jQuery('.b-comparison li:empty').addClass('comparison_li_' + input_index);
			jQuery('.b-comparison li:empty').append(jQuery(a).clone()).html();
		} 
		else {
			if( jQuery('.b-comparison li').hasClass('comparison_li_' + input_index ) ){
				jQuery('.b-comparison li.comparison_li_' + input_index ).remove()
			}
		}
		/**/
		
		/** ajax add_to_ && delete_from_ compare_list */ 
		if (this.checked) {
			jQuery.get(jQuery(this).val(), {}, function(){}, 'json');
		} else {
			jQuery.get(jQuery(this).val().replace(/ADD_TO/m, "DELETE_FROM"), {}, function(){}, 'json');
			// deleting from list
			var items = jQuery(".b-comparison li");
			for (var i = 0; i < items.length; i++) {
				if (jQuery(items[i]).html().indexOf('"' + _href + '"') > 0) {
					jQuery(items[i]).remove();
				}
			}
		}
		/**/
	});
	
	/** Нажатие на кнопку "Очистить" */
	jQuery('#clean-button').click(function(){
		// ajax-удаление из сравнения
		var items = jQuery(".b-comparison li>a").each(function(){
			var remove_link = jQuery(this).attr('href').replace(/\/(\d+)\/(\d+)\//mg, "/$1/index.php?action=DELETE_FROM_COMPARE_LIST&id=$2");
			jQuery.get(remove_link, {}, function(){}, 'json');
		});

		jQuery('.b-comparison li').remove();
		// Снимаем галочки с чекбоксов
		if(jQuery('.b-comparison_table input:checkbox').is(':checked')) {
			jQuery('.b-comparison_table input:checkbox').removeAttr('checked')
		}	
		return false
	})
	/**/
	
	/** Нажатие на кнопку закрытия - удаление из сравнения */
	/*jQuery('.close').click(function(){
		var remove_link = jQuery(this).parent().find('a').eq(0).attr('href').replace(/\/(\d+)\/(\d+)\//mg, "/$1/index.php?action=DELETE_FROM_COMPARE_LIST&id=$2");
	
		// ajax-удаление из сравнения
		jQuery.get(remove_link, {}, function(){}, 'json');
	
		td = jQuery(this).parents('table.b-compare-img_table').find('tr:first-child td');
		td1 = jQuery(this).parents('div.b-compare-img_div').siblings('.b-prod-info').find('td');
		width = Math.round(100 / ( jQuery(td).length - 1));
		width1 = Math.round(78 / ( jQuery(td).length - 1));
		
		my_class = jQuery(this).attr('class');
		my_class = my_class.split(' ');
		jQuery('td.' + my_class).remove();
		
		jQuery(td).css('width', width + '%');
		jQuery(td1).css('width', width1 + '%')
	});*/
	/**/
	
	jQuery('dl.b-prod-descr dt').click(function(){
        jQuery(this).siblings().removeClass('active').end().next('dd').andSelf().addClass('active');
		return false
    });
});

window.onload = function(){
	jQuery('.b-call-form').slideUp()
}