var Product = {}; $load_library('SHARED', 'ajax_functions.js'); $load_library('SHARED', 'Product/external.js'); $load_library('SHARED', 'Product/social.js'); $load_library('SHARED', 'protozoom.js'); Product.alert = (function(alert_message, additional_options, track_alert) { CMSTemplate.alert(alert_message, additional_options); if(!track_alert) CMSTemplate.Site.Analytics.addEvent('Product', 'Alert', alert_message); }); document.addEventListener("DOMContentLoaded", function() { let form_obj = Product.getInstance('Form'), form_elm = form_obj.getElement('addProduct'); if(form_elm) { form_obj.watchElements(); form_elm.addEventListener('submit', Product.Cart.Submit.bind(this)); } Product.Rating = new ProductRating(window.starcount); Product.External.getInstance(); new Product.Social(); if(CMSTemplate.getSetting('large_order') !== null) { form_obj.getElement('quantity').addEventListener('change', function() { if(form_obj.getElement('quantity').getValue() > 1) alert(CMSTemplate.getSetting('large_order')); }); } if(form_elm) form_obj.updatePrice(); new Product.Comments(); }); Product.Image = Class.create({ initialize: function(options) { if(Product.Image.initialized) return false; Product.Image.initialized = this; Product.Image.Hooks = { FileName: [this.mainFilename.bind(this)], Failure : [], Loading : [] }; this.options = Object.extend({ currentImage: -1, imageZoom : function(evt) {}, imageSelect : this.imageSelect.bind(this) }, options || {}); this.main_image = document.getElementById('main-image'); this.product_image = document.getElementById('product-image'); this.image_selector = $$('.image-selector a'); this.image_link = this.main_image.down('a.image-link') || document.createElement('a'); this.image_title_text = document.getElementById('image_title_text') || document.createElement('div'); this.fail_notice = this.main_image.down('.fail-notice') || document.createElement('div'); this.main_video = document.getElementById('main-video') || document.createElement('div'); this.image_link.addEventListener('click', this.zoomImage.bind(this)); this.product_image.addEventListener('error', this.imageFailure.bind(this, this.product_image, 'medium')); this.product_image.addEventListener('load', this.imageLoaded.bind(this)); this.thumbnails = {}; counter = 0; this.image_selector.each(function(x) { var imageId = x.readAttribute('id'); if(imageId === null) { // For legacy templates (v. 1, 2, 3) imageId = counter++; x.setAttribute('id', 'selectImage' + imageId); } else { imageId = imageId.replace('selectImage', ''); } x.addEventListener('click', function(evt) { evt.stopPropagation(); evt.preventDefault(); this.changeImage(imageId); }.bind(this)); this.thumbnails[imageId] = x.down('img.thumb-image'); if(this.thumbnails[imageId]) { this.thumbnails[imageId].store('image_id', imageId) .addEventListener('error', this.imageFailure.bind(this, this.thumbnails[imageId], 'thumb')); } }.bind(this)); }, cartPrimaryImage: function() { if(typeof this.cart_primary_image === 'undefined') { this.cart_primary_image = {}; ['large', 'medium', 'thumb'].each(function(x) { this.cart_primary_image[x] = new Element('input', { type: 'hidden', name: 'cartImage[' + x + ']' }); }.bind(this)); var add_product = Product.getInstance('Form') .getElement('addProduct'); if(typeof add_product.insert !== 'undefined') { add_product.insert(this.cart_primary_image.large); add_product.insert(this.cart_primary_image.medium); add_product.insert(this.cart_primary_image.thumb); } } this.cart_primary_image.large.setValue(Product.Image.List[0].filenames.large); this.cart_primary_image.medium.setValue(Product.Image.List[0].filenames.medium); this.cart_primary_image.thumb.setValue(Product.Image.List[0].filenames.thumb); }, getSelectedImage: function() { return this.product_image; }, zoomImage: function(evt) { if(this.product_image.hasClassName('load-fail')) { Product.alert('The image failed to load. This error has been logged and we are working to get it resolved.'); } this.options.imageZoom(evt); }, displayYouTubeVideo: function(imageId) { var image = Product.Image.List[imageId]; var video_iframe = '