jQuery(document).ready(function($){
	// check the first radiobutton
	$('#types li:first-child input').attr('checked', 'checked');
	
	$('#types :radio').each(function(e){
		$(this).bind('click', function(e){
			var typeValue = $(this).siblings('label').children('.type-value').html();
			var productPrice = JS_NETLASH.main.parsefloat($(this).siblings('label').children('strong').children('.type-price').html());
			var subtotal = productPrice * JS_NETLASH.main.parseint($('#cart-qty').val());

			$('#product-price').attr('rel', 'type-' + $(this).attr('id').substr(5)).html(productPrice);
			$('#cart-type-id').html($(this).attr('id').substr(5));
			$('#cart-type-value').html(typeValue);
			$('#cart-price').html(productPrice);
			$('#cart-subtotal').html(subtotal);
			$('#product-type').html($('#types-title').html() + ' ' + $(this).val());
			$('#add-to-cart-error').addClass('hidden');
		});
	});
	
	if ($('#types :radio').length == 0) $('#product-type').html('');
	
	JS_NETLASH.shopCore.hookEvents(0);
	
	$('#cart-qty').bind('keypress', function numbersonly(e) {
		var unicode = (e.charCode ? e.charCode : e.keyCode);
		// the key is backspace, left or right arrow or tab - allowed so return true
		if (unicode == 8 || unicode == 9 || unicode == 37 || unicode == 39 || unicode == 46) { return true; }
		// not a number - not allowed so return false
		if (unicode < 48 || unicode > 57) { return false; }
	});

	// Lightbox stuff
	$('.showAll').bind('click', function() {
		$('.lightBoxThumbs li.selected').removeClass('selected');
		$('#lbPreview1Thumb').addClass('selected');
		$('#lbBigImage').attr('src', $('#lbPreview1Src').html());
		$('#lbBigAlt').html($('#lbPreview1Alt').html());
		$('#lbBigDescr').html($('#lbPreview1Descr').html());
	});
	
	$('.showLb').bind('click', function() {
		var showItem = $(this).attr('id').substring(6);
		$('.lightBoxThumbs li.selected').removeClass('selected');
		$('#lb' + showItem + 'Thumb').addClass('selected');
		$('#lbBigImage').attr('src', $('#lb' + showItem + 'Src').html());
		$('#lbBigAlt').html($('#lb' + showItem + 'Alt').html());
		$('#lbBigDescr').html($('#lb' + showItem + 'Descr').html());
	});
	
	$('.changeBigImage').bind('click', function(evt) {
		evt.preventDefault();
		var showItem = $(this).attr('id').substring(6);
		$('.lightBoxThumbs li.selected').removeClass('selected');
		$('#lb' + showItem + 'Thumb').addClass('selected');
		$('#lbBigImage').attr('src', $('#lb' + showItem + 'Src').html());
		$('#lbBigAlt').html($('#lb' + showItem + 'Alt').html());
		$('#lbBigDescr').html($('#lb' + showItem + 'Descr').html());
	});
	
	$('#bigThumb').bind('mouseover', function(evt) {
		$('#bigThumb .loop').show();
	}).bind('mouseout', function(evt) {
		$('#bigThumb .loop').hide();
	});

	// Keyboard support
	$('#bigThumb a').bind('focus', function(evt) {
		$('#bigThumb .loop').show();
	}).bind('blur', function(evt) {
		$('#bigThumb .loop').hide();
	});
	
});