if(detectBrowser.modernBrowser()){
	



var SetFilterFactory = Class.create();
SetFilterFactory.prototype = {
	initialize:function(){
		this.filters = $$('.setfilter').map(function(el){
			return new SetFilter(el);
		});
	}
};


/*
format for a filter checkbox:
<input type="checkbox" class="setfilter_check 40" />
*/
var SetFilter = Class.create();
SetFilter.prototype = {
	initialize:function(filterContainer,updateFilterClosure,listenEventAtContainer){
		if(filterContainer){
			var parseWeight = function(elem){ // parse classnames to find the weight of a given checkbox
				return $A(elem.classNames()).find(function(token){
					return parseInt(token) > -1;
				});
			};
			var getTotalWeight = function(){ // return the total weight of the checked checkboxes
				var checkedTotal = this.filterCheckboxes.inject(0,function(acc,filterCheck){
					return acc + parseInt(filterCheck.checked?parseWeight(filterCheck):0);
				});
				return (checkedTotal==0)?this.totalTotal:checkedTotal;
			}.bind(this);
			this.filterCheckboxes = filterContainer.getElementsBySelector("input.setfilter_check").map(function(fc){
				if(listenEventAtContainer){
					Event.observe(fc.parentNode,'click',function(ev){
						if(ev.target!=fc){
							fc.checked = !fc.checked;
						}
						updateFilterClosure(getTotalWeight()); // when a checkbox is checked, we recalculate the filter
					}.bind(this));								
				} else {
					Event.observe(fc,'click',function(ev){
						updateFilterClosure(getTotalWeight()); // when a checkbox is checked, we recalculate the filter
					}.bind(this));				
				}
				return fc;
			}.bind(this));
			this.totalTotal = this.filterCheckboxes.inject(0,function(acc,filterCheck){
				return acc + parseInt(parseWeight(filterCheck));
			});
			updateFilterClosure(getTotalWeight());
		}
	}
};




}