Array.prototype.inArray = function(val) {
	var l = this.length;
	for(var i = 0; i < l; i++) {
		if(this[i] == val) {
			return true;
		}
	}
	return false;
}

jQuery(document).ready(function($){
	$("span[id^='toggle_tooltip_']").hover(
		function(e){
			var id = $(this).attr("id").replace("toggle_tooltip_","");
			$("div#tooltip_"+id).css({"top":((e.pageY-10)-$(window).scrollTop())+"px","left":(e.pageX+20)+"px"}).stop().show();
		},function(){
			var id = $(this).attr("id").replace("toggle_tooltip_","");
			$("div#tooltip_"+id).stop().hide();
	});

	// REAPPLY LINE HEIGHT FOR SINGLE / DOUBLE LINE
	// need class="calculator_[maximum width]_[line height to apply]"
	//$("span[class^='calculator ']").each(function(){
	//	var span_width = $(this).width();
	//	var max_width = parseInt($(this).attr('class').replace(/calculator (\d+)_(\d+)/,'$1'));
	//	var line_height = $(this).attr('class').replace(/calculator (\d+)_(\d+)/,'$2');
	//	if(span_width > max_width ){
	//		$(this).parent().css("line-height",line_height+"px");
	//		$(this).parent().html($(this).html());
	//	}
	//});
	
	$("span.calculator").each(function(){
		var parent = $(this).parent();
		var span_width = $(this).width();
		var max_width = parseInt($(this).parent().width());
		
		if(span_width > max_width ){
			var ratio = max_width/span_width;
			var line_ratio = 1;
			
			if(ratio >= 0.5) {
				line_ratio = 2;
			} else if(ratio >= 0.3333) {
				line_ratio = 3;
			} else if(ratio >= 0.25) {
				line_ratio = 4;
			}
			var line_height = Math.floor(parseInt($(this).parent().css('line-height').replace('px',''))/line_ratio);

			$(this).parent().css("line-height",line_height+"px");
			$(this).parent().css('overflow','hidden').html($(this).html());
		}
	});

});

