// Edward Kmett (c) 2006 The Linguist List

Math.LOG_HALF = -0.6931471805599453;

Math.bias = function (a, b) {
    if (b == 0.5) return a;
    if (a<0.001) return 0;
    if (a>0.999) return 1;
    if (b<0.001) return 0;
    if (b>0.999) return 1;
    return Math.pow(a, Math.log(b)/Math.LOG_HALF); 
};

Math.gain = function (a, b) {
    if (b == 0.5) return a;
    if (a<0.001) return 0;
    if (a>0.999) return 1;
    b = Math.max(0.001, Math.min(.999, b));
    var p = Math.log(1-b)/ Math.LOG_HALF;
    return a < 0.5 ? (Math.pow(2 * a, p) / 2) : 1 - (Math.pow(2 * (1 - a), p) / 2);
};	

function position(time,goal) { 
	// scale the position so it eases in and out of the animation.
	return Math.gain(time/100,0.9)*goal;
}

// the following uses jquery
$(document).ready(function() { 
	var tick = 0;
	var interval = setInterval(function() { 
		tick+=pigmeter_multiplier;
		$(".pigmeter").css("height",(480-pigmeter_shorten)+"px");
		if (tick<100) { 
			var offset = -pigmeter_shorten-position(tick,Math.min(pigmeter_percentage,100));
			$(".pigmeter-sky").css("top",offset+"px");
			var amount = position(tick,pigmeter_percentage/100.0*pigmeter_goal);
			$(".pigmeter-text").html("$" + amount.toFixed(2));
			$(".pigmeter-text").css("top",(offset+300)+"px");
		} else { 
			$(".pigmeter-text").html("$" + pigmeter_current.toFixed(2));
			clearInterval(interval);
		}
			
	},15*pigmeter_multiplier);
});
