function selectBrand(brand) {
	if (brand) window.location = '/catalog/br/' + brand + '/';
}
function toggle(id){
	if (document.getElementById(id).style.display=='none'){
		document.getElementById(id).style.display='block';
	} else {
		document.getElementById(id).style.display='none';
	}
	return false;
}
function AddItemToCart(id_item) {
	window.location="/catalog/cart/additem/"+id_item+"/";
}
function FilterClick(id_filter,id_value) {
//	console.log($('#filterval_'+id_value));
//	console.log($('#filterval_'+id_value+' input:first').attr('checked'));
	if (id_value==0) {
		$('#filter_'+id_filter+' input').attr('checked',false);
		$('#filter_'+id_filter+' a').removeClass('active');
		$('#filter_'+id_filter+' li.all a').addClass('active');
	} else {
		$('#filter_'+id_filter+' li.all a').removeClass('active');
		if ($('#filterval_'+id_value+' input:first').attr('checked')) {
			$('#filterval_'+id_value+' input:first').attr('checked',false);
			$('#filterval_'+id_value+' a:first').removeClass('active');
			if (!$('#filter_'+id_filter+' li.checkbox input:checked').get(0)) {
				$('#filter_'+id_filter+' li.all a').addClass('active');
			}
		} else {
			$('#filterval_'+id_value+' input:first').attr('checked',true);
			$('#filterval_'+id_value+' a:first').addClass('active');
		}
	}
//	console.log($('#filter_'+id_filter+' li.checkbox input:checked'));
	var url='/catalog/c/'+category_url+'/?ajax=1';
	$('ul.filters').each(function(){
		if ($(this).find('li.all a').hasClass('active')) return;
		var _this=this;
//		console.log(_this);
		$(this).find('li.checkbox input:checked').each(function(){
//			console.log(this);
			url+='&mf['+$(_this).attr('rel')+'][]='+$(this).attr('rel');
		});
	});
	$.getJSON(url,{},function(data){
		var i,j;
		for (i in data.filters) {
			for (j in data.filters[i].values) {
				$('#filterval_'+j+' label small').html('('+data.filters[i].values[j]+')');
				if (data.filters[i].values[j]==0){
					$('#filterval_'+j+' label').addClass('disabled');
					$('#filterval_'+j+' input').attr('disabled','disabled');
				} else {
					$('#filterval_'+j+' label').removeClass('disabled');
					$('#filterval_'+j+' input').removeAttr('disabled');
				}
//				console.log('#filterval_'+j+' label small');
//				console.log($('#filterval_'+j+' label small'));
			}
			//console.log(data.filters[i]);
		}
	});
	return false;
}
$(document).ready(function(){
//	console.log($('div.sortings a'));
	$('div.sortings a').click(function(){
//		console.log(this.href);
		var _this=this;
		$('#items_list').load(this.href+'s/'+this.rel+'/'+'?ajax_load=1',{ajax:1},function(){
			$('div.sortings a').removeClass('active');
			$(_this).addClass('active');
		});
		return false;
	});
});
