function countper(elem) {
	var total = 0;
	
	$j('#' + elem + ' .per input:text').each(function() {
		var $this = $j(this);
		if ($this.val() == '') $this.val(0);
		total = total + parseInt($this.val());
	});
			
	$per = $j('#' + elem + ' p.pertotalnum');
	$per.html(total + '%');
	if (total >= 100) { $per.addClass('active'); } else { $per.removeClass('active'); }
};

$j(document).ready(function() {
	
	$j('#step1 .per input:text').blur(function() { countper('step1') });
	$j('#step2 .per input:text').blur(function() { countper('step2') });
	
	$j('.radio input:radio').click(function() {
		var $per = $j(this).parents('div.bool').siblings('div.per');
	
		if ($j(this).val() == 'no' || $j(this).val() == 0) {
			$per.find('input:text').val(0);
			countper($j(this).parents('ul.tab').attr('id'));
			$per.hide('slide', { direction: 'left' });	
		} else {
			$per.show('slide', { direction: 'left' });	
		}
	});
	
	$j('.droptrigger input:radio').click(function() {
		var $drop = $j(this).parents('div.bool').siblings('div.drop');
		
		if ($j(this).val() == 'yes') {
			$drop.slideDown();
		} else {
			$drop.slideUp();	
		}
	});
	
	$j('#carpool').change(function() {
		var $per = $j(this).parents('div.subrow').next('div.subrow');
	
		if ($j(this).val() == 0) {
			$per.slideUp();
		} else {
			$per.slideDown();	
		}
	});
	
	
	$j('#stepTabs a.trigger').click(function() {
		$j('.tab').filter(this.hash).show().siblings('.tab').hide();
		$j(this).addClass('active').siblings('a').removeClass('active');
		return false;
	}).filter(':first').click();
	
	$j('a.stepnav').click(function() {
		$j('.tab').filter(':visible').next().show().siblings('.tab').hide();
		$j('#stepTabs a.active').next().addClass('active').siblings('a').removeClass('active');
		return false;
	});
	
	$j('a.submit').click(function() {
		$j('form#carbon_form').submit();
	});
	
	$j('select#shelter_q2').change(function() {
		val = $j(this).val();
		
		if (val >= 0.85) {
			$j('li#warmair-q3').show();	
		} else {
			$j('li#warmair-q3').hide();	
		}
	});
	

	$j('.tabCalc li').not('.nobg').hover(function() { $j(this).addClass('hov'); },
	function() { $j(this).removeClass('hov'); });
	
	$j('.tabCalc li *').focus(function() { $j(this).parents('li').not('.nobg').addClass('focus'); })
	.blur(function() { $j(this).parents('li').not('.nobg').removeClass('focus'); });

	
})
