var AE = window.AE || {};

AE.setDisabled = function() {
	$$('.search-options ul li.all input[value="All"]').each(function(elm) {
		Event.observe(elm,'click',function(evnt) {
			elm = evnt.target;
			if(elm.checked) {
				elm.up('span').addClassName('grey');

				$$('.'+elm.up('ul').id+' input[type=checkbox]').each(function(check_elm){
					if(check_elm.value != 'All') {
						check_elm.checked = false;
						check_elm.next('label').addClassName('grey')
					}
				});
			} else {
				elm.up('span').removeClassName('grey');

				$$('.'+elm.up('ul').id+' input[value!="All"]').each(function(elm) {
					elm.next('label').removeClassName('grey');
				});
			}
		});
		
		//in the event that the all option is selected by default, we need to check it on load.
		if($(elm).checked) {
			elm.up('span').addClassName('grey');

			$$('.'+elm.up('ul').id+' input[type=checkbox]').each(function(check_elm){
				if(check_elm.value != 'All') {
					check_elm.checked = false;
					check_elm.next('label').addClassName('grey')
				}
			});
		}
	});
	$$('.search-options ul li input[value!="All"]').each(function(elm) {
		Event.observe(elm,'click',function(evnt) {
			elm = evnt.target;
			//uncheck all if we're checking something that's not all...
			check_elm = $$('.'+$w(elm.up('ul').className)[0]+' input[type=checkbox]').first();
			check_elm.checked=false;
			check_elm.up('span').removeClassName('grey');
			
			//remove the colors to grey:
			$$('.'+$w(elm.up('ul').className)[0]+' input[value!="All"]').each(function(elm) {
				elm.next('label').removeClassName('grey');
			});
			
			
		});
	});
	
}

document.observe("dom:loaded",function() {
	AE.setDisabled();
});
