function $$(id) {
 	return document.getElementById(id);
}
function updatecount() {
 
	sales_count = $$('sales_count');
	newvalue = parseInt(sales_count.innerHTML.replace(/\D+/g,'')) + Math.floor(1 + Math.random()*8);
	sales_count.innerHTML = '$' + addCommas(newvalue);
}
function bridge_updated() {
 
	prod_count = $$('sales_count2');
	newvalue = parseInt(prod_count.innerHTML.replace(/\D+/g,'')) + Math.floor(1 + Math.random()*4);
	prod_count.innerHTML = addCommas(newvalue);
}

 
function addCommas(nStr) {
	try{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	}catch(e){
	alert(e); 	
	}
	return x1 + x2;
}

$("a[href^=#][href!=#]").live('click',function(e){
	$('html,body').animate({'scrollTop': $($(this).attr('href')).offset().top+'px'});
	e.preventDefault();
});
$(document).ready(function(){
	if ($('#savings_calc1').length){
		$('#savings_calc1').click(function(){
			user_items = $('input[name=items]').val().replace(/,/g,'');
			$('#save_items').html(addCommas(total_products-user_items));
			$('#save_labor').html(addCommas((total_products-user_items)*9/60*15));
			$('#save_time').html(addCommas(((total_products-user_items)*9/60/35).toFixed(2)));
			$('#calc1_result').show();
		});
		$('#calc1').submit(function(){
			$('#savings_calc1').click();
			return false;
		});
		$('#savings_calc2').click(function(){
			user_items = $('input[name=site_items]').val().replace(/,/g,'');
			user_pay = $('input[name=pay]').val().replace(/,|$/g,'');
			$('#spent_labor').html(addCommas((user_items*9/60*user_pay).toFixed(2)));
			$('#spent_time').html(addCommas((user_items*9/60/35).toFixed(2)));
			$('#spent_sell').html(addCommas((user_items*9/60*user_pay*2).toFixed(2)));
			$('#calc2_result').show();
		});
		$('#calc2').submit(function(){
			$('#savings_calc2').click();
			return false;
		});
	}
});
