
$(document).ready(function(){

 	//--------------- Topbar --------------------//
  
	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$("h2.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
	});
});


function calcTotalNew(wasKeyPress) {
	var subPrice = 0;
	var subTotalPrice = 0;
	var totalPrice = 0;
	var totalShipping = parseFloat(shippingTotal);
	var i = 0;
	var countArticle = 0;
	// Walk through each of the possible defined items, to look for checked/selected ones
	for (i=0; i < quantityArray.length; i++) {
		if (document.getElementById('qty-'+quantityArray[i]) && document.getElementById('qty-'+quantityArray[i]).value > 0) {
			subPrice = priceArray[i] * document.getElementById('qty-'+quantityArray[i]).value;
			subTotalPrice+= parseFloat(subPrice);
			countArticle+=document.getElementById('qty-'+quantityArray[i]).value;
		}
	}
	// Add shipping cost to the total
	if(countArticle==0){
		totalShipping = 0;
	}else if(countArticle > 1){
		totalShipping = 0;
	}
	totalPrice = subTotalPrice +  totalShipping;

	// Now update the whole page total
	if (isNaN(totalPrice)) {
		alert("You can only use numbers in the quantity fields.");
	}else{
		document.getElementById('order-total').innerHTML = totalPrice;
		document.getElementById('order-subtotal').innerHTML = subTotalPrice;
		document.getElementById('shipping-fee').innerHTML = countArticle==1 ? shippingTotal : '0.00';
	}
}
