jQuery(document).ready(function(){
	//Set scrolls for this page
	
	jQuery('.productSpecs a').click(function(){
		jQuery.scrollTo(jQuery('#productSpecs'), scrollDuration);
	});
	
	//jQuery('#imageGallery .imageWrapper a').lightBox({fixedNavigation:true});
	//jQuery('#imageGalleryNav a').lightBox({fixedNavigation:true});
	
	jQuery('#imageGalleryNav a').click(
		function(){
			//Prepare the image for loading
			var img = new Image();
			var newImagSrc = jQuery(this).children().attr('src').replace('ti', '');
			var $thisParent = jQuery(this).parent();
			
			//jQuery('.imageWrapper img').hide();
			
			jQuery(img)
				.load(function(){
					jQuery('.imageWrapper img.productImage').attr('src', newImagSrc);
					jQuery('#imageGalleryNav li.selected').removeClass('selected');
					$thisParent.addClass('selected');
				})
				.attr('src', newImagSrc)
			;
			
		}
	)
	
	
	// Quantity
	jQuery('input.quantity').focus(function(){
		jQuery(this).select();
	});
	
	// Length
	jQuery('select.length').change(function(){
		
		// Get new price
		var metrePrice = parseFloat(jQuery(this).closest('form').find('input[name=sale_price_per_metre]').val());
		//var cuttingPrice = parseFloat(jQuery(this).closest('form').find('input[name=cut_length_one_off_price]').val());
		
		var length;
		if( jQuery(this).val() ){
			length = parseFloat(jQuery(this).val());
		} else {
			length = 1;
		}
		
		var newPrice = (metrePrice * length);
		newPrice = roundNumber(newPrice, 2).toFixed(2);
		
		var thisHTML = '&pound;' + newPrice;
		
		if( length == 1 ){
			thisHTML += '/m';
		}
		
		jQuery(this).closest('.buyBox').find('div.price').html(thisHTML);
	});
	
});
