/* Actions for product-buttons in webshop_standard.php */
$(document).ready( function () {

	$('input.button_buy').focus( function () { $(this).blur(); });

	$('input.button_buy').click( function () {
			
		var prodId = $(this).attr('name');
		var prodQt = $('input[@type=text]#'+ prodId).attr('value');
		var prodSection = $('#productForm select').serialize();

		$('#cart').html('<div style="padding: 0px 0px 0px 30px; color: #333;">Uppdaterar...</div>');
		
		$('div.confirm-overlay').show();
		$('div.confirm-alert').show();

		$.post('xmlhttp/cartaction.php', { action: 'add', prodId: prodId, prodQty: prodQt, prodSection: prodSection }, function (data) {
			
			if (data != '' && ! isNaN(data)) {
				$.get('ajax.php', { sel: data, page: 'cart', ajax: '1' }, function (html) {
					$('#cart').html(html);
				});
			} else if (! data) {
				$('#cart').load('xmlhttp/cart.php?ajax=1');
			}
		});

		return false;
	});

	$('.prodSection').change( function () {

		propID = $(this).val();
		price = $('#prod_price').val();
		productID = $('#prodId').val();

		if(propID != 0){
			imageID = $('#prod_'+propID).attr('class');
		}else{
			imageID = 0;
		}

		if(imageID != 0){
			img = $('#thumbnailImage'+imageID).attr('src');

			$('#productImageLargeTD').html('<img src="'+img+'">');
		}

		$.get('xmlhttp/checkPrice.php',{ propID: propID, price: price, productID: productID, imageID: imageID }, function (data) {
			$('.price-body').html(data+':-');
		});

	});
});
