function copy_billing_to_shipping ()
{
	if ($ ('#bezorg_op_factuuradres').attr ('checked'))
	{
		$ ('#bezorgadres input').attr ('disabled', true);
		$ ('#bezorg_adres').val ($ ('#factuur_adres').val ());
		$ ('#bezorg_postcode').val ($ ('#factuur_postcode').val ());
		$ ('#bezorg_plaats').val ($ ('#factuur_plaats').val ());
	} else {
		$ ('#bezorgadres input').attr ('disabled', false);
	}
}

function update_cart (action, operand)
{
	$.get
	(
		'/ajax/cart',
		{
			'action' : action,
			'operand' : operand,
			'value' : $ ('#count-' + operand).val ()
		},
		function (data)
		{
			$ ('#status_main').html (data.status);
			$ ('#cart').html (data.cart);
			if (action == 'add')
			{
				$ ('html,body').animate ({ 'scrollTop' : $ ('#status_main').offset ().top - 1 }, 500);
				$ ('#cart').hide ();
				toggle_cart ();
			}
		}
	);
	return false;
}

function update_custom (action, operand)
{
	$.get
	(
		'/ajax/custom',
		{
			'action' : action,
			'operand' : operand,
			'value' : $ ('#count-' + operand).val ()
		},
		function (data)
		{
			$ ('#custom').html (data.custom);
		}
	);
	return false;
}

function order_custom ()
{
	$.get
	(
		'/ajax/custom',
		{
			'action' : 'order'
		},
		function (data)
		{
			$ ('#cart').html (data.cart);
			$ ('#custom').html (data.custom);
			$ ('#status_main').html (data.status);
			$ ('html,body').animate ({ 'scrollTop' : $ ('#status_main').offset ().top - 1 }, 500);
			$ ('#cart').hide ();
			toggle_cart ();
		}
	);
	return false;
}

function toggle_cart ()
{
	var status = $('#status_main');
	var pos = status.position ();
	$ ('#cart').toggle ().css ( { 'left' : (pos.left - 50) + 'px', 'top' : (pos.top + status.outerHeight (true) + 4) + 'px' });
}

function close_overlay ()
{
	$ ('#overlay-screen').remove ();
}
function create_overlay ()
{
	$ ('<div id="overlay-screen">'). prependTo (document.body).append ($ ('<div id="overlay">').css ('display', 'none')).click (close_overlay);
}
function magnify (url)
{
	create_overlay ();
	$ ('#overlay').append
	(
		$ ('<img>').attr ('src', url).load (function ()
		{
			var ovl = $ ('#overlay');
			ovl.css
			({
				'display' : 'block',
				'margin-top' : '-' + (ovl.outerHeight () / 2) + 'px',
				'margin-left' : '-' + (ovl.outerWidth () / 2) + 'px'
			});
		})
	)
}

