$(window).load(function(){

	var money = $('#ccCash').val();
	var target = $('#ccGoal').val();
	var ratio = ((money/target)*1000)/1000; // like 0.429
	var perc = ratio*100;
	var $bar = $('#capital_goal');
	var $now = $('#capital_raised');
	var $line = $('#cc_line');
	var $gvalue = $('#goal_value');
	var $cvalue = $('#current_value');
	var $capital = $('#cc_bar');
	var $show = $('span.perc', $bar);
	var target_money = r1(target/1000000);
	var raised_money = money/1000000;
	var hOne = $bar.outerHeight();
	var hTwo = Math.round(hOne*ratio);
	var time = 6000;
	var intval = 1;

	counting = setInterval(countup, intval);
		
	function countup(){
		var current_height = hOne-$now.height();
		var current_perc = r1((current_height/hOne)*100);
		var current_money = r1((current_height/hOne)*(target_money));
		show = current_perc+'%';
		showmoney = '$'+current_money+' MM';
		if (current_perc >= perc) {
			clearInterval(counting);
			show = r1(perc)+'%';
			showmoney = '$'+r1(raised_money)+' MM';
			$show.text(show);
			$cvalue.html(showmoney);
			return;
		}
		$show.text(show);
		$cvalue.html(showmoney);
	}

	$line.css({height:hOne+'px'}).animate({height:(hOne-hTwo)+'px'},time);
	$gvalue.css({height:hOne+'px'}).html('$'+target_money+' MM').animate({height:(hOne-hTwo)+'px'},time);
	$now.animate({height:(hOne-hTwo)+'px'},time);

	// Round to 1 decimal place
	function r1(n) {
		ans = n * 100
		ans = Math.round(ans /10) + ""
		while (ans.length < 2) {ans = "0" + ans}
		len = ans.length
		ans = ans.substring(0,len-1) + "." + ans.substring(len-1,len)
		return ans
	} 

});
