
$(document).ready(function() {
	recalculatePrice();
	$('[id^=ProductThumbImage]:first').attr('class', 'ProductThumbImage ProductThumbActive');
});


/**
 * Function recalculates product price based on selected Qty and options(if these exist)
 * Set's #PriceTag to the calculated price
 */
function recalculatePrice() {
	var unitPrice =	Number($('#unitPrice').val());
	var qty = Number($('#itemQty option:selected').text());
	var totalPrice = 0.0;

	var currentlySelectedOptionId = $("input[@name='selectedProductOption']:checked").val();
	var optionPrice = Number($("input[@name='optionPrices["+currentlySelectedOptionId+"]']").val());
	
	if (Number(optionPrice)) {
		unitPrice = optionPrice;
	}

	if(unitPrice > 0) {
		totalPrice = unitPrice * qty;	
	}

	var finalPrice = Number(totalPrice);
	$('#PriceTag').html('$ ' + finalPrice.toFixed(2));
}


function changeImage(num) {
	$('.ProductThumbImage').attr('class', 'ProductThumbImage');
	$('#ProductThumbImage' + num).attr('class', 'ProductThumbImage ProductThumbActive');

	$('#ProductBigImage').fadeOut(500, function(){
		$('#ProductBigImage').attr('src', eval("SmallImage" + num + ".src"))
	});
	$('#ProductBigImage').fadeIn(500);
}


