(function($){"use strict";var autoplay,bgcolor,blocknum,blocktitle,border,core,container,content,dest,extraCss,framewidth,frameheight,gallItems,infinigall,items,keyNavigationDisabled,margine,numeratio,overlayColor,overlay,title,thisgall,thenext,theprev,nextok,prevok,preloader,$preloader,navigation,obj,gallIndex,startouch,vbheader,images,startY,startX,endY,endX,diff,diffX,diffY,threshold;$.fn.extend({venobox:function(options){var plugin=this;var defaults={arrowsColor:'#B6B6B6',autoplay:!1,bgcolor:'#fff',border:'0',closeBackground:'#161617',closeColor:"#d2d2d2",framewidth:'',frameheight:'',gallItems:!1,infinigall:!1,htmlClose:'&times;',htmlNext:'<span>Next</span>',htmlPrev:'<span>Prev</span>',numeratio:!1,numerationBackground:'#161617',numerationColor:'#d2d2d2',numerationPosition:'top',overlayClose:!0,overlayColor:'rgba(23,23,23,0.85)',spinner:'double-bounce',spinColor:'#d2d2d2',titleattr:'title',titleBackground:'#161617',titleColor:'#d2d2d2',titlePosition:'top',cb_pre_open:function(){return!0},cb_post_open:function(){},cb_pre_close:function(){return!0},cb_post_close:function(){},cb_post_resize:function(){},cb_after_nav:function(){},cb_init:function(){}};var option=$.extend(defaults,options);option.cb_init(plugin);return this.each(function(){obj=$(this);if(obj.data('venobox')){return!0}
plugin.VBclose=function(){closeVbox()};obj.addClass('vbox-item');obj.data('framewidth',option.framewidth);obj.data('frameheight',option.frameheight);obj.data('border',option.border);obj.data('bgcolor',option.bgcolor);obj.data('numeratio',option.numeratio);obj.data('gallItems',option.gallItems);obj.data('infinigall',option.infinigall);obj.data('overlaycolor',option.overlayColor);obj.data('titleattr',option.titleattr);obj.data('venobox',!0);obj.on('click',function(e){e.preventDefault();obj=$(this);var cb_pre_open=option.cb_pre_open(obj);if(cb_pre_open===!1){return!1}
plugin.VBnext=function(){navigateGall(thenext)};plugin.VBprev=function(){navigateGall(theprev)};overlayColor=obj.data('overlay')||obj.data('overlaycolor');framewidth=obj.data('framewidth');frameheight=obj.data('frameheight');autoplay=obj.data('autoplay')||option.autoplay;border=obj.data('border');bgcolor=obj.data('bgcolor');nextok=!1;prevok=!1;keyNavigationDisabled=!1;dest=obj.data('href')||obj.attr('href');extraCss=obj.data('css')||'';title=obj.attr(obj.data('titleattr'))||'';preloader='<div class="vbox-preloader">';switch(option.spinner){case 'rotating-plane':preloader+='<div class="sk-rotating-plane"></div>';break;case 'double-bounce':preloader+='<div class="sk-double-bounce">'+'<div class="sk-child sk-double-bounce1"></div>'+'<div class="sk-child sk-double-bounce2"></div>'+'</div>';break;case 'wave':preloader+='<div class="sk-wave">'+'<div class="sk-rect sk-rect1"></div>'+'<div class="sk-rect sk-rect2"></div>'+'<div class="sk-rect sk-rect3"></div>'+'<div class="sk-rect sk-rect4"></div>'+'<div class="sk-rect sk-rect5"></div>'+'</div>';break;case 'wandering-cubes':preloader+='<div class="sk-wandering-cubes">'+'<div class="sk-cube sk-cube1"></div>'+'<div class="sk-cube sk-cube2"></div>'+'</div>';break;case 'spinner-pulse':preloader+='<div class="sk-spinner sk-spinner-pulse"></div>';break;case 'chasing-dots':preloader+='<div class="sk-chasing-dots">'+'<div class="sk-child sk-dot1"></div>'+'<div class="sk-child sk-dot2"></div>'+'</div>';break;case 'three-bounce':preloader+='<div class="sk-three-bounce">'+'<div class="sk-child sk-bounce1"></div>'+'<div class="sk-child sk-bounce2"></div>'+'<div class="sk-child sk-bounce3"></div>'+'</div>';break;case 'circle':preloader+='<div class="sk-circle">'+'<div class="sk-circle1 sk-child"></div>'+'<div class="sk-circle2 sk-child"></div>'+'<div class="sk-circle3 sk-child"></div>'+'<div class="sk-circle4 sk-child"></div>'+'<div class="sk-circle5 sk-child"></div>'+'<div class="sk-circle6 sk-child"></div>'+'<div class="sk-circle7 sk-child"></div>'+'<div class="sk-circle8 sk-child"></div>'+'<div class="sk-circle9 sk-child"></div>'+'<div class="sk-circle10 sk-child"></div>'+'<div class="sk-circle11 sk-child"></div>'+'<div class="sk-circle12 sk-child"></div>'+'</div>';break;case 'cube-grid':preloader+='<div class="sk-cube-grid">'+'<div class="sk-cube sk-cube1"></div>'+'<div class="sk-cube sk-cube2"></div>'+'<div class="sk-cube sk-cube3"></div>'+'<div class="sk-cube sk-cube4"></div>'+'<div class="sk-cube sk-cube5"></div>'+'<div class="sk-cube sk-cube6"></div>'+'<div class="sk-cube sk-cube7"></div>'+'<div class="sk-cube sk-cube8"></div>'+'<div class="sk-cube sk-cube9"></div>'+'</div>';break;case 'fading-circle':preloader+='<div class="sk-fading-circle">'+'<div class="sk-circle1 sk-circle"></div>'+'<div class="sk-circle2 sk-circle"></div>'+'<div class="sk-circle3 sk-circle"></div>'+'<div class="sk-circle4 sk-circle"></div>'+'<div class="sk-circle5 sk-circle"></div>'+'<div class="sk-circle6 sk-circle"></div>'+'<div class="sk-circle7 sk-circle"></div>'+'<div class="sk-circle8 sk-circle"></div>'+'<div class="sk-circle9 sk-circle"></div>'+'<div class="sk-circle10 sk-circle"></div>'+'<div class="sk-circle11 sk-circle"></div>'+'<div class="sk-circle12 sk-circle"></div>'+'</div>';break;case 'folding-cube':preloader+='<div class="sk-folding-cube">'+'<div class="sk-cube1 sk-cube"></div>'+'<div class="sk-cube2 sk-cube"></div>'+'<div class="sk-cube4 sk-cube"></div>'+'<div class="sk-cube3 sk-cube"></div>'+'</div>';break}
preloader+='</div>';navigation='<a class="vbox-next">'+option.htmlNext+'</a><a class="vbox-prev">'+option.htmlPrev+'</a>';vbheader='<div class="vbox-title"></div><div class="vbox-num">0/0</div><div class="vbox-close">'+option.htmlClose+'</div>';core='<div class="vbox-overlay '+extraCss+'" style="background:'+overlayColor+'">'+preloader+'<div class="vbox-container"><div class="vbox-content"></div></div>'+vbheader+navigation+'</div>';$('body').append(core).addClass('vbox-open');$('.vbox-preloader div:not(.sk-circle) .sk-child, .vbox-preloader .sk-rotating-plane, .vbox-preloader .sk-rect, .vbox-preloader div:not(.sk-folding-cube) .sk-cube, .vbox-preloader .sk-spinner-pulse').css('background-color',option.spinColor);overlay=$('.vbox-overlay');container=$('.vbox-container');content=$('.vbox-content');blocknum=$('.vbox-num');blocktitle=$('.vbox-title');$preloader=$('.vbox-preloader');$preloader.show();blocktitle.css(option.titlePosition,'-1px');blocktitle.css({'color':option.titleColor,'background-color':option.titleBackground});$('.vbox-close').css({'color':option.closeColor,'background-color':option.closeBackground});$('.vbox-num').css(option.numerationPosition,'-1px');$('.vbox-num').css({'color':option.numerationColor,'background-color':option.numerationBackground});$('.vbox-next span, .vbox-prev span').css({'border-top-color':option.arrowsColor,'border-right-color':option.arrowsColor});content.html('');content.css('opacity','0');overlay.css('opacity','0');checknav();overlay.animate({opacity:1},250,function(){if(obj.data('vbtype')=='iframe'){loadIframe()}else if(obj.data('vbtype')=='inline'){loadInline()}else if(obj.data('vbtype')=='ajax'){loadAjax()}else if(obj.data('vbtype')=='video'){loadVid(autoplay)}else{content.html('<img src="'+dest+'">');preloadFirst()}
option.cb_post_open(obj,gallIndex,thenext,theprev)});$('body').keydown(keyboardHandler);$('.vbox-prev').on('click',function(){navigateGall(theprev)});$('.vbox-next').on('click',function(){navigateGall(thenext)});return!1});function checknav(){thisgall=obj.data('gall');numeratio=obj.data('numeratio');gallItems=obj.data('gallItems');infinigall=obj.data('infinigall');if(gallItems){items=gallItems}else{items=$('.vbox-item[data-gall="'+thisgall+'"]')}
thenext=items.eq(items.index(obj)+1);theprev=items.eq(items.index(obj)-1);if(!thenext.length&&infinigall===!0){thenext=items.eq(0)}
if(items.length>1){gallIndex=items.index(obj)+1;blocknum.html(gallIndex+' / '+items.length)}else{gallIndex=1}
if(numeratio===!0){blocknum.show()}else{blocknum.hide()}
if(title!==''){blocktitle.show()}else{blocktitle.hide()}
if(!thenext.length&&infinigall!==!0){$('.vbox-next').css('display','none');nextok=!1}else{$('.vbox-next').css('display','block');nextok=!0}
if(items.index(obj)>0||infinigall===!0){$('.vbox-prev').css('display','block');prevok=!0}else{$('.vbox-prev').css('display','none');prevok=!1}
if(prevok===!0||nextok===!0){content.on(TouchMouseEvent.DOWN,onDownEvent);content.on(TouchMouseEvent.MOVE,onMoveEvent);content.on(TouchMouseEvent.UP,onUpEvent)}}
function navigateGall(destination){if(destination.length<1){return!1}
if(keyNavigationDisabled){return!1}
keyNavigationDisabled=!0;overlayColor=destination.data('overlay')||destination.data('overlaycolor');framewidth=destination.data('framewidth');frameheight=destination.data('frameheight');border=destination.data('border');bgcolor=destination.data('bgcolor');dest=destination.data('href')||destination.attr('href');autoplay=destination.data('autoplay');title=destination.attr(destination.data('titleattr'))||'';if(destination===theprev){content.addClass('animated').addClass('swipe-right')}
if(destination===thenext){content.addClass('animated').addClass('swipe-left')}
$preloader.show();content.animate({opacity:0,},500,function(){overlay.css('background',overlayColor);content.removeClass('animated').removeClass('swipe-left').removeClass('swipe-right').css({'margin-left':0,'margin-right':0});if(destination.data('vbtype')=='iframe'){loadIframe()}else if(destination.data('vbtype')=='inline'){loadInline()}else if(destination.data('vbtype')=='ajax'){loadAjax()}else if(destination.data('vbtype')=='video'){loadVid(autoplay)}else{content.html('<img src="'+dest+'">');preloadFirst()}
obj=destination;checknav();keyNavigationDisabled=!1;option.cb_after_nav(obj,gallIndex,thenext,theprev)})}
function keyboardHandler(e){if(e.keyCode===27){closeVbox()}
if(e.keyCode==37&&prevok===!0){navigateGall(theprev)}
if(e.keyCode==39&&nextok===!0){navigateGall(thenext)}}
function closeVbox(){var cb_pre_close=option.cb_pre_close(obj,gallIndex,thenext,theprev);if(cb_pre_close===!1){return!1}
$('body').off('keydown',keyboardHandler).removeClass('vbox-open');obj.focus();overlay.animate({opacity:0},500,function(){overlay.remove();keyNavigationDisabled=!1;option.cb_post_close()})}
var closeclickclass='.vbox-overlay';if(!option.overlayClose){closeclickclass='.vbox-close'}
$('body').on('click',closeclickclass,function(e){if($(e.target).is('.vbox-overlay')||$(e.target).is('.vbox-content')||$(e.target).is('.vbox-close')||$(e.target).is('.vbox-preloader')){closeVbox()}});startX=0;endX=0;diff=0;threshold=50;startouch=!1;function onDownEvent(e){content.addClass('animated');startY=endY=e.pageY;startX=endX=e.pageX;startouch=!0}
function onMoveEvent(e){if(startouch===!0){endX=e.pageX;endY=e.pageY;diffX=endX-startX;diffY=endY-startY;var absdiffX=Math.abs(diffX);var absdiffY=Math.abs(diffY);if((absdiffX>absdiffY)&&(absdiffX<=100)){e.preventDefault();content.css('margin-left',diffX)}}}
function onUpEvent(e){if(startouch===!0){startouch=!1;var subject=obj;var change=!1;diff=endX-startX;if(diff<0&&nextok===!0){subject=thenext;change=!0}
if(diff>0&&prevok===!0){subject=theprev;change=!0}
if(Math.abs(diff)>=threshold&&change===!0){navigateGall(subject)}else{content.css({'margin-left':0,'margin-right':0})}}}
var TouchMouseEvent={DOWN:"touchmousedown",UP:"touchmouseup",MOVE:"touchmousemove"};var onMouseEvent=function(event){var type;switch(event.type){case "mousedown":type=TouchMouseEvent.DOWN;break;case "mouseup":type=TouchMouseEvent.UP;break;case "mouseout":type=TouchMouseEvent.UP;break;case "mousemove":type=TouchMouseEvent.MOVE;break;default:return}
var touchMouseEvent=normalizeEvent(type,event,event.pageX,event.pageY);$(event.target).trigger(touchMouseEvent)};var onTouchEvent=function(event){var type;switch(event.type){case "touchstart":type=TouchMouseEvent.DOWN;break;case "touchend":type=TouchMouseEvent.UP;break;case "touchmove":type=TouchMouseEvent.MOVE;break;default:return}
var touch=event.originalEvent.touches[0];var touchMouseEvent;if(type==TouchMouseEvent.UP){touchMouseEvent=normalizeEvent(type,event,null,null)}else{touchMouseEvent=normalizeEvent(type,event,touch.pageX,touch.pageY)}
$(event.target).trigger(touchMouseEvent)};var normalizeEvent=function(type,original,x,y){return $.Event(type,{pageX:x,pageY:y,originalEvent:original})};if("ontouchstart" in window){$(document).on("touchstart",onTouchEvent);$(document).on("touchmove",onTouchEvent);$(document).on("touchend",onTouchEvent)}else{$(document).on("mousedown",onMouseEvent);$(document).on("mouseup",onMouseEvent);$(document).on("mouseout",onMouseEvent);$(document).on("mousemove",onMouseEvent)}
function loadAjax(){$.ajax({url:dest,cache:!1}).done(function(msg){content.html('<div class="vbox-inline">'+msg+'</div>');preloadFirst()}).fail(function(){content.html('<div class="vbox-inline"><p>Error retrieving contents, please retry</div>');updateoverlay()})}
function loadIframe(){content.html('<iframe class="venoframe" src="'+dest+'"></iframe>');updateoverlay()}
function loadVid(autoplay){var player;var videoObj=parseVideo(dest);var stringAutoplay=autoplay?"?rel=0&autoplay=1":"?rel=0";var queryvars=stringAutoplay+getUrlParameter(dest);if(videoObj.type=='vimeo'){player='https://player.vimeo.com/video/'}else if(videoObj.type=='youtube'){player='https://www.youtube.com/embed/'}
content.html('<iframe class="venoframe vbvid" webkitallowfullscreen mozallowfullscreen allowfullscreen frameborder="0" src="'+player+videoObj.id+queryvars+'"></iframe>');updateoverlay()}
function parseVideo(url){url.match(/(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?/);var type;if(RegExp.$3.indexOf('youtu')>-1){type='youtube'}else if(RegExp.$3.indexOf('vimeo')>-1){type='vimeo'}
return{type:type,id:RegExp.$6}}
function getUrlParameter(name){var result='';var sPageURL=decodeURIComponent(name);var firstsplit=sPageURL.split('?');if(firstsplit[1]!==undefined){var sURLVariables=firstsplit[1].split('&');var sParameterName;var i;for(i=0;i<sURLVariables.length;i++){sParameterName=sURLVariables[i].split('=');result=result+'&'+sParameterName[0]+'='+sParameterName[1]}}
return encodeURI(result)}
function loadInline(){content.html('<div class="vbox-inline">'+$(dest).html()+'</div>');updateoverlay()}
function preloadFirst(){images=content.find('img');if(images.length){images.each(function(){$(this).one('load',function(){updateoverlay()})})}else{updateoverlay()}}
function updateoverlay(){blocktitle.html(title);content.find(">:first-child").addClass('figlio').css({'width':framewidth,'height':frameheight,'padding':border,'background':bgcolor});$('img.figlio').on('dragstart',function(event){event.preventDefault()});updateOL();content.animate({'opacity':'1'},'slow',function(){$preloader.hide()})}
function updateOL(){var sonH=content.outerHeight();var finH=$(window).height();if(sonH+60<finH){margine=(finH-sonH)/2}else{margine='30px'}
content.css('margin-top',margine);content.css('margin-bottom',margine);option.cb_post_resize()}
$(window).resize(function(){if($('.vbox-content').length){setTimeout(updateOL(),800)}})})}})})(jQuery)