// Image switcher

$(document).ready(function() {
	// Fancy box initialization
	$("#rightSectionItemView a.fancy").fancybox({
		'hideOnContentClick': true,
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'overlayShow': true,
		'overlayOpacity': 0.8
	});

	// Enhancements for viewing larger versions of the product images
	$('a.imageSwitcher').click(function() {
		var target = $(this).attr('href');
		var newLink = target.split('_')[0];
		
		$('a.fancy').attr({href: newLink});
		
		$('img.main').fadeOut('slow', function () {
			$('img.main').attr({src: target}).fadeIn('medium');
		});
		return false;
	});

	// If the image is clicked, don't follow the link - we have the functionality covered via javascript
	// If the user has javascript disabled, they'll still be able to see the larger image
	// since they have a link to it, however
	// $('a.imageSwitcher').click(function() {return false;}); 
	
	
	// Add a little usability enhancement to form text entry boxes

	$('input:text').focus(function() {
		if (this.value == this.defaultValue) {this.value = "";}});
		$('input:text').blur(function() {if (!this.value.length) {this.value = this.defaultValue;}});
		
	// Animation on main store category menus
	$('ul.categories a').click(function() {
		$(this).parent().children('ul').toggle('slow');
		$(this).parent().siblings('li').children('ul.subCategory').hide('slow');
		return false;
	});

	// Billing / shipping form enhancement
	$('input#shippingYes').click(function() {
		$('fieldset.shippingAddress input:not(:radio), fieldset.shippingAddress select').attr('disabled', 'disabled');
	});

	$('input#shippingNo').click(function() {
		$('fieldset.shippingAddress input:not(:radio), fieldset.shippingAddress select').removeAttr('disabled');
	});
	$('#billingForm input').focus(function() {this.select()});
	$('input#shippingNo').click();
});

