if (this.Prototype) {
	Event.observe(window, 'load', function() {
		// get form
		var form = $('contact');

		if (form) {
			form.select('.powermail-fieldset-branch').each(function(el) {
				var children = el.childElements();
				switch(true) {
					case (children.length >= 3):
						children[2].addClassName('powermail-fieldwrap-subbranch');

						// add listeners
						var cbs = children[1].select('input[type="checkbox"]');
						for (var i=0; i < cbs.length; i++) {
							cbs[i].observe('click', function(e){
								if (this.getValue()) {
									this.up(1).next().appear();
								} else {
									this.up(1).next().fade();
								}
							});
						}
						// hide submenu
						if(typeof children[1].select('.checkbox')[0] != "undefined" && children[1].select('.checkbox')[0].checked == true){
							children[2].show();
						}
						else{
							children[2].hide();
						}
					case (children.length >= 2):
						children[1].addClassName('powermail-fieldwrap-branch');
					break;
				}
			});
		}
	});
}
