/*
Script Name: 			US-Travels
Description:			Case 1 2nd Semester 09MMD2b 2010
Author: 					Casper Knudsen
Creation Date: 		28-02-2010
		
Revision History
================
Date: 					
Description: 			
*/

$(document).ready(function(){

$("#formID").validationEngine();

// Login formular
$("#login_form").hide();
var x = 1; // Set x to the value of 1
$("#login").click(function(){
	x++; // Increases the value of x
	if(x==2){
		$("#login_form").show("slow"); // If x equals 2, show the #login_form
	}else{
		$("#login_form").hide("slow"); // Else, hide the #login_form
		x = 1; //  Set the value of x to 1 so a#login will trigger next time it's clicked
	}
});

// Category animation effects
$("#cat_overlay li").mouseover(function(){  
    $(this).stop().animate({height:'250px'},{queue:false, duration:400, easing:'easeInCubic'})  
});
$("#cat_overlay li").mouseout(function(){
    $(this).stop().animate({height:'32px'},{queue:false, duration:200, easing:'easeOutCubic'})
});

// Price calculation
$.Calculation.setDefaults({
	// a regular expression for detecting European-style formatted numbers
	reNumbers: /(-|-\$)?(\d+(\.\d{3})*(,\d{1,})?|,\d{1,})?/g
	// define a procedure to convert the string number into an actual usable number
	, cleanseNumber: function (v){
		// Remove extra data (like commas and dollar signs)
		return v.replace(/[^0-9,\-]/g, "").replace(/,/g, ",");
	}
});

$("input[name^=qty_item_]").bind("keyup", recalc);

recalc();

function recalc(){
	$("[id^=total_item]").calc(
		"qty * price",	// the equation to use for the calculation
		{
			qty: $("input[name^=qty_item_]"),	// define the variables used in the equation
			price: $("[id^=price_item_]")
		},
		function (s){	// define the formatting callback
			return s.toFixed(2) + " kr.";	// return the number as a kroner amount
		},
		function ($this){	// define the finish callback, this runs after the calculation has been complete
			var sum = $this.sum();// sum the total of the $("[id^=total_item]") selector
			
			$("#grandTotal").text(
				sum.toFixed(2) + " kr." // round the results to 2 digits
			);
		}
	);
}


});
