;(function($) {

	$.widget('dealp.dealpfilter', {
	
		options:{
			el_link:null
		},

		_init:function(){
			this.options._form = $('.deal-js-form', this.element);
			return this._bind();
		},
		
		_bind:function(){
			var self = this;
			$(this.options.el_link).unbind('click.deal').bind('click.deal',function(){ self.toggle(); return false; });
			$('.deal-js-link-toggle_categories', this.element).unbind('click.deal').bind('click.deal',function(){ self.toggle_checkboxes('.deal-js-categories'); return false; });
			$('.deal-js-link-toggle_types', this.element).unbind('click.deal').bind('click.deal',function(){ self.toggle_checkboxes('.deal-js-types'); return false; });
			$('.deal-js-link-submit', this.element).unbind('click.deal').bind('click.deal',function(){ self.submit(); return false; });
			$('input[type=checkbox]', this.options._form).attr('autocomplete','off');
		},
		
		toggle:function(){ $(this.element).toggle('blind'); },
		
		toggle_checkboxes:function(selector){
			//_log(selector + ' input[type=checkbox]');
			if ($(selector + ' input[type=checkbox]', this.options._form).first().is(':checked')) {
				$(selector + ' input[type=checkbox]', this.options._form).removeAttr('checked');
			}else{
				$(selector + ' input[type=checkbox]', this.options._form).attr('checked','checked');
			}
			return this;
		},

		submit:function(){
			$(this.options._form).trigger('submit');
			return this;
		}
		
		
	});

})(jQuery);
	

