$(function(){
	$('#dpg').dGallery();
	$('#vg').dGallery({
		activeClass: 'vg-active',
		activateOnMouseover: false,
		disabledClass: 'vg-disabled',
		captions: '#vg-captions',
		full: '#vg-full',
		hideScrollClass: 'vg-hide-scroll',
		noScrollClass: 'vg-no-scroll',
		scrollable: {
			items: '#vg-thumbs',
			next: '#vg-next',
			prev: '#vg-prev',
			scrollable: '#vg-scrollable'
		},
		size: {
			thumb: {width: 120, height: 90},
			full: {width: 560, height: 315},
			zoom1: {width: 800, height: 800},
			zoom2: {width: 1600, height: 1600}
		},
		toolbar: '#vg-toolbar',
		zoom: {
			lens: '#vg-zoom-lens',
			size: {
				source: {width: 300, height: 300},
				zoom: {width: 300, height: 300},
				zoom1: {width: 800, height: 800},
				zoom2: {width: 1600, height: 1600}
			},
			zoom: '#vg-zoom',
			zoomIn: '#vg-zoom-in',
			zoomOut: '#vg-zoom-out'
		}
	});
	$('#prod-tabs').dTabs({
		currentTabClass: 'prod-tab-current',
		sectionAttribute: 'data-section',
		sectionClass: 'prod-section',
		sectionIdSuffix: 'prod-',
		visibleSectionClass: 'prod-section-show'
	});
	
	if ($('#prod-items').length && $('#prod-excerpt').length && !$('#prod-more-details').length) {
		$('#prod-tabs a[data-section="details"]').hide();
	}
	$('.a2c-icons').find('a').each(function(){
		$(this).removeAttr('href');
	}).end().find('span').T().mousedown(function(){
		$('#prod-tabs a[data-section="shipping"]').mousedown();
	});
	$('.a2c-icon-new').T();
	$('#prod-excerpt a').removeAttr('href').mousedown(function(){
		$('#prod-tabs a[data-section="details"]').mousedown();
	});
	$('.a2c-qty').QO();
	$('#prod-more img').T();
	
	$('#prod-page').mousemove(function(){ // attempt to fix rendering issues in IE when excerpt appears and buttons don't move down
		$('.dss-btn').hide().show();
		$(this).unbind('mousemove'); // only do this the first time the mouse moves
	}).filter('.ie6').each(function(){ // fix ie6 issue with floating gallery
		var _max_middle = Math.max($('#dpg').outerHeight(), $('#prod-items').outerHeight(), $('#prod-details').outerHeight(), $('#prod-specials').outerHeight(), $('#prod-more').outerHeight(), $('#prod-related').outerHeight(), $('#prod-shipping').outerHeight());
		$('#middle-right').height($('.dss-breadcrumb').outerHeight() + $('#prod-name').outerHeight() + $('#prod-tabs').outerHeight() + _max_middle + 50);
	})
	
	// reviews
	$.fn.RVU = function(){
		return this.each(function(){
			//$('#prod-share').css('position', 'relative').prepend('<div id="review" class="review-min"><h3><a><img alt="envelope" src="/pcat/images/clear.gif"> Review this product</a></h3></div> ');
			$('#prod-share').css('position', 'relative').prepend('<div id="review" class="review-min"><h3><a>Review this product</a></h3></div> ');
			$('.review-min').live('click', function(){
				var $review = $(this);
				if (!$('button', $review).length) {
					$('p', $review).remove();
					var $dropdown = $('<select class="dss-input dss-input-select" id="review-sku"></select>');
					$('#prod-items .a2c-sku').each(function(){
						var _sku = $(this).text();
						$dropdown.append('<option value="' + _sku + '">' + _sku + '</option>');
					});
					$dropdown.wrap('<div></div>');
					$review.append('<img alt="close" id="review-close" src="/themes/close.gif"><p class="dss-p dss-medium">We strive to provide you with the best products possible. If we can improve our product selection to better serve you, please let us know. We value your opinion!</p><p class="dss-p dss-p-center"><label for="review-sku">Item Number:</label> ' + $dropdown.parent().html() + '</p><p class="dss-p dss-p-center"><textarea class="dss-input dss-input-textarea"></textarea></p><p class="dss-p dss-p-center dss-medium"><button class="dss-btn dss-btn-primary" type="button" value="Submit Review">Submit Review</button></p>');
				}
				$('#prod-items .dss-btn').css('z-index', '1');
				$review.addClass('review-max').removeClass('review-min').find('textarea').focus();
			});
			$('#review-close').live('click', function(){
				$('.review-max').addClass('review-min').removeClass('review-max').height('auto');
			});
			$('.review-max button').live('click', function(){
				$review = $('#review');
				$review.css('height', $review.height());
				var _sku = $('#review-sku :selected').val();
				var _message = $('textarea', $review).val();
				if ($.trim(_message).length > 0) {
					$review.addClass('review-loading');
					$('p', $review).remove();
					$.ajax({
						type: 'POST',
						url: '/pcat/xt_marketing_feedback.php',
						data: 'feedback=[Review: ' + _sku + '] ' + _message,
						success: function(){ $.fn.RVU.thanks(); },
						error: function(){ $.fn.RVU.thanks(); }
					});
				}
			});
		});
	};
	$.fn.RVU.thanks = function(){
		$('#review').removeClass('review-loading').append('<p class="dss-p dss-medium">Thank you for your review! While we will be unable to respond to your comments directly, your input will help improve Delasco.com, the premier destination in dermatology!</p><p class="dss-p dss-medium">If you have a question or need assistance, please contact Customer Service:</p><p class="dss-p dss-medium">Email: <a href="mailto:questions@delasco.com" target="_blank">questions@delasco.com</a></p><p class="dss-p dss-medium">Phone: (800) 831-6273 or (712) 323-3269</p>');
	};
	if ($('body').hasClass('catalog-3')) {
		$('body').RVU();
	}
});
(function() {
	if (window.location.hostname == 'www.delasco.com') {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	}
})();

