function initializeSlimbox()
{
	$(document).ready(function()
	{
		$('a.slimbox').slimbox({counterText: "Afbeelding {x} van {y}"});
	});
}

function initalizeCalculator()
{
	$(document).ready(function()
	{
		$('input#option_quantity').keyup(function()
		{
			calculatePrice();
		});

		$('input#user_careyn_id').keyup(function()
		{
			if (this.value != '')
				$('tr.discountRow').show();
			else
				$('tr.discountRow').hide();

			calculatePrice();
		});

		$('input#user_careyn_id').keyup();
	});
}

function calculatePrice()
{
	c_quantity = $('input#option_quantity').val();

	if (isNaN(c_quantity))
	{
		alert('Geen geldig aantal, de prijs kan niet berekend worden.');
		return false;
	}

	// Quantity and price
	$('span#c_quantity').html(c_quantity);
	var price = (c_quantity < 100) ? c_price : c_price_100;
	$('span#price').html('&euro; '+(price).toFixed(2));
	price *= c_quantity;
	$('span#c_price').html('&euro; '+(price).toFixed(2));

	// Printing
	price += c_price_printing;

	// Discount
	var discount = ($.trim($('input#user_careyn_id').val()) == '') ? 0 : c_price_discount;
	$('span#discount').html((discount));
	discount = c_price_printing * (discount / 100);
	price -= discount;
	$('span#c_price_discount').html('- &euro; '+(discount).toFixed(2));

	// Shipping costs
	price += c_price_shipping_costs;

	// Total price
	$('span#c_price_total').html('&euro; '+(price).toFixed(2));
}

function initializePmsSelector()
{
	$(document).ready(function()
	{
		$('input[name=Order\\[option_color_inside\\]\\[\\]][type=text]').click(function()
		{
			$('input#option_color_inside_custom').attr('checked', true);
		});

		$('input[name=Order\\[option_color_outside\\]\\[\\]][type=text]').click(function()
		{
			$('input#option_color_outside_custom').attr('checked', true);
		});

		$('input.pmsCheckBox1').change(function()
		{
			var length = $('input.pmsCheckBox1:checked').length + $('input#option_color_inside_custom:checked').length;
			if (length > 4)
			{
				this.checked = false;
				alert('U kunt maximaal 4 kleuren selecteren voor de binnenzijde');
			}
		});

		$('input.pmsCheckBox2').change(function()
		{
			var length = $('input.pmsCheckBox2:checked').length + $('input#option_color_outside_custom:checked').length;
			if (length > 4)
			{
				this.checked = false;
				alert('U kunt maximaal 4 kleuren selecteren voor de buitenzije');
			}
		});
	});
}

function initializeGrid()
{
	$(document).ready(function()
	{
		var gridForm = $('#gridForm');

		gridForm.find('a.linkButton').live('click', function()
		{
			$(this).parents('form').submit();
			return false;
		});

		gridForm.live('submit', function()
		{
			if (gridForm.find('.rowCheckbox:checked').length == 0)
			{
				alert('U heeft geen items geselecteerd.');
				return false;
			}

			if( ! confirm('Weet u zeker dat u deze actie wilt uitvoeren?'))
				return false;

			return true;
		});

		$('#select_all').live('click',function()
		{
			var checked = this.checked;
			gridForm.find('.rowCheckbox').each(function()
			{
				this.checked = checked;
			});
		});

		gridForm.find('.rowCheckbox').click(function()
		{
			$('#select_all').attr('checked', gridForm.find('.rowCheckbox').length == gridForm.find('.rowCheckbox:checked').length);
		});
	});
}
