var bIsFirebugReady = (!!window.console && !!window.console.log);

	$(document).ready(
		function (){
			// update the plug-in version
			$("#idPluginVersion").text($.Calculation.version);

/*			
			$.Calculation.setDefaults({
				onParseError: function(){
					this.css("backgroundColor", "#cc0000")
				}
				, onParseClear: function (){
					this.css("backgroundColor", "");
				}
			});
*/			
			// bind the recalc function to the quantity fields
			$("input[name^=qty_item_]").bind("keyup", recalc);
			$("input[name^=ldRaw]").bind("keyup", recalc);
			$("input[name^=hdRaw]").bind("keyup", recalc);
			$("input[name^=standardDrinkers]").bind("keyup", recalc);
			$("[id^=heavyDrinkers]").bind("keyup", recalc);
			$("[id^=lightDrinkers]").bind("keyup", recalc);
			$("[id^=EventDuration]").bind("keyup", recalc);
			$("[id^=hours]").bind("keyup", recalc);
			$("[id^=hoursValue]").bind("keyup", recalc);
			$("[id^=peopleHours]").bind("keyup", recalc);
			$("[id^=guestsNumber]").bind("keyup", recalc);
			$("[id^=beerCount]").bind("keyup", recalc);
			$("[id^=wineCount]").bind("keyup", recalc);
			$("[id^=hardCount]").bind("keyup", recalc);
			$("[id^=cases]").bind("keyup", recalc);
			$("[id^=beer01]").bind("keyup", recalc);
			$("[id^=options]").bind("keyup", recalc);
			$("[id^=beer]").bind("change", recalc);
			$("[id^=wine]").bind("change", recalc);
			$("[id^=hardstuff]").bind("change", recalc);
			$("[id^=beer]").bind("click", recalc);
			$("[id^=wine]").bind("click", recalc);
			$("[id^=hardstuff]").bind("click", recalc);
		
			// run the calculation function now
			recalc();

			// automatically update the "#totalSum" field every time
			// the values are changes via the keyup event
			$("input[name^=sum]").sum("keyup", "#totalSum");
			
			// automatically update the "#totalAvg" field every time
			// the values are changes via the keyup event
			$("input[name^=avg]").avg({
				bind:"keyup"
				, selector: "#totalAvg"
				// if an invalid character is found, change the background color
				, onParseError: function(){
					this.css("backgroundColor", "#cc0000")
				}
				// if the error has been cleared, reset the bgcolor
				, onParseClear: function (){
					this.css("backgroundColor", "");
				}
			});

			// automatically update the "#minNumber" field every time
			// the values are changes via the keyup event
			$("input[name^=min]").min("keyup", "#numberMin");

			// automatically update the "#minNumber" field every time
			// the values are changes via the keyup event
			$("input[name^=max]").max("keyup", {
				selector: "#numberMax"
				, oncalc: function (value, options){
					// you can use this to format the value
					$(options.selector).val(value);
				}
			});

			// this calculates the sum for some text nodes
			$("#idTotalTextSum").click(
				function (){
					// get the sum of the elements
					var sum = $(".textSum").sum();

					// update the total
					$("#totalTextSum").text("$" + sum.toString());
				}
			);
			
			// this calculates the sum for some text nodes
			$("#CalculateButton").click(
				function (){
					// get the sum of the elements
					var sum = $("#beerCount").sum();

					// update the total
					$("#bCountFinal").text("" + sum.toString());
				}
			);
			
			// this calculates the sum for some text nodes
			$("#CalculateButton").click(
				function (){
					// get the sum of the elements
					var sum = $("#wineCount").sum();

					// update the total
					$("#wCountFinal").text("" + sum.toString());
				}
			);
			
			// this calculates the sum for some text nodes
			$("#CalculateButton").click(
				function (){
					// get the sum of the elements
					var sum = $("#hardCount").sum();

					// update the total
					$("#hCountFinal").text("" + sum.toString());
				}
			);

			// this calculates the average for some text nodes
			$("#idTotalTextAvg").click(
				function (){
					// get the average of the elements
					var avg = $(".textAvg").avg();

					// update the total
					$("#totalTextAvg").text(avg.toString());
				}
			);

		}
	);
	
	function recalc(){
		
		$("[id^=lightDrinkers]").calc(
			// the equation to use for the calculation
			"ld * thq",
			// define the variables used in the equation, these can be a jQuery object
			{
				ld: $("input[name^=ldRaw]"),
				thq: $("[id^=threeQuarters]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=heavyDrinkers]").calc(
			// the equation to use for the calculation
			"hd * doble",
			// define the variables used in the equation, these can be a jQuery object
			{
				hd: $("input[name^=hdRaw]"),
				doble: $("[id^=double]")
				// thq: $("[id^=threeQuarters]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=standardDrinkers]").calc(
			// the equation to use for the calculation
			"sd + cero",
			// define the variables used in the equation, these can be a jQuery object
			{
				sd: $("input[name^=standardDrinkers]"),
				cero: $()
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=guestsNumber]").calc(
			// the equation to use for the calculation
			"lightdrinkers + standarddrinkers + heavydrinkers",
			// define the variables used in the equation, these can be a jQuery object
			{
				lightdrinkers: $("[id^=lightDrinkers]"),
				standarddrinkers: $("[id^=standardDrinkers]"),
				heavydrinkers: $("[id^=heavyDrinkers]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=hours]").calc(
			// the equation to use for the calculation
			"EventDuration + cero",
			// define the variables used in the equation, these can be a jQuery object
			{
				EventDuration: $("[id^=EventDuration]"),
				cero: $("[id^=cero]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=hoursValue]").calc(
			// the equation to use for the calculation
			"hours * half + half",
			// define the variables used in the equation, these can be a jQuery object
			{
				hours: $("[id^=hours]"),
				half: $("[id^=half]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=peopleHours]").calc(
			// the equation to use for the calculation
			"hoursVal * people",
			// define the variables used in the equation, these can be a jQuery object
			{
				hoursVal: $("[id^=hoursValue]"),
				people: $("[id^=guestsNumber]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=beerCount]").calc(
			// the equation to use for the calculation
			"((value / cases) / options) * beer",
			// define the variables used in the equation, these can be a jQuery object
			{
				beer: $("[id^=beer]"),
				value: $("[id^=peopleHours]"),
				cases: $("[id^=cases]"),
				options: $("[id^=options]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#beerCount").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
					
		$("[id^=wineCount]").calc(
			// the equation to use for the calculation
			"((value / glasses) / options) * wine",
			// define the variables used in the equation, these can be a jQuery object
			{
				wine: $("[id^=wine]"),
				value: $("[id^=peopleHours]"),
				glasses: $("[id^=glasses]"),
				options: $("[id^=options]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#wineCount").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
			
		$("[id^=hardCount]").calc(
			// the equation to use for the calculation
			"((value / hardDrinks) / options) * hardstuff",
			// define the variables used in the equation, these can be a jQuery object
			{
				hardstuff: $("[id^=hardstuff]"),
				value: $("[id^=peopleHours]"),
				hardDrinks: $("[id^=hardDrinks]"),
				options: $("[id^=options]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#hardCount").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
		$("[id^=options]").calc(
			// the equation to use for the calculation
			"wine + beer + hardstuff",
			// define the variables used in the equation, these can be a jQuery object
			{
				beer: $("[id^=beer]"),
				wine: $("[id^=wine]"),
				hardstuff: $("[id^=hardstuff]"),
				half: $("[id^=half]")
			},
						
			// define the formatting callback, the results of the calculation are passed to this function
			function (s){
				// return the number as a dollar amount
				return "" + s.toFixed();
			},
			// define the finish callback, this runs after the calculation has been complete
			function ($this){
				// sum the total of the $("[id^=total_item]") selector
				var sum = $this.sum();
				
				$("#grandTotal").text(
					// round the results to 2 digits
					"" + sum.toFixed()
				);
			}
		);
		
	}
	
	// run the calculation function now
			recalc();
