var conditionals = function () {
	var hide_nos = function(event,looker,check,show,hide){
		if(event && !$(event.target).is('input:not([name^=v:]), select', 'div.conditional > *nth-child(2)'))
			return;

		var search = $(looker).attr('conditional');
		var not = 0;
		if($(looker).attr('notconditional')){
			not=1;
			search=$(looker).attr('notconditional');
			}
		else if(search==undefined){
			search='Yes';
			}
		var string='[value';
		if(not){
			string += '!';
			}
		string += '="' + search + '"]';
		var string2 = string + ':checked';
		if($('input:radio' + string2 + ', input:checkbox' + string2 + ', select' + string,check).is(':checked, select')){
			$(show).show();
			}
		else{
			$(hide).contents('*:not(input:hidden)').val('').end().hide();
			}
		};
	var condition = function(event,that){
			hide_nos(
				event,
				that,
				that,
				$(that).children().filter(':hidden'),
				$(that).children().filter('*:not(:nth-child(2))')
				);
			}
	var list = $.grep($('div.conditional:has(*:nth-child(2) input), div.conditional:has(*:nth-child(2) select)'),function(that, n){
		if($(that).find('*:nth-child(2) input:not([name^=v:]), select').size())
			return true;
		return false;
		});
	$(list).each(function(){
		$(this).bind('change click',function(event){
			condition(event,this);
			}).addClass('setcondition').removeClass('conditional');
		condition(0,this);
		});
	var other = function(event,self,look){
			hide_nos(
				event,
				self,
				look.parent(),
				self.children().filter(':hidden'),
				self.children()
				);
			};
	$('div.otherConditional[selector]').each(function(){
		var self=$(this);
		var look=$($(this).attr('selector'));
		var search=$(this).attr('conditional');
		if(search==undefined) search='Yes';
		var string='[value="' + search + '"]:checked';
		if(look.size()){
			look.bind('change click', function(event){
				other(event,self,look);
				});
			other(0,self,look);
			}
		self.removeClass('otherConditional').addClass('setothercondition');
		});
	};
$(document).ready(conditionals);
