(function($){'use strict';const CONSTANTS={SELECTORS:{WP_GALLERY:'.wp-block-gallery',ML_LIGHTBOX_ENABLED:'.ml-lightbox-enabled',ML_LIGHTBOX_BUTTON:'.ml-lightbox-button',LG_INITIALIZED:'.lg-initialized',CONTENT_CONTAINERS:'.entry-content, .post-content, .page-content, article, .content, main, [role="main"], .site-main, .elementor-widget-theme-post-content, .et_pb_section, .fusion-body'},CLASSES:{ML_LIGHTBOX_ENABLED:'ml-lightbox-enabled',ML_LIGHTBOX_BUTTON:'ml-lightbox-button',LG_INITIALIZED:'lg-initialized'},VIDEO_HANDLERS:{youtube:{selector:'div.youtube[data-id]',idAttr:'data-id',urlTemplate:(id)=>`https://www.youtube.com/watch?v=${id}`,thumbTemplate:(id)=>`https://img.youtube.com/vi/${id}/maxresdefault.jpg`},vimeo:{selector:'div.vimeo[data-id]',idAttr:'data-id',urlTemplate:(id)=>`https://vimeo.com/${id}`,thumbTemplate:(id)=>`https://vumbnail.com/${id}.jpg`,fallbackSelectors:['[data-slide-id]','a[href*="vimeo.com"]']},externalVideo:{selector:'div.external-video',sourcesAttr:'data-sources',posterAttr:'data-poster'},localVideo:{selector:'div.local-video',sourcesAttr:'data-sources',posterAttr:'data-poster'}}};function getButtonText(){return(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.button_text)?mlLightboxSettings.button_text:'Open in Lightbox';}
$(document).ready(function(){initLightboxes();removeConflictingAttributes();});function removeConflictingAttributes(){$('.ml-lightbox-enabled').each(function(){var $container=$(this);if($container.find('.ml-lightbox-button').length>0){$container.removeAttr('href');$container.removeAttr('data-src');$container.removeAttr('data-thumb');}});}
function initLightboxes(){if(typeof lightGallery==='undefined'){console.warn('MetaSlider Lightbox: LightGallery not loaded');return;}
if(typeof mlLightboxSettings==='undefined'){console.warn('MetaSlider Lightbox: Settings not available');return;}
initLightboxSystems();}
function initLightboxSystems(){initMetaSlider();var manualExcluded=mlLightboxSettings.manual_excluded===true||mlLightboxSettings.manual_excluded==='1'||mlLightboxSettings.manual_excluded===1;if(!manualExcluded){var useButtonsForManual=false;if(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.metaslider_options){useButtonsForManual=mlLightboxSettings.metaslider_options.show_lightbox_button!==false;}
$('.ml-lightbox-enabled').each(function(){initLightboxEnabled($(this),useButtonsForManual);});}
var overrideEnabled=typeof mlLightboxSettings!=='undefined'&&(mlLightboxSettings.override_enlarge_on_click===true||mlLightboxSettings.override_enlarge_on_click==='1'||mlLightboxSettings.override_enlarge_on_click===1);if(overrideEnabled&&!manualExcluded){var $wordpressOverrideGalleries=$('.wp-block-gallery').filter(function(){var $gallery=$(this);var $wpImagesOld=$gallery.find('.wp-lightbox-container img[data-wp-on-async--click="actions.showLightbox"]');var $wpContainersNew=$gallery.find('.wp-lightbox-container[data-wp-interactive="core/image"]');return($wpImagesOld.length>1||$wpContainersNew.length>1)&&!$gallery.hasClass('ml-lightbox-enabled')&&!$gallery.hasClass('lg-initialized');});$wordpressOverrideGalleries.each(function(){initWordPressGallery($(this));});}
var pageExcluded=mlLightboxSettings.page_excluded===true||mlLightboxSettings.page_excluded==='1'||mlLightboxSettings.page_excluded===1;if(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.enable_galleries&&!pageExcluded){var $wordpressGalleries=$('.wp-block-gallery').filter(function(){var $gallery=$(this);if($gallery.attr('data-ml-exclude-gallery')==='true'){return false;}
var $wpImagesOld=$gallery.find('.wp-lightbox-container img[data-wp-on-async--click="actions.showLightbox"]');var $wpContainersNew=$gallery.find('.wp-lightbox-container[data-wp-interactive="core/image"]');var overrideEnabled=mlLightboxSettings.override_enlarge_on_click===true||mlLightboxSettings.override_enlarge_on_click==='1'||mlLightboxSettings.override_enlarge_on_click===1;if(!overrideEnabled&&($wpImagesOld.length>0||$wpContainersNew.length>0)){return false;}
return($wpImagesOld.length>1||$wpContainersNew.length>1)&&!$gallery.hasClass('ml-lightbox-enabled')&&!$gallery.hasClass('lg-initialized');});$wordpressGalleries.each(function(){initWordPressGallery($(this));});}
if(!manualExcluded){var $wordpressContainersOld=$('.wp-lightbox-container').has('button[data-wp-on-async--click="actions.showLightbox"]');var $wordpressContainersNew=$('.wp-lightbox-container[data-wp-interactive="core/image"]');var $allWordpressContainers=$wordpressContainersOld.add($wordpressContainersNew);var $unprocessedContainers=$allWordpressContainers.filter(function(){var $figure=$(this);var $parentGallery=$figure.closest('.wp-block-gallery');var overrideEnabled=typeof mlLightboxSettings!=='undefined'&&(mlLightboxSettings.override_enlarge_on_click===true||mlLightboxSettings.override_enlarge_on_click==='1'||mlLightboxSettings.override_enlarge_on_click===1);if(!overrideEnabled){return false;}
if($parentGallery.length>0){var $galleryContainers=$parentGallery.find('.wp-lightbox-container[data-wp-interactive="core/image"], .wp-lightbox-container').has('button[data-wp-on-async--click="actions.showLightbox"]');if($galleryContainers.length>1){return false;}}
return!$figure.hasClass('ml-lightbox-enabled')&&!$figure.hasClass('lg-initialized')&&($parentGallery.length===0||!$parentGallery.hasClass('lg-initialized'));});$unprocessedContainers.each(function(){var $container=$(this);var $img=$container.find('img').first();if($img.length){if(useButtonsForManual){initWordPressEnlargeOnClickWithButton($img);}else{initWordPressEnlargeOnClick($img);}}});}
var overrideEnabled=typeof mlLightboxSettings!=='undefined'&&(mlLightboxSettings.override_enlarge_on_click===true||mlLightboxSettings.override_enlarge_on_click==='1'||mlLightboxSettings.override_enlarge_on_click===1);if(overrideEnabled&&!manualExcluded){var $enlargeOnClickGalleries=$('.wp-block-gallery').filter(function(){var $gallery=$(this);var $wpButtons=$gallery.find('button[data-wp-on-async--click="actions.showLightbox"]');return $wpButtons.length>1&&!$gallery.hasClass('ml-lightbox-enabled')&&!$gallery.hasClass('lg-initialized');});$enlargeOnClickGalleries.each(function(){initEnlargeOnClickGallery($(this),useButtonsForManual);});}
var linkOverrideEnabled=typeof mlLightboxSettings!=='undefined'&&(mlLightboxSettings.override_link_to_image_file===true||mlLightboxSettings.override_link_to_image_file==='1'||mlLightboxSettings.override_link_to_image_file===1);if(linkOverrideEnabled&&!manualExcluded){var $linkToMediaManualGalleries=$('.wp-block-gallery').filter(function(){var $gallery=$(this);var $mediaLinks=$gallery.find('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').filter(function(){return $(this).find('img').length>0;});return $mediaLinks.length>1&&!$gallery.hasClass('ml-lightbox-enabled')&&!$gallery.hasClass('lg-initialized')&&$gallery.find('.wp-lightbox-container').length===0&&$gallery.find('button[data-wp-on-async--click="actions.showLightbox"]').length===0;});$linkToMediaManualGalleries.each(function(){initLinkToMediaManualGallery($(this),useButtonsForManual);});}
if(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.enable_galleries&&!pageExcluded){var $linkToMediaGalleries=$('.wp-block-gallery').filter(function(){var $gallery=$(this);if($gallery.attr('data-ml-exclude-gallery')==='true'){return false;}
var $mediaLinks=$gallery.find('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').filter(function(){return $(this).find('img').length>0;});return $mediaLinks.length>1&&!$gallery.hasClass('ml-lightbox-enabled')&&!$gallery.hasClass('lg-initialized')&&$gallery.find('.wp-lightbox-container').length===0;});$linkToMediaGalleries.each(function(){initLinkToMediaGallery($(this),useButtonsForManual);});}
if(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.enable_galleries&&!pageExcluded){var $plainImageGalleries=$('.wp-block-gallery').filter(function(){var $gallery=$(this);if($gallery.attr('data-ml-exclude-gallery')==='true'){return false;}
var $images=$gallery.find('img');var $mediaLinks=$gallery.find('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]');var $wpLightboxImages=$gallery.find('img[data-wp-on-async--click="actions.showLightbox"]');return $images.length>1&&$mediaLinks.length===0&&$wpLightboxImages.length===0&&!$gallery.hasClass('ml-lightbox-enabled')&&!$gallery.hasClass('lg-initialized');});$plainImageGalleries.each(function(){initPlainImageGallery($(this),useButtonsForManual);});}
if(mlLightboxSettings.override_link_to_image_file&&!manualExcluded){var $mediaLinks=$('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').filter(function(){var $link=$(this);var $parentGallery=$link.closest('.wp-block-gallery');var $parentContainer=$link.closest('.wp-lightbox-container');return $link.find('img').length>0&&$parentGallery.length===0&&$parentContainer.length===0&&!$link.hasClass('lg-initialized')&&!$link.closest('.ml-lightbox-enabled').length;});$mediaLinks.each(function(){if(useButtonsForManual){initLinkToMediaFileWithButton($(this));}else{initLinkToMediaFile($(this));}});}
if(mlLightboxSettings.enable_on_content&&!pageExcluded){var contentImageSelectors=[];var containers=CONSTANTS.SELECTORS.CONTENT_CONTAINERS.split(', ');containers.forEach(function(container){contentImageSelectors.push(container+' img[src$=".jpg"]');contentImageSelectors.push(container+' img[src$=".jpeg"]');contentImageSelectors.push(container+' img[src$=".png"]');contentImageSelectors.push(container+' img[src$=".gif"]');contentImageSelectors.push(container+' img[src$=".webp"]');contentImageSelectors.push(container+' img[src$=".svg"]');});var $standaloneImages=$(contentImageSelectors.join(', ')).filter(function(){var $img=$(this);if($img.closest('.wp-block-gallery').length>0){return false;}
if($img.closest('.flex-control-nav, .flex-control-thumbs').length>0){return false;}
if($img.hasClass('ml-lightbox-enabled')||$img.closest('.ml-lightbox-wrapper').length>0||$img.closest('.ml-image-overlay').length>0||$img.siblings('.ml-lightbox-button').length>0||$img.parent().hasClass('lg-initialized')){return false;}
if($img.parent('a').length>0){return false;}
if($img.hasClass('wp-post-image')){return false;}
if($img.attr('data-wp-on-async--click')==='actions.showLightbox'){return false;}
if($img.attr('data-ml-exclude')==='true'){return false;}
var uiClasses=['custom-logo','site-logo','logo','avatar','icon','emoji','thumbnail','thumb'];for(var i=0;i<uiClasses.length;i++){if($img.hasClass(uiClasses[i])){return false;}}
var uiContainers=['.wp-block-site-logo','.site-logo','.site-branding','.site-header','.site-footer','.navigation','.nav','.menu','.widget','.sidebar'];for(var j=0;j<uiContainers.length;j++){if($img.closest(uiContainers[j]).length>0){return false;}}
var minWidth=mlLightboxSettings.minimum_image_width||200;var minHeight=mlLightboxSettings.minimum_image_height||200;var imgWidth=$img[0].naturalWidth||$img.width()||$img.attr('width')||0;var imgHeight=$img[0].naturalHeight||$img.height()||$img.attr('height')||0;if(minWidth>0&&imgWidth>0&&imgWidth<minWidth){return false;}
if(minHeight>0&&imgHeight>0&&imgHeight<minHeight){return false;}
return true;});$standaloneImages.each(function(){if(useButtonsForManual){handleSingleElementWithButton($(this));}else{handleSingleElement($(this));}});}}
function initLightboxEnabled($container,useButtonMode){useButtonMode=useButtonMode||false;if($container.hasClass('lg-initialized')||$container.data('lightgallery')){return;}
var $imageLinks=$container.find('a[data-src], a[data-video]');if($imageLinks.length===0){var $images=$container.find('img');if($images.length>1){$images.each(function(){var $img=$(this);var $figure=$img.closest('figure, div');if($figure.length===0)$figure=$img.parent();if($figure.find('.ml-image-overlay, .ml-lightbox-button').length>0||$figure.hasClass('lg-initialized')){return;}
var src=$img.attr('src');if(!src)return;var fullUrl=removeWordPressSizeSuffix(src);if(useButtonMode){var $button=$('<a href="#" class="ml-lightbox-button">'+getButtonText()+'</a>');$button.attr({'data-src':fullUrl,'data-thumb':src});$figure.css('position','relative').append($button);}else{var $overlay=$('<a href="#" class="ml-image-overlay"></a>');$overlay.attr({'data-src':fullUrl,'data-thumb':src});$figure.css('position','relative').prepend($overlay);}});var gallerySettings=getLightboxSettings(true);gallerySettings.selector=useButtonMode?'.ml-lightbox-button':'.ml-image-overlay';try{var instance=lightGallery($container[0],gallerySettings);$container.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing manual gallery:',error);}
return;}
if(useButtonMode){handleSingleElementWithButton($container);}else{handleSingleElement($container);}
return;}
var isGallery=$imageLinks.length>1;var settings=getLightboxSettings(isGallery);try{var instance=lightGallery($container[0],settings);$container.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing LightGallery:',error);}}
function handleSingleElement($element){var $target=null;var dataSrc='';var dataThumb='';var isVideo=false;if($element.is('img')){var src=$element.attr('src');if(!src)return;var $wrapper=$('<div class="ml-lightbox-wrapper"></div>');$element.wrap($wrapper);$target=$element.parent();var fullUrl=removeWordPressSizeSuffix(src);$target.attr({'data-src':fullUrl,'data-thumb':src});var caption=extractCaption($element);if(caption){$target.attr('data-sub-html',caption);}}else if($element.is('a')){var href=$element.attr('href');if(!href)return;$target=$element;var $img=$element.find('img').first();var imgSrc=$img.length?$img.attr('src'):href;isVideo=isVideoUrl(href);if(isVideo){var videoUrl=getVideoUrl(href);$target.attr({'data-src':videoUrl,'data-thumb':imgSrc||getVideoThumbnail(href)});}else{$target.attr({'data-src':href,'data-thumb':imgSrc});}
var caption=extractCaption($element);if(caption){$target.attr('data-sub-html',caption);}}else{var $iframe=$element.find('iframe[src*="youtube"], iframe[src*="vimeo"]').first();var $video=$element.find('video').first();if($iframe.length>0){var iframeSrc=$iframe.attr('src');var $overlay=$('<a href="#" class="ml-video-overlay"></a>');var videoUrl=getVideoUrl(iframeSrc);$overlay.attr({'data-src':videoUrl,'data-thumb':getVideoThumbnail(iframeSrc)});var caption=extractCaption($element);if(caption){$overlay.attr('data-sub-html',caption);}
$element.css('position','relative').prepend($overlay);$target=$element;isVideo=true;}else if($video.length>0){var videoSrc=$video.attr('src')||$video.find('source').first().attr('src');if(!videoSrc)return;var videoData={source:[{src:videoSrc,type:getVideoType(videoSrc)}],attributes:{preload:false,controls:true}};var $overlay=$('<a href="#" class="ml-video-overlay"></a>');$overlay.attr({'data-src':'','data-video':JSON.stringify(videoData),'data-thumb':$video.attr('poster')||'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZGRkIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxOCIgZmlsbD0iIzk5OSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPjQwMHgzMDA8L3RleHQ+PC9zdmc+'});var caption=extractCaption($element);if(caption){$overlay.attr('data-sub-html',caption);}
$element.css('position','relative').prepend($overlay);$target=$element;isVideo=true;}else{var $img=$element.find('img').first();if(!$img.length)return;var src=$img.attr('src');if(!src)return;var fullUrl=removeWordPressSizeSuffix(src);if($element.hasClass('wp-lightbox-container')){var $overlay=$('<a href="#" class="ml-image-overlay"></a>');$overlay.attr({'data-src':fullUrl,'data-thumb':src});var caption=extractCaption($element);if(caption){$overlay.attr('data-sub-html',caption);}
$element.css('position','relative').prepend($overlay);$target=$element;}else{$target=$element;$target.attr({'data-src':fullUrl,'data-thumb':src});var caption=extractCaption($element);if(caption){$target.attr('data-sub-html',caption);}}}}
if(!$target)return;var settings=getLightboxSettings(false);if(isVideo&&$target.find('.ml-video-overlay').length>0){settings.selector='.ml-video-overlay';}else if(!isVideo&&$target.find('.ml-image-overlay').length>0){settings.selector='.ml-image-overlay';}else{settings.selector='this';}
try{var instance=lightGallery($target[0],settings);$target.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing single lightbox:',error);}}
function handleSingleElementWithButton($element){if($element.hasClass('lg-initialized')||$element.data('lightgallery')){return;}
var $button=null;if($element.is('img')){var src=$element.attr('src');if(!src)return;var fullUrl=removeWordPressSizeSuffix(src);$button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':fullUrl,'data-thumb':src});var caption=extractCaption($element);if(caption){$button.attr('data-sub-html',caption);}
$element.wrap('<div style="position: relative; display: inline-block;"></div>');$element.parent().append($button);var settings=getLightboxSettings(false);settings.selector='.ml-lightbox-button';try{var instance=lightGallery($element.parent()[0],settings);$element.parent().addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing button mode for manual lightbox:',error);}}else if($element.is('a')){var href=$element.attr('href');if(!href)return;var $img=$element.find('img').first();var imgSrc=$img.length>0?$img.attr('src'):'';var isVideo=isVideoUrl(href);if(isVideo){var videoUrl=getVideoUrl(href);$button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':videoUrl,'data-thumb':imgSrc||getVideoThumbnail(href)});}else{$button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':href,'data-thumb':imgSrc});}
var caption=extractCaption($element);if(caption){$button.attr('data-sub-html',caption);}
$element.css('position','relative').append($button);var settings=getLightboxSettings(false);settings.selector='.ml-lightbox-button';try{var instance=lightGallery($element[0],settings);$element.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing button mode for manual lightbox:',error);}}else{var $existingButton=$element.find('.ml-lightbox-button').first();if($existingButton.length>0){var settings=getLightboxSettings(false);settings.selector='.ml-lightbox-button';try{var instance=lightGallery($element[0],settings);$element.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing existing button:',error);}
return;}
var $img=$element.find('img').first();var $iframe=$element.find('iframe[src*="youtube"], iframe[src*="vimeo"]').first();var $video=$element.find('video').first();if($img.length>0){var src=$img.attr('src');if(src){var fullUrl=removeWordPressSizeSuffix(src);$button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':fullUrl,'data-thumb':src});}}else if($iframe.length>0){var iframeSrc=$iframe.attr('src');if(iframeSrc){var videoUrl=getVideoUrl(iframeSrc);$button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':videoUrl,'data-thumb':getVideoThumbnail(iframeSrc)});}}else if($video.length>0){var videoSrc=$video.attr('src')||$video.find('source').first().attr('src');if(videoSrc){$button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');var videoData={source:[{src:videoSrc,type:getVideoType(videoSrc)}],attributes:{preload:false,controls:true}};$button.attr({'data-src':'','data-video':JSON.stringify(videoData),'data-thumb':$video.attr('poster')||'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZGRkIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxOCIgZmlsbD0iIzk5OSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPjQwMHgzMDA8L3RleHQ+PC9zdmc+'});}}
if($button){var caption=extractCaption($element);if(caption){$button.attr('data-sub-html',caption);}
$element.css('position','relative').append($button);var settings=getLightboxSettings(false);settings.selector='.ml-lightbox-button';try{var instance=lightGallery($element[0],settings);$element.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing button mode for manual lightbox:',error);}}}}
function getLightboxSettings(isGallery){var metasliderOptions=mlLightboxSettings.metaslider_options||{};var settings={selector:'a[data-src]',mode:'lg-fade',speed:350,download:false,counter:isGallery,closable:true,closeOnTap:true,controls:!!metasliderOptions.show_arrows,plugins:[]};if(!shouldShowCaptions()){settings.subHtml='';settings.getCaptionFromTitleOrAlt=false;}
if(isGallery&&metasliderOptions.show_thumbnails&&typeof lgThumbnail!=='undefined'){settings.plugins.push(lgThumbnail);settings.thumbWidth=100;settings.thumbHeight=80;settings.thumbMargin=4;settings.exThumbImage='data-thumb';}
if(typeof lgVideo!=='undefined'){settings.plugins.push(lgVideo);settings.videoMaxSize='1280-720';}
return settings;}
function removeWordPressSizeSuffix(url){if(!url)return'';return url.replace(/-\d+x\d+(\.[^.]+)$/,'$1');}
function isVideoUrl(url){if(!url)return false;return/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/|vimeo\.com\/(?:video\/)?|\.(?:mp4|webm|ogg|mov|avi)(?:\?|$))/i.test(url);}
function getVideoUrl(url){if(!url)return'';var youtubeMatch=url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/);if(youtubeMatch){return'https://www.youtube.com/watch?v='+youtubeMatch[1];}
var vimeoMatch=url.match(/vimeo\.com\/(?:video\/)?(\d+)/);if(vimeoMatch){return'https://vimeo.com/'+vimeoMatch[1];}
return url;}
function getVideoThumbnail(url){if(!url)return'';var youtubeMatch=url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/);if(youtubeMatch){return'https://img.youtube.com/vi/'+youtubeMatch[1]+'/maxresdefault.jpg';}
var vimeoMatch=url.match(/vimeo\.com\/(?:video\/)?(\d+)/);if(vimeoMatch){return'https://vumbnail.com/'+vimeoMatch[1]+'.jpg';}
return'';}
function initWordPressGallery($gallery){var $wpImagesOld=$gallery.find('.wp-lightbox-container img[data-wp-on-async--click="actions.showLightbox"]');var $wpContainersNew=$gallery.find('.wp-lightbox-container[data-wp-interactive="core/image"]');var $allContainers=$();$wpImagesOld.each(function(){$allContainers=$allContainers.add($(this).closest('.wp-lightbox-container'));});$allContainers=$allContainers.add($wpContainersNew);if($allContainers.length<=1)return;$allContainers.each(function(){var $figure=$(this);var $img=$figure.find('img').first();if($figure.find('.ml-image-overlay').length>0||$figure.hasClass('lg-initialized')){return;}
var src=$img.attr('src');if(!src)return;var fullUrl=removeWordPressSizeSuffix(src);var $overlay=$('<a href="#" class="ml-image-overlay"></a>');$overlay.attr({'data-src':fullUrl,'data-thumb':src});$figure.css('position','relative').prepend($overlay);});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='.ml-image-overlay';gallerySettings.galleryId='ml-gallery-'+Date.now()+'-'+Math.random().toString(36).substr(2,9);try{var instance=lightGallery($gallery[0],gallerySettings);$gallery.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing WordPress gallery:',error);}}
function initWordPressEnlargeOnClick($img){var $figure=$img.closest('.wp-lightbox-container');var src=$img.attr('src');if(!src)return;var fullUrl=removeWordPressSizeSuffix(src);var $overlay=$('<a href="#" class="ml-image-overlay"></a>');$overlay.attr({'data-src':fullUrl,'data-thumb':src});var caption=extractCaption($img);if(caption){$overlay.attr('data-sub-html',caption);}
var $wpButton=$figure.find('button[data-wp-on-async--click="actions.showLightbox"]');$wpButton.remove();$figure.css('position','relative').prepend($overlay);var settings=getLightboxSettings(false);settings.selector='.ml-image-overlay';try{var instance=lightGallery($figure[0],settings);$figure.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing Enlarge on Click overlay:',error);}}
function initWordPressEnlargeOnClickWithButton($img){var $figure=$img.closest('.wp-lightbox-container');var src=$img.attr('src');if(!src)return;var fullUrl=removeWordPressSizeSuffix(src);var $button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':fullUrl,'data-thumb':src});var caption=extractCaption($img);if(caption){$button.attr('data-sub-html',caption);}
var $wpButton=$figure.find('button[data-wp-on-async--click="actions.showLightbox"]');$wpButton.remove();$figure.css('position','relative').append($button);var settings=getLightboxSettings(false);settings.selector='.ml-lightbox-button';try{var instance=lightGallery($figure[0],settings);$figure.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing Enlarge on Click button:',error);}}
function initLinkToMediaGallery($gallery,useButtonMode){var $mediaLinks=$gallery.find('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').filter(function(){return $(this).find('img').length>0;});if($mediaLinks.length<=1)return;if(useButtonMode){$mediaLinks.each(function(){var $link=$(this);var href=$link.attr('href');var $img=$link.find('img').first();var imgSrc=$img.attr('src');if(!href||!imgSrc)return;var $button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':href,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$button.attr('data-sub-html',caption);}
$link.parent().append($button);});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='.ml-lightbox-button';}else{$mediaLinks.each(function(){var $link=$(this);var href=$link.attr('href');var $img=$link.find('img').first();var imgSrc=$img.attr('src');if(!href||!imgSrc)return;$link.attr({'data-src':href,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$link.attr('data-sub-html',caption);}});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='a[data-src]';}
try{var instance=lightGallery($gallery[0],gallerySettings);$gallery.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing "Link to Media File" gallery:',error);}}
function initPlainImageGallery($gallery,useButtonMode){var $images=$gallery.find('img');if($images.length<=1)return;if(useButtonMode){$images.each(function(){var $img=$(this);var imgSrc=$img.attr('src');if(!imgSrc)return;var fullUrl=removeWordPressSizeSuffix(imgSrc);var $figure=$img.closest('.wp-block-image');if($figure.length===0){$figure=$img.parent();}
$figure.attr({'data-src':fullUrl,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$figure.attr('data-sub-html',caption);}
var $button=$('<a href="#" class="ml-lightbox-button" data-src="'+fullUrl+'" data-thumb="'+imgSrc+'">'+getButtonText()+'</a>');if(caption){$button.attr('data-sub-html',caption);}
$figure.css('position','relative').append($button);});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='.ml-lightbox-button';}else{$images.each(function(){var $img=$(this);var imgSrc=$img.attr('src');if(!imgSrc)return;var fullUrl=removeWordPressSizeSuffix(imgSrc);var $wrapper=$('<a href="#" data-src="'+fullUrl+'" data-thumb="'+imgSrc+'"></a>');var caption=extractCaption($img);if(caption){$wrapper.attr('data-sub-html',caption);}
$img.wrap($wrapper);});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='a[data-src]';}
try{var instance=lightGallery($gallery[0],gallerySettings);$gallery.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing plain image gallery:',error);}}
function initLinkToMediaFile($link){var href=$link.attr('href');var $img=$link.find('img').first();var imgSrc=$img.attr('src');if(!href||!imgSrc)return;$link.attr({'data-src':href,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$link.attr('data-sub-html',caption);}
var settings=getLightboxSettings(false);settings.selector='this';try{var instance=lightGallery($link[0],settings);$link.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing "Link to Media File" image:',error);}}
function initLinkToMediaFileWithButton($link){var href=$link.attr('href');var $img=$link.find('img').first();var imgSrc=$img.attr('src');if(!href||!imgSrc)return;var $button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':href,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$button.attr('data-sub-html',caption);}
$link.css('position','relative').append($button);var settings=getLightboxSettings(false);settings.selector='.ml-lightbox-button';try{var instance=lightGallery($link[0],settings);$link.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing "Link to Media File" button:',error);}}
function initMetaSlider(){var $sliders=$('.metaslider, [class*="ml-slider-lightbox-"]');if($sliders.length===0){return;}
$sliders.each(function(){var $slider=$(this);if($slider.hasClass('lg-initialized')){return;}
var sliderId=$slider.attr('id');if(!sliderId){var $firstSlide=$slider.find('li').first();var slideClass=$firstSlide.attr('class');if(slideClass){var classMatch=slideClass.match(/slider-(\d+)/);if(classMatch){sliderId=classMatch[1];}}}
if(sliderId){var matches=sliderId.match(/(\d+)/);if(matches){sliderId=matches[1];}}
if(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.slider_settings&&sliderId){var sliderSettings=mlLightboxSettings.slider_settings[sliderId];if(sliderSettings&&sliderSettings.lightbox_enabled===false){return;}}
var showButton=true;if(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.metaslider_options){showButton=mlLightboxSettings.metaslider_options.show_lightbox_button!==false;}
if(showButton){initMetaSliderButtonMode($slider);}else{initMetaSliderDirectMode($slider);}});}
function initMetaSliderButtonMode($slider){var $slides=$slider.find('li').not('.clone');var buttonsAdded=0;$slides.each(function(){var $slide=$(this);var $button=null;if($slide.find('.ml-lightbox-button').length>0){return;}
if($slide.hasClass('ms-youtube')){$button=createYouTubeButton($slide);}
else if($slide.hasClass('ms-vimeo')){$button=createVimeoButton($slide);}
else if($slide.hasClass('ms-external-video')){$button=createExternalVideoButton($slide);}
else if($slide.hasClass('ms-local-video')){$button=createLocalVideoButton($slide);}
else if($slide.hasClass('ms-postfeed')){$button=createPostFeedButton($slide);}
else if($slide.hasClass('ms-layer')){$button=createLayerButton($slide);}
else if($slide.hasClass('ms-custom-html')){$button=createCustomHtmlButton($slide);}
else{$button=createImageButton($slide);}
if($button){$slide.css('position','relative').append($button);buttonsAdded++;}});if(buttonsAdded>0){var settings=getLightboxSettings(buttonsAdded>1);settings.selector='.ml-lightbox-button';try{lightGallery($slider[0],settings);$slider.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing button mode:',error);}}}
function initMetaSliderDirectMode($slider){var $slides=$slider.find('li').not('.clone');var linksAdded=0;$slides.each(function(){var $slide=$(this);if($slide.find('.ml-metaslider-link, .ml-video-overlay').length>0)return;var dataAttributes=null;if($slide.hasClass('ms-youtube')){dataAttributes=getYouTubeOverlayData($slide);}
else if($slide.hasClass('ms-vimeo')){dataAttributes=getVimeoOverlayData($slide);}
else if($slide.hasClass('ms-external-video')){dataAttributes=getExternalVideoOverlayData($slide);}
else if($slide.hasClass('ms-local-video')){dataAttributes=getLocalVideoOverlayData($slide);}
else if($slide.hasClass('ms-postfeed')){dataAttributes=getPostFeedOverlayData($slide);}
else if($slide.hasClass('ms-layer')){dataAttributes=getLayerOverlayData($slide);}
else if($slide.hasClass('ms-custom-html')){dataAttributes=getCustomHtmlOverlayData($slide);}
else{dataAttributes=getImageOverlayData($slide);}
if(dataAttributes){if(dataAttributes.overlay){var overlayClass='ml-video-overlay';if($slide.hasClass('ms-image')){overlayClass='ml-image-overlay';}
var $overlay=$('<a href="#" class="'+overlayClass+'"></a>');$overlay.attr(dataAttributes.attrs);$slide.css('position','relative').prepend($overlay);}else{var $link=$slide.find('a').first();if($link.length>0){$link.attr(dataAttributes.attrs).addClass('ml-metaslider-link');}}
linksAdded++;}});if(linksAdded>0){var settings=getLightboxSettings(linksAdded>1);settings.selector='.ml-metaslider-link, .ml-video-overlay, .ml-image-overlay';try{lightGallery($slider[0],settings);$slider.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing direct-click mode:',error);}}}
function isGalleryAlreadyProcessed($gallery){return $gallery.hasClass(CONSTANTS.CLASSES.ML_LIGHTBOX_ENABLED)||$gallery.hasClass(CONSTANTS.CLASSES.LG_INITIALIZED);}
function extractVideoId($slide,handler){var $element=$slide.find(handler.selector);if($element.length===0)return null;var id=$element.attr(handler.idAttr);if(!id&&handler.fallbackSelectors){for(var i=0;i<handler.fallbackSelectors.length;i++){var fallbackSelector=handler.fallbackSelectors[i];var $fallback=$slide.find(fallbackSelector);if(fallbackSelector.startsWith('a[href*=')){var url=$fallback.attr('href');if(url){var match=url.match(/vimeo\.com\/(\d+)/);if(match){id=match[1];break;}}}else{id=$fallback.attr(handler.idAttr);if(id)break;}}}
return id;}
function createVideoButton($slide,videoType){var handler=CONSTANTS.VIDEO_HANDLERS[videoType];if(!handler)return null;var videoData=null;if(videoType==='youtube'||videoType==='vimeo'){var videoId=extractVideoId($slide,handler);if(!videoId)return null;videoData={url:handler.urlTemplate(videoId),thumb:handler.thumbTemplate(videoId)};}else if(videoType==='externalVideo'||videoType==='localVideo'){var $element=$slide.find(handler.selector);if($element.length===0)return null;var dataSources=$element.attr(handler.sourcesAttr);var videoSources=[];var videoUrl=null;if(dataSources){try{var sources=JSON.parse(dataSources);if(sources&&sources.length>0){videoUrl=sources[0].src;videoSources=sources.map(function(source){return{'src':source.src,'type':source.type||getVideoType(source.src)};});}}catch(e){console.error('MetaSlider Lightbox: Error parsing video sources',e);return null;}}
if(!videoUrl||videoSources.length===0)return null;videoData={url:'',thumb:$element.attr(handler.posterAttr)||getPlaceholderThumb(),videoData:{'source':videoSources,'attributes':{'preload':false,'controls':true}}};}
if(!videoData)return null;var $button=$('<a class="'+CONSTANTS.CLASSES.ML_LIGHTBOX_BUTTON+'" href="#">'+getButtonText()+'</a>');if(videoData.videoData){$button.attr({'data-src':'','data-video':JSON.stringify(videoData.videoData),'data-thumb':videoData.thumb});}else{if(!videoData.url)return null;$button.attr({'data-src':videoData.url,'data-thumb':videoData.thumb});}
return $button;}
function createImageButton($slide){var $link=$slide.find('a').first();var $img=$slide.find('img').first();if($img.length===0)return null;var imgSrc=$img.attr('src');var linkHref=($link.length>0)?$link.attr('href'):null;if(!linkHref){linkHref=imgSrc;}
var $button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':linkHref,'data-thumb':imgSrc});return $button;}
function createYouTubeButton($slide){return createVideoButton($slide,'youtube');}
function createVimeoButton($slide){return createVideoButton($slide,'vimeo');}
function createExternalVideoButton($slide){return createVideoButton($slide,'externalVideo');}
function createLocalVideoButton($slide){return createVideoButton($slide,'localVideo');}
function getVideoType(url){if(url.includes('.mp4'))return'video/mp4';if(url.includes('.webm'))return'video/webm';if(url.includes('.ogg'))return'video/ogg';return'video/mp4';}
function getPlaceholderThumb(){return'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZGRkIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxOCIgZmlsbD0iIzk5OSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPjQwMHgzMDA8L3RleHQ+PC9zdmc+';}
function createPostFeedButton($slide){var $img=$slide.find('img').first();if($img.length===0)return null;var imgSrc=removeWordPressSizeSuffix($img.attr('src'));var $button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':imgSrc,'data-thumb':imgSrc});var caption=extractCaption($slide);if(caption){$button.attr('data-sub-html',caption);}
return $button;}
function getPostFeedOverlayData($slide){var $img=$slide.find('img').first();if($img.length===0)return null;var imgSrc=removeWordPressSizeSuffix($img.attr('src'));var attrs={'data-src':imgSrc,'data-thumb':imgSrc};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:false,attrs:attrs};}
function createLayerButton($slide){var slideContent=$slide.html();if(!slideContent||!slideContent.trim())return null;var scaledSlideContent=slideContent.replace(/<div class="layer"[^>]*style="([^"]*)"[^>]*>/g,function(match,styleAttr){var scaledStyle=styleAttr.replace(/(top|left|right|bottom):\s*(\d+(?:\.\d+)?)(px|%)/g,function(cssMatch,property,value,unit){var numValue=parseFloat(value);var scaledValue=Math.round(numValue*2);return property+': '+scaledValue+unit;});return match.replace(styleAttr,scaledStyle);});var $tempDiv=$('<div>').html(slideContent);var animationClasses=[];$tempDiv.find('[class*="animated"], [class*="animation_"], [data-animation]').each(function(){var $elem=$(this);var classes=$elem.attr('class')||'';var animationType=$elem.attr('data-animation')||'';if(classes){animationClasses=animationClasses.concat(classes.split(' ').filter(function(cls){return cls.match(/animated|fadeIn|pulse|bounce|slide|animation_/i);}));}
if(animationType){animationClasses.push(animationType);}});var uniqueAnimationClasses=animationClasses.filter(function(value,index,self){return self.indexOf(value)===index;}).join(' ');var scaleCSS=`
            .layer-slide-content {
                position: relative !important;
                display: inline-block !important;
            }
            .layer-slide-content .msDefaultImage {
                display: block !important;
                width: 1400px !important;
                height: 600px !important;
                max-width: 80% !important;
                margin: 0 auto !important;
                object-fit: cover !important;
            }
            .layer-slide-content .msHtmlOverlay {
                position: absolute !important;
                top: 0 !important;
                left: 50% !important;
                width: 80% !important;
                height: 100% !important;
                transform: translateX(-50%) !important;
            }
            .layer-slide-content .msHtmlOverlay .content {
                font-size: 1.8em !important;
                line-height: 1.2 !important;
            }
        `;var htmlContent='<div style="display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; box-sizing: border-box; background: #000;"><div class="layer-slide-content '+uniqueAnimationClasses+'" style="position: relative; display: inline-block; max-width: 100%; max-height: 100vh;">'+scaledSlideContent+'</div></div>';var dataUri='data:text/html;charset=utf-8,'+encodeURIComponent('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Layer Content</title><style>body{margin:0;padding:0;background:#000;} '+scaleCSS+'</style><link rel="stylesheet" href="'+window.location.origin+'/wp-content/plugins/metaslider/assets/animate/animate.css" type="text/css" /></head><body>'+htmlContent+'</body></html>');var $button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':dataUri,'data-thumb':getPlaceholderThumb(),'data-iframe':'true','data-width':'800','data-height':'600'});return $button;}
function getLayerOverlayData($slide){var slideContent=$slide.html();if(!slideContent||!slideContent.trim())return null;var scaledSlideContent=slideContent.replace(/<div class="layer"[^>]*style="([^"]*)"[^>]*>/g,function(match,styleAttr){var scaledStyle=styleAttr.replace(/(top|left|right|bottom):\s*(\d+(?:\.\d+)?)(px|%)/g,function(cssMatch,property,value,unit){var numValue=parseFloat(value);var scaledValue=Math.round(numValue*2);return property+': '+scaledValue+unit;});return match.replace(styleAttr,scaledStyle);});var $tempDiv=$('<div>').html(slideContent);var animationClasses=[];$tempDiv.find('[class*="animated"], [class*="animation_"], [data-animation]').each(function(){var $elem=$(this);var classes=$elem.attr('class')||'';var animationType=$elem.attr('data-animation')||'';if(classes){animationClasses=animationClasses.concat(classes.split(' ').filter(function(cls){return cls.match(/animated|fadeIn|pulse|bounce|slide|animation_/i);}));}
if(animationType){animationClasses.push(animationType);}});var uniqueAnimationClasses=animationClasses.filter(function(value,index,self){return self.indexOf(value)===index;}).join(' ');var scaleCSS=`
            .layer-slide-content {
                position: relative !important;
                display: inline-block !important;
            }
            .layer-slide-content .msDefaultImage {
                display: block !important;
                width: 1400px !important;
                height: 600px !important;
                max-width: 80% !important;
                margin: 0 auto !important;
                object-fit: cover !important;
            }
            .layer-slide-content .msHtmlOverlay {
                position: absolute !important;
                top: 0 !important;
                left: 50% !important;
                width: 80% !important;
                height: 100% !important;
                transform: translateX(-50%) !important;
            }
            .layer-slide-content .msHtmlOverlay .content {
                font-size: 1.8em !important;
                line-height: 1.2 !important;
            }
        `;var htmlContent='<div style="display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; box-sizing: border-box; background: #000;"><div class="layer-slide-content '+uniqueAnimationClasses+'" style="position: relative; display: inline-block; max-width: 100%; max-height: 100vh;">'+scaledSlideContent+'</div></div>';var dataUri='data:text/html;charset=utf-8,'+encodeURIComponent('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Layer Content</title><style>body{margin:0;padding:0;background:#000;} '+scaleCSS+'</style><link rel="stylesheet" href="'+window.location.origin+'/wp-content/plugins/metaslider/assets/animate/animate.css" type="text/css" /></head><body>'+htmlContent+'</body></html>');var attrs={'data-src':dataUri,'data-thumb':getPlaceholderThumb(),'data-iframe':'true','data-width':'800','data-height':'600'};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:true,attrs:attrs};}
function shouldShowCaptions(){if(typeof mlLightboxSettings!=='undefined'&&mlLightboxSettings.metaslider_options&&typeof mlLightboxSettings.metaslider_options.show_captions!=='undefined'){return mlLightboxSettings.metaslider_options.show_captions===true||mlLightboxSettings.metaslider_options.show_captions===1;}
return true;}
function extractCaption($element){if(!shouldShowCaptions()){return'';}
var caption='';var $img=$element.is('img')?$element:$element.find('img').first();var $figcaption=$element.closest('figure').find('figcaption');if($figcaption.length>0){caption=$figcaption.html();}
if(!caption){var $captionWrap=$element.find('.caption-wrap .caption');if($captionWrap.length===0){$captionWrap=$element.closest('li').find('.caption-wrap .caption');}
if($captionWrap.length===0){$captionWrap=$element.closest('.slide').find('.caption-wrap .caption');}
if($captionWrap.length>0){caption=$captionWrap.html();}}
if(!caption&&$img.length>0){caption=$img.attr('alt')||$img.attr('title')||'';}
if(!caption){caption=$element.attr('data-sub-html')||'';}
return caption.trim();}
function getImageOverlayData($slide){var $link=$slide.find('a').first();var $img=$slide.find('img').first();if($img.length===0)return null;var imgSrc=$img.attr('src');var linkHref=($link.length>0)?$link.attr('href'):null;if(!linkHref){linkHref=imgSrc;}
var needsOverlay=($link.length===0);var attrs={'data-src':linkHref,'data-thumb':imgSrc};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:needsOverlay,attrs:attrs};}
function getYouTubeOverlayData($slide){var $youtubeDiv=$slide.find('div.youtube[data-id]');if($youtubeDiv.length===0)return null;var youtubeId=$youtubeDiv.attr('data-id');if(!youtubeId)return null;var youtubeUrl='https://www.youtube.com/watch?v='+youtubeId;var thumbUrl='https://img.youtube.com/vi/'+youtubeId+'/maxresdefault.jpg';var attrs={'data-src':youtubeUrl,'data-thumb':thumbUrl};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:true,attrs:attrs};}
function getVimeoOverlayData($slide){var $vimeoDiv=$slide.find('div.vimeo[data-id]');if($vimeoDiv.length===0)return null;var vimeoId=$vimeoDiv.attr('data-id');if(!vimeoId){vimeoId=$vimeoDiv.attr('data-slide-id');}
if(!vimeoId){var $existingLink=$slide.find('a[href*="vimeo.com"]').first();if($existingLink.length>0){var vimeoUrl=$existingLink.attr('href');var vimeoMatch=vimeoUrl.match(/vimeo\.com\/(\d+)/);if(vimeoMatch){vimeoId=vimeoMatch[1];}}}
if(!vimeoId)return null;var vimeoUrl='https://vimeo.com/'+vimeoId;var vimeoPoster='https://vumbnail.com/'+vimeoId+'.jpg';var attrs={'data-src':vimeoUrl,'data-thumb':vimeoPoster};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:true,attrs:attrs};}
function getExternalVideoOverlayData($slide){var $videoDiv=$slide.find('div.external-video');if($videoDiv.length===0)return null;var dataSources=$videoDiv.attr('data-sources');var videoSources=[];var videoUrl=null;if(dataSources){try{var sources=JSON.parse(dataSources);if(sources&&sources.length>0){videoUrl=sources[0].src;videoSources=sources.map(function(source){return{'src':source.src,'type':source.type||getVideoType(source.src)};});}}catch(e){console.error('MetaSlider Lightbox: Error parsing video sources',e);return null;}}
if(!videoUrl||videoSources.length===0)return null;var posterUrl=$videoDiv.attr('data-poster')||getPlaceholderThumb();var videoData={'source':videoSources,'attributes':{'preload':false,'controls':true}};var attrs={'data-src':'','data-video':JSON.stringify(videoData),'data-thumb':posterUrl};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:true,attrs:attrs};}
function getLocalVideoOverlayData($slide){var $videoDiv=$slide.find('div.local-video');if($videoDiv.length===0)return null;var dataSources=$videoDiv.attr('data-sources');var videoSources=[];var videoUrl=null;if(dataSources){try{var sources=JSON.parse(dataSources);if(sources&&sources.length>0){videoUrl=sources[0].src;videoSources=sources.map(function(source){return{'src':source.src,'type':source.type||getVideoType(source.src)};});}}catch(e){console.error('MetaSlider Lightbox: Error parsing video sources',e);return null;}}
if(!videoUrl||videoSources.length===0)return null;var posterUrl=$videoDiv.attr('data-poster')||getPlaceholderThumb();var videoData={'source':videoSources,'attributes':{'preload':false,'controls':true}};var attrs={'data-src':'','data-video':JSON.stringify(videoData),'data-thumb':posterUrl};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:true,attrs:attrs};}
function createCustomHtmlButton($slide){var slideContent=$slide.html();if(!slideContent||!slideContent.trim())return null;var responsiveCSS=`
            .custom-html-content {
                width: 100% !important;
                max-width: 100% !important;
                height: 100vh !important;
                display: flex !important;
                align-items: center !important;
                justify-content: center !important;
                padding: 20px !important;
                box-sizing: border-box !important;
                background: #000 !important;
                color: white !important;
                font-family: Arial, sans-serif !important;
                overflow: auto !important;
            }
            .custom-html-content > div {
                max-width: 100% !important;
                max-height: 100% !important;
            }
            @media (max-width: 768px) {
                .custom-html-content {
                    padding: 10px !important;
                }
            }
        `;var htmlContent='<div class="custom-html-content">'+slideContent+'</div>';var dataUri='data:text/html;charset=utf-8,'+encodeURIComponent('<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Custom HTML</title><style>body{margin:0;padding:0;} '+responsiveCSS+'</style></head><body>'+htmlContent+'</body></html>');var $button=$('<a class="ml-lightbox-button" href="#">'+getButtonText()+'</a>');$button.attr({'data-src':dataUri,'data-thumb':getPlaceholderThumb(),'data-iframe':'true','data-width':'90%','data-height':'90%'});return $button;}
function getCustomHtmlOverlayData($slide){var slideContent=$slide.html();if(!slideContent||!slideContent.trim())return null;var responsiveCSS=`
            .custom-html-content {
                width: 100% !important;
                max-width: 100% !important;
                height: 100vh !important;
                display: flex !important;
                align-items: center !important;
                justify-content: center !important;
                padding: 20px !important;
                box-sizing: border-box !important;
                background: #000 !important;
                color: white !important;
                font-family: Arial, sans-serif !important;
                overflow: auto !important;
            }
            .custom-html-content > div {
                max-width: 100% !important;
                max-height: 100% !important;
            }
            @media (max-width: 768px) {
                .custom-html-content {
                    padding: 10px !important;
                }
            }
        `;var htmlContent='<div class="custom-html-content">'+slideContent+'</div>';var dataUri='data:text/html;charset=utf-8,'+encodeURIComponent('<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Custom HTML</title><style>body{margin:0;padding:0;} '+responsiveCSS+'</style></head><body>'+htmlContent+'</body></html>');var attrs={'data-src':dataUri,'data-thumb':getPlaceholderThumb(),'data-iframe':'true','data-width':'90%','data-height':'90%'};var caption=extractCaption($slide);if(caption){attrs['data-sub-html']=caption;}
return{overlay:true,attrs:attrs};}
function initEnlargeOnClickGallery($gallery,useButtonMode){var $wpContainers=$gallery.find('.wp-lightbox-container').has('button[data-wp-on-async--click="actions.showLightbox"]');if($wpContainers.length<=1)return;if(useButtonMode){$wpContainers.each(function(){var $container=$(this);var $img=$container.find('img').first();var $wpButton=$container.find('button[data-wp-on-async--click="actions.showLightbox"]');if($img.length&&$wpButton.length){var imgSrc=$img.attr('src');if(!imgSrc)return;var fullUrl=removeWordPressSizeSuffix(imgSrc);$container.attr({'data-src':fullUrl,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$container.attr('data-sub-html',caption);}
var $button=$('<a href="#" class="ml-lightbox-button" data-src="'+fullUrl+'" data-thumb="'+imgSrc+'">'+getButtonText()+'</a>');if(caption){$button.attr('data-sub-html',caption);}
$wpButton.remove();$container.css('position','relative').append($button);}});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='.ml-lightbox-button';}else{$wpContainers.each(function(){var $container=$(this);var $img=$container.find('img').first();var $wpButton=$container.find('button[data-wp-on-async--click="actions.showLightbox"]');if($img.length&&$wpButton.length){var imgSrc=$img.attr('src');if(!imgSrc)return;var fullUrl=removeWordPressSizeSuffix(imgSrc);var $wrapper=$('<a href="#" data-src="'+fullUrl+'" data-thumb="'+imgSrc+'"></a>');var caption=extractCaption($img);if(caption){$wrapper.attr('data-sub-html',caption);}
$img.wrap($wrapper);$wpButton.remove();}});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='a[data-src]';}
try{var instance=lightGallery($gallery[0],gallerySettings);$gallery.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing Enlarge on Click gallery:',error);}}
function initLinkToMediaManualGallery($gallery,useButtonMode){var $mediaLinks=$gallery.find('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').filter(function(){return $(this).find('img').length>0;});if($mediaLinks.length<=1)return;if(useButtonMode){$mediaLinks.each(function(){var $link=$(this);var href=$link.attr('href');var $img=$link.find('img').first();var imgSrc=$img.attr('src');if(!href||!imgSrc)return;var $container=$link.closest('.wp-block-image');if($container.length===0){$container=$link.parent();}
$container.attr({'data-src':href,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$container.attr('data-sub-html',caption);}
var $button=$('<a href="#" class="ml-lightbox-button" data-src="'+href+'" data-thumb="'+imgSrc+'">'+getButtonText()+'</a>');if(caption){$button.attr('data-sub-html',caption);}
$container.css('position','relative').append($button);});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='.ml-lightbox-button';}else{$mediaLinks.each(function(){var $link=$(this);var href=$link.attr('href');var $img=$link.find('img').first();var imgSrc=$img.attr('src');if(!href||!imgSrc)return;$link.attr({'data-src':href,'data-thumb':imgSrc});var caption=extractCaption($img);if(caption){$link.attr('data-sub-html',caption);}});var gallerySettings=getLightboxSettings(true);gallerySettings.selector='a[data-src]';}
try{var instance=lightGallery($gallery[0],gallerySettings);$gallery.addClass('lg-initialized');}catch(error){console.error('MetaSlider Lightbox: Error initializing Link to Media File manual gallery:',error);}}})(jQuery);