function extractProductMicrodata(){const e=document.querySelector('script[type="application/ld+json"]');if(e)try{const t=JSON.parse(e.innerText);if("Product"===t["@type"]){return{name:t.name||"",sku:t.sku||"",description:t.description||"",image:t.image||"",brand:t.brand?.name||"",price:t.offers?.price||"",url:t.offers?.url||"",ratingValue:t.aggregateRating?.ratingValue||"",reviewCount:t.aggregateRating?.reviewCount||""}}}catch(e){console.error("Error parsing JSON-LD data:",e)}const t=document.querySelector('[itemtype="http://schema.org/Product"]');if(!t)return null;let r={};["name","sku","description","image","brand","price","url"].forEach((e=>{const a=t.querySelector(`[itemprop="${e}"]`);a&&(r[e]=a.getAttribute("content")||a.innerText)}));const a=t.querySelector('[itemprop="brand"] [itemprop="name"]');a&&(r.brand=a.innerText);const o=t.querySelector('[itemprop="offers"] [itemprop="price"]');o&&(r.price=o.getAttribute("content")||o.innerText);const n=t.querySelector('[itemprop="offers"] [itemprop="url"]');n&&(r.url=n.getAttribute("content")||n.innerText);const i=t.querySelector('[itemprop="aggregateRating"] [itemprop="ratingValue"]');i&&(r.ratingValue=i.innerText);const d=t.querySelector('[itemprop="aggregateRating"] [itemprop="reviewCount"]');return d&&(r.reviewCount=d.innerText),r}async function postProductMicrodata(){showAlert("fa-pulse fa-spinner","Processing","Please wait...","#FFFFFF",!1);let e=extractProductMicrodata();if(!e)return void console.warn("No product microdata found!");let t=document.getElementById("txtQty").value;e.qty=t;let r=document.getElementById("printing");r&&"Yes"==r.value&&(e.printing="Y");try{const r=0==selectsWithDataExtra.length?"/basket/add":"/basket/add-multiple",o=0==selectsWithDataExtra.length?e:{items:[e]};for(var a of selectsWithDataExtra)""!==a.value&&o.items.push({sku:a.value,qty:t});const n=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}),i=await n.json();i.mysteryGifts?showOverlay({URL:"/popups/mystery-gift"}):showAlert("fa-check","Added!","Added item(s) to your basket!","#FFFFFF",!1),setBasket({Qty:i.totalQty,Cost:i.totalPrice}),"function"==typeof window.track_add_basket&&window.track_add_basket()}catch(e){console.error("Error posting product data:",e)}}async function postWishlistMicrodata(){let e=extractProductMicrodata();if(!e||!e.sku)return void showAlert("fa-exclamation-triangle","Oops","We couldn't detect the product to add.","#FFFFFF",!1);let t=parseInt(document.getElementById("txtQty").value,10)||1;e={sku:String(e.sku).trim(),qty:t};const r=[e];for(const e of selectsWithDataExtra)""!==e.value&&r.push({sku:String(e.value).trim(),qty:t});if(await isUserLoggedIn())try{showAlert("fa-pulse fa-spinner","Adding to wishlist","Please wait...","#FFFFFF",!1);const a=1===r.length?"/wishlist/add":"/wishlist/add-multiple",o=1===r.length?r[0]:{items:r},n=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(o)});if(401===n.status)return void promptLoginOrRegister();const i=await n.json();if(!n.ok||i&&!1===i.success){const e=i&&(i.error||i.message)||"Unable to add to wishlist.";throw new Error(e)}window.WishlistView&&"function"==typeof window.WishlistView.refresh&&window.WishlistView.refresh(!0),showAlert("fa-heart","Saved","Item(s) added to your wishlist.","#FFFFFF",!1),"function"==typeof window.track_add_wishlist&&window.track_add_wishlist({sku:e.sku,qty:t})}catch(e){console.error("Wishlist error:",e),showAlert("fa-exclamation-triangle","Wishlist",e.message||"Unable to add to wishlist.","#FFFFFF",!1)}else promptLoginOrRegister()}function qty_increase(){var e=parseInt(document.getElementById("txtQty").value,10);e=isNaN(e)?1:e,e++,document.getElementById("txtQty").value=qty_check(e),updatePrice()}function qty_decrease(){var e=parseInt(document.getElementById("txtQty").value,10);e=isNaN(e)?1:e,e--,document.getElementById("txtQty").value=qty_check(e),updatePrice()}function qty_check(e){var t=isNaN(e)?1:e;return t>999?t=999:t<1&&(t=1),t}function qty_update(){var e=parseInt(document.getElementById("txtQty").value,10);document.getElementById("txtQty").value=qty_check(e),updatePrice()}async function isUserLoggedIn(){try{if(window.__user&&window.__user.ID)return!0;return(await fetch("/wishlist/totals",{credentials:"same-origin"})).ok}catch{return!1}}function promptLoginOrRegister(){try{"function"==typeof showAlert&&showAlert("icon-cancel-circled","Please sign in to add to your wishlist",'',"#FFFFFF",!1)}catch{}}function followToLogin(){const e=encodeURIComponent(window.location.pathname+window.location.search+window.location.hash);window.location.href="/login?url="+e}function updatePrice(){var e=document.querySelector('[itemprop="price"]').content,t=parseInt(document.getElementById("txtQty").value,10),r=e*t;for(var a of selectsWithDataExtra)if(""!==a.value){let e=a.options[a.selectedIndex];e&&e.hasAttribute("data-extra-price")&&(r+=e.getAttribute("data-extra-price")*t)}document.getElementById("price").innerHTML=localizeCost(r)}var getFinalPrice=function(e,t){return Number((e*((100-t)/100)).toFixed(2))};const selectsWithDataExtra=document.querySelectorAll("[data-extra] select");document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll("[data-basket-add]").forEach((e=>{e.addEventListener("click",postProductMicrodata)})),selectsWithDataExtra.forEach((e=>{e.addEventListener("click",updatePrice)}));document.querySelectorAll("[data-wishlist-add]").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault(),postWishlistMicrodata()}))}))}));var prod_gallery_images,prod_isMobile=window.innerWidth<=980,prod_gal_selector=document.querySelector(".prod_gal_selector"),galleryCont=document.getElementById("galleryCont"),videoCont=document.getElementById("videoCont"),galleryModel=function(e){this.media=void 0!==e.ImagePath?"Image":"Video";var t=e.ImagePath;t&&"/"!==t.charAt(0)&&(t="/"+t),this.source=t||e.VideoLink,this.orderID=e.ImageOrder||e.VideoOrder,this.caption=e.Caption},gallery=[];if(void 0!==window.__gallery)for(var i in window.__gallery)gallery.push(new galleryModel(window.__gallery[i]));if(void 0!==window.__videos)for(var i in window.__videos)gallery.push(new galleryModel(window.__videos[i]));function createGallery(){galleryCont.innerHTML="",videoCont.innerHTML="",gallery.forEach((function(e,t){var r=e.caption||(document.querySelector("h1")?document.querySelector("h1").textContent:"Gala Tent")+" Gallery image "+(t+1);if("Image"===e.media)(a=document.createElement("div")).className="gal_img",(o=document.createElement("img")).src=cdn.getSRC(e.source,{w:60,h:60}),o.setAttribute("data-position",t),o.setAttribute("caption",r),o.setAttribute("title",r),o.setAttribute("alt",r),o.classList.add("animated","fadeIn"),a.appendChild(o),galleryCont.appendChild(a);else if("Video"===e.media){var a,o;(a=document.createElement("div")).className="gal_img",(o=document.createElement("img")).src="https://i.ytimg.com/vi/"+e.source+"/hqdefault.jpg",o.setAttribute("data-position",t),o.setAttribute("caption",r),o.setAttribute("title",r),o.setAttribute("media",e.media),o.setAttribute("yt",e.source),o.setAttribute("loading","lazy"),o.classList.add("animated","fadeIn"),a.appendChild(o),videoCont.appendChild(a)}})),prod_gallery_images=document.querySelectorAll(".prod_gal_selector .gal_img");for(let e=0;e=gallery.length&&(e=0);try{if(void 0===e)return;prod_current=e;var r=document.body.classList.contains("overlay_gal");if(!t&&void 0!==prod_current&&!r)return prod_expand();var a=prod_last;prod_last=e;var o=document.getElementById("prod_gallery_main");o.innerHTML="";var n=prod_gallery_images[e].querySelector("img"),i=n.getAttribute("src").replace("?w=60&h=60",""),d=n.getAttribute("media"),l=n.getAttribute("yt");if("Video"==d)o.innerHTML='
',setTimeout(yt_light,0),prod_isMobile||setTimeout((function(){document.querySelector(".prod_gal_container .youtube-player").firstChild.click()}),1e3);else{var c=new Image;c.src=i+(r?"?w=1500&h=1500":"?w=400&h=400"),c.alt=n.alt,c.title=n.title,c.classList.add("zoom"),o.innerHTML='',c.onload=function(){o.innerHTML="",a!==e&&c.classList.add("fadeIn","animated"),r&&c.classList.add("zoomlg","animated","fadeIn"),o.appendChild(c)}}}catch(e){}}function prod_expand(){document.body.classList.add("overlay_gal"),prod_setImage(prod_current,!1)}function prod_despand(){document.body.classList.remove("overlay_gal")}function init_md_gal(){document.querySelector(".expand").addEventListener("click",(function(){prod_expand()})),document.querySelector(".despand").addEventListener("click",(function(){prod_despand()})),document.querySelector(".gal-reverse").addEventListener("click",(function(){prod_deltaImage(-1)})),document.querySelector(".gal-next").addEventListener("click",(function(){prod_deltaImage(1)})),document.querySelectorAll("img.alt").forEach((e=>{e.addEventListener("mouseleave",(function(e){e.target.setAttribute("src",e.target.getAttribute("data-orig"))})),e.addEventListener("mouseover",(function(e){e.target.setAttribute("src",e.target.getAttribute("data-alt"))}))}))}document.addEventListener("DOMContentLoaded",(function(){init_md_gal()})),document.getElementById("shareButton").addEventListener("click",(async()=>{const e=document.title,t=document.querySelector("h1")?document.querySelector("h1").textContent:"";if(navigator.share)try{await navigator.share({title:e,text:"Look at this "+t+"!",url:window.location.href})}catch(e){}else modalOpen(document.getElementById("share-product"))}));