var JQ = {
	koopnu: function(productid, productaantal){
		url = $('#'+productid).attr('href');
		$.getJSON('/ajax.php', {id: productid, method: 'koopnu'}, function(aantal) {
			if(aantal) {
				$('#cartsummary').find('span.bold').html(aantal);
				$('#dialogproductdetailpagelink').attr('href', url);
				JQ.showdialog();
			} else {
				window.location= url;
			}
		});
	},
	showdialog: function() {
		$('#dialog').show();
		$('#dialog').dialog({
            resizable: false,
            height: 200,
            width: 450,
            bgiframe: true, // to fix the IE6 bug that shows select trough overlays
            modal: true,
            overlay: { backgroundColor: '#000', opacity: 0.4 },
            open: function() {
                // TEMP FIX: remove jQuery dialog borders
                $('.ui-resizable-handle').remove();
            }
        })
	},
	init: function(){
		$(document).ready(function(){
			$('.buynow').click(function(){
				JQ.koopnu(this.id, 1);
				return false;
			});
		});
	}
};
JQ.init();