  jQuery(function(){
	product.init();
	jQuery('#product-image-scroll').serialScroll({
	  target: '.wrap',
		items:'li',
		prev:'a.previous',
		next:'a.next',
		axis:'xy',
		duration:1000,
		start: 0, 
		step:3, 
		lazy: true,
		onBefore:function( e, elem, jQuerypane, jQueryitems, pos ){
			e.preventDefault();
			if( this.blur )
				this.blur();
			
 		},
		onAfter: function(elem){
			scroller.setup(elem, jQuery("#product-image-scroll .wrap"), jQuery("#product-image-scroll ul"), jQuery("#product-image-scroll li"), jQuery('#product-image-scroll a.previous'), jQuery('#product-image-scroll a.next'));
		}
	});
});
var product = {
	scrollWidth : 0,
	init : function(){
	  jQuery("#product-image-scroll li:not('.previous,.next')").each(function(){
	    product.scrollWidth += jQuery(this).width();
	  });
		jQuery("#product-image-scroll ul").width((product.scrollWidth));
		if(jQuery("#product-image-scroll li").size() > 3){
			jQuery('#product-image-scroll').prepend('<a href="#" class="previous"><img src="/images/template/product_page/icon_previous.gif" width="14" height="26"></a>');
			jQuery('#product-image-scroll').append('<a href="#" class="next"><img src="/images/template/product_page/icon_next.gif" width="14" height="26"></a>')
		}
		jQuery('#product-image-scroll a.previous').hide();
		product.imageSwap();
	},
	imageSwap : function(){
		jQuery("#product-image-scroll li img").each(function(){
			jQuery(this).click(function(){
				var re = "product_[A-Za-z0-9_]*.jpg$";
				var thumbSrc = jQuery(this).attr("src");
				var largeSrc = jQuery("#product-image").attr("src");
				var thumbImage = thumbSrc.match(re);
				var largeImage = largeSrc.match(re);
				var newLargeSrc = largeSrc.replace(largeImage, thumbImage);
				jQuery("#product-image").attr("src", newLargeSrc);
					return false;
				});
		});
	}
}

jQuery(document).ready(function() {
	
		jQuery('input.submit').show();
		
		/* if(location.href.match(/year/)) {
			jQuery('#special-attributes').html('<a href="#">Renewing MUCC Member?</a> <span id="renew" style="display: none;"></span>');
			jQuery('#special-attributes').show();
			jQuery('#special-attributes a').click(function() {
				jQuery('#special-attributes a').fadeOut('slow', function() {
					jQuery('#renew').html('<input type="text" class="defaultText" title="Enter your MUCC ID" name="member_id" value="Enter your MUCC ID" />');
					defaultText.init();
					jQuery('input.submit').click(function() {
						if(jQuery('input.defaultText').val() == "Enter your MUCC ID" || jQuery('input.defaultText').val() == "") {
							jQuery('input.defaultText').remove();
						}
					});
					jQuery('#renew').fadeIn('slow');
				});
				return false;
			});
		} */
		if(location.href.match(/mucc_club_member_subscription/)) {
			jQuery('input.submit, #product-form > p:first-child').hide();
			jQuery('#special-attributes').css('margin-left','0').show();
			jQuery('#special-attributes').html('<input type="text" class="defaultText affiliate_club" title="MUCC Affiliate Club" name="mucc_affiliate_club" value="MUCC Affiliate Club" /> <input class="affiliate_club_sub" type="button" value="Submit" />');
			jQuery('#special-attributes input.affiliate_club_sub').click(function() {
				if(jQuery('input.affiliate_club').val() != '' && jQuery('input.affiliate_club').val() != 'Enter your MUCC Affiliate Club') {
					jQuery('input.affiliate_club_sub, input.affiliate_club').fadeOut('slow', function() {
						jQuery('input.submit, #product-form > p:first-child').fadeIn('slow');
					})
				}
			});
		}
		if(location.href.match(/gift/) && !location.href.match(/gift_giver_bonus/)) {
			jQuery('input.submit, #product-form > p:first-child').hide();
			jQuery('#special-attributes').html('<label for="address_select" style="display:block;">Would you like the gift card/package sent to your billing address, or to the Gift Recipients Address?</label><select id="address_select"><option>Select Delivery Address</option><option>My Billing Address</option><option>Gift Recipients Address</option></select>');
			jQuery('#special-attributes').show();
			jQuery('#address_select').change(function() {
				if(jQuery('#address_select option:selected').text() == 'My Billing Address') {
					jQuery('#address_select, #special-attributes label').fadeOut('slow', function() {
						jQuery('input.submit, #product-form > p:first-child').fadeIn('slow');
					});
				}
				if(jQuery('#address_select option:selected').text() == 'Gift Recipients Address') {
					jQuery('#address_select, #special-attributes label').fadeOut('slow', function() {
						jQuery('#special-attributes').html('<label for="gift_address" style="display:none;">Please enter the name and mailing address of the person you would like to have this gift subscription sent to:</label> <textarea style="display:none;" id="gift_address" name="Gift Address"></textarea><input class="gift_add_sub" type="button" value="Submit" />');
						jQuery('#special-attributes textarea, #special-attributes label').fadeIn('slow');
						jQuery('#special-attributes input.gift_add_sub').click(function() {
							if(jQuery('#special-attributes textarea').val() == "" || jQuery('#special-attributes textarea').val() == "Please enter a name and mailing address") {
								jQuery('#special-attributes textarea').val('Please enter a name and mailing address');
							}
							else {
								jQuery('input.gift_add_sub, textarea#gift_address, #special-attributes label').fadeOut('slow', function() {
									jQuery('input.submit, #product-form > p:first-child').fadeIn('slow');
								});
							}
						});
					});
				}
			});
		}
		if(location.href.match(/subscribe/)) {
			jQuery('.text-ads > li').each(function (i) {
				jQuery(this).click(function() {
					location=jQuery(this).children('a').attr('href');
				});
			});
		}		
	});