$(function() {
	
	$('div#channelmenu div.channels a:last').addClass('last');
	$('div#breadcrumb a:last').addClass('last');

	$('.clickable').click(function() {
		$(this).find('a[href]').eq(0).each(function() {
			document.location.href = $(this).get(0).href;
		});
		return false;
	});

	// Default styling for inputs
	$('input[type=checkbox]').addClass('checkbox');
	$('input[type=radio]').addClass('radio');
	$('input[type=button]').addClass('button');
	$('input[type=submit]').addClass('button');

	// Table column widths
	$('table[class*=w40-60] > tbody > tr').each(function() { $(':eq(0)', this).css('width', '40%') });
	$('table[class*=w40-60] > tbody > tr').each(function() { $(':eq(1)', this).css('width', '60%') });
});


/**
 * haalt de prijs op van een product, aan de hand van de gespecificeerde lengte, breedte en aantal
 * @param 	integer	product_id
 * @return	void
 */
function calculatePrice(product_id) {
	// haal de lengte, breedte en aantal op
	var length = $('#length_' + product_id).val();
	var width = $('#width_' + product_id).val();
	var quantity = $('#quantity_' + product_id).val();

	var sUrlExtra = '';
	if (parseInt(quantity) > 0) {
		sUrlExtra+= '/quantity/' + quantity;
	}
	if (parseInt(length) > 0) {
		sUrlExtra+= '/length/' + length;
	}
	if (parseInt(width) > 0) {
		sUrlExtra+= '/width/' + width;
	}
	
	$.ajax({
		url: baseUrl + 'shop/calcproductprice/product_id/' + product_id + sUrlExtra,
		type: 'GET',
		success: function(data, status, requestObj){
			if(requestObj.responseText != '') {
				// prijs kan samengesteld zijn
				var prijs = requestObj.responseText
				var aTemp = prijs.split('|');
				
				document.getElementById('listprice_total').innerHTML = '&euro; ' + aTemp[0];
				if (aTemp.length > 1) {
					// er is ook een 'price per unit'
					document.getElementById('listprice_unit').innerHTML = '&euro; ' + aTemp[1];
				}
			}
		}
	});
}
