﻿(function($){$.fn.visualLightbox=function(options){var activeImage=null,badObjects=["select","object","embed"],groupName=null,imageArray=[],slideShowTimer=null,startImage=null,descriptionHeight=50,imgPreloader,showTimer;if(!document.getElementsByTagName)return;options=$.extend({animate:true,autoPlay:true,borderSize:39,containerID:document,enableSlideshow:true,googleAnalytics:false,imageDataLocation:"south",closeLocation:"",initImage:"",loop:true,overlayDuration:.2,overlayOpacity:.7,prefix:"",classNames:"vlightbox",resizeSpeed:7,showGroupName:false,slideTime:4,strings:{closeLink:"",loadingMsg:"loading",nextLink:"",prevLink:"",startSlideshow:"",stopSlideshow:"",numDisplayPrefix:"",numDisplaySeparator:"/"},featBrowser:true,breathingSize:20,startZoom:false,floating:true},options);if(options.animate){var overlayDuration=Math.max(options.overlayDuration,0);options.resizeSpeed=Math.max(Math.min(options.resizeSpeed,10),1);var resizeDuration=(11-options.resizeSpeed)*.15}else var overlayDuration=0,resizeDuration=0;var enableSlideshow=options.enableSlideshow;options.overlayOpacity=Math.max(Math.min(options.overlayOpacity,1),0);var playSlides=options.autoPlay,container=$(options.containerID),classNames=options.classNames;updateImageList();var objBody=container.length&&container.get(0)!=document?container.get(0):document.getElementsByTagName("body").item(0);if(objBody.childNodes.length){$(objBody.childNodes[0]).before($("<div></div>"));objBody=objBody.childNodes[0]}var objOverlay=document.createElement("div");objOverlay.setAttribute("id",getID("overlay"));objOverlay.style.display="none";objBody.appendChild(objOverlay);$(objOverlay).click(end);var objLightbox=document.createElement("div");objLightbox.setAttribute("id",getID("lightbox"));objLightbox.style.display="none";objBody.appendChild(objLightbox);$(objLightbox).click(end);var objImageDataContainer=document.createElement("div");objImageDataContainer.setAttribute("id",getID("imageDataContainer"));objImageDataContainer.className=getID("clearfix");var objImageData=document.createElement("div");objImageData.setAttribute("id",getID("imageData"));objImageDataContainer.appendChild(objImageData);var objImageDetails=document.createElement("div");objImageDetails.setAttribute("id",getID("imageDetails"));objImageData.appendChild(objImageDetails);var objCaption=document.createElement("div");objCaption.setAttribute("id",getID("caption"));objImageDetails.appendChild(objCaption);var objNumberDisplay=document.createElement("span");objNumberDisplay.setAttribute("id",getID("numberDisplay"));objImageDetails.appendChild(objNumberDisplay);var objDetailsNav=document.createElement("span");objDetailsNav.setAttribute("id",getID("detailsNav"));objImageDetails.appendChild(objDetailsNav);var objPrevLink=document.createElement("a");objPrevLink.setAttribute("id",getID("prevLinkDetails"));objPrevLink.setAttribute("href","javascript:void(0);");objPrevLink.innerHTML=options.strings.prevLink;objDetailsNav.appendChild(objPrevLink);$(objPrevLink).click(showPrev);var objSlideShowControl=document.createElement("a");objSlideShowControl.setAttribute("id",getID("slideShowControl"));objSlideShowControl.setAttribute("href","javascript:void(0);");objDetailsNav.appendChild(objSlideShowControl);$(objSlideShowControl).click(toggleSlideShow);var objNextLink=document.createElement("a");objNextLink.setAttribute("id",getID("nextLinkDetails"));objNextLink.setAttribute("href","javascript:void(0);");objNextLink.innerHTML=options.strings.nextLink;objDetailsNav.appendChild(objNextLink);$(objNextLink).click(showNext);var objOuterImageContainer=document.createElement("table");objOuterImageContainer.setAttribute("id",getID("outerImageContainer"));objOuterImageContainer.cellSpacing=0;objLightbox.appendChild(objOuterImageContainer);var objOICTop=objOuterImageContainer.insertRow(-1),objOICTL=objOICTop.insertCell(-1);objOICTL.className="tl";var objOICTC=objOICTop.insertCell(-1);objOICTC.className="tc";var objOICTR=objOICTop.insertCell(-1);objOICTR.className="tr";var objOICMiddle=objOuterImageContainer.insertRow(-1),objOICML=objOICMiddle.insertCell(-1);objOICML.className="ml";var objLightboxFrameBody=objOICMiddle.insertCell(-1);objLightboxFrameBody.setAttribute("id",getID("lightboxFrameBody"));objLightboxFrameBody.innerHTML="&nbsp;";var objOICMR=objOICMiddle.insertCell(-1);objOICMR.className="mr";var objOICBottom=objOuterImageContainer.insertRow(-1),objOICBL=objOICBottom.insertCell(-1);objOICBL.className="bl";var objOICBC=objOICBottom.insertCell(-1);objOICBC.className="bc";var objOICBR=objOICBottom.insertCell(-1);objOICBR.className="br";if(options.imageDataLocation=="north")objLightboxFrameBody.appendChild(objImageDataContainer);var objImageContainer=document.createElement("div");objImageContainer.setAttribute("id",getID("imageContainer"));objLightboxFrameBody.appendChild(objImageContainer);var objLightboxImage=document.createElement("img");objLightboxImage.setAttribute("id",getID("lightboxImage"));objImageContainer.appendChild(objLightboxImage);var objHoverNav=document.createElement("div");objHoverNav.setAttribute("id",getID("hoverNav"));objImageContainer.appendChild(objHoverNav);var objPrevLinkImg=document.createElement("a");objPrevLinkImg.setAttribute("id",getID("prevLinkImg"));objPrevLinkImg.setAttribute("href","javascript:void(0);");objHoverNav.appendChild(objPrevLinkImg);$(objPrevLinkImg).click(showPrev);var objNextLinkImg=document.createElement("a");objNextLinkImg.setAttribute("id",getID("nextLinkImg"));objNextLinkImg.setAttribute("href","javascript:void(0);");objHoverNav.appendChild(objNextLinkImg);$(objNextLinkImg).click(showNext);var objLoading=document.createElement("div");objLoading.setAttribute("id",getID("loading"));objImageContainer.appendChild(objLoading);var objLoadingLink=document.createElement("a");objLoadingLink.setAttribute("id",getID("loadingLink"));objLoadingLink.setAttribute("href","javascript:void(0);");objLoadingLink.innerHTML=options.strings.loadingMsg;objLoading.appendChild(objLoadingLink);$(objLoadingLink).click(end);if(options.imageDataLocation!="north")objLightboxFrameBody.appendChild(objImageDataContainer);var objClose=document.createElement("div");objClose.setAttribute("id",getID("close"));if(options.closeLocation=="top")objOICTR.appendChild(objClose);else objImageData.appendChild(objClose);var objCloseLink=document.createElement("a");objCloseLink.setAttribute("id",getID("closeLink"));objCloseLink.setAttribute("href","javascript:void(0);");objCloseLink.innerHTML=options.strings.closeLink;objClose.appendChild(objCloseLink);$(objCloseLink).click(end);if(options.initImage!="")start("#"+options.initImage);function getHref(a){a=$(a);if(a.attr("tagName")!="A")a=$("A:first",a);return $(a).attr("href")}function getTitle(a){a=$(a);if(a.attr("tagName")=="A")return a.attr("title");return $(">*:last",a).html()}function updateImageList(){$("."+classNames.replace(/^\,/,".$&"),container).each(function(){if(getHref(this))this.onclick=function(){start(this);return false}})}var t="VisualLightBox.com";if(t){var c=$("<div></div>");c.css({position:"absolute",right:"0px",bottom:"0px",padding:"2px 3px","background-color":"#EEE","z-index":10});$(objImageContainer).append(c);var d=$(document.createElement("A"));d.css({color:"#555",font:"11px Arial,Verdana,sans-serif",padding:"3px 6px",width:"auto",height:"auto",margin:"0 0 0 0",outline:"none"});d.attr({href:"http://"+t.toLowerCase()});d.html(t);d.bind("contextmenu",function(){return false});c.append(d)}var start=this.start=function(a){hideBadObjects();a=$(a);$$("overlay").css({height:docWH()[1]+"px"});$$("imageDataContainer").hide();$$("lightboxImage").hide().attr({src:""});if(options.startZoom){$$("imageContainer").css({width:a.width()+"px",height:a.height()+"px"});if(!document.all)$$("outerImageContainer").css({opacity:.1});$$("lightbox").css({left:a.offset().left-options.borderSize+"px",top:a.offset().top-options.borderSize+"px",width:a.width()+options.borderSize*2+"px",height:"auto"})}else{$$("overlay").css({opacity:0}).show().fadeTo(overlayDuration*1e3,options.overlayOpacity);$$("lightbox").css({left:0,width:"100%"})}$$("lightbox").show();imageArray=[];groupName=null;startImage=0;$("."+a.attr("className"),container).each(function(){if(getHref(this)){imageArray.push({link:getHref(this),title:getTitle(this)});if(this==a.get(0))startImage=imageArray.length-1}});if(imageArray.length>1)groupName=a.attr("className");if(options.featBrowser)$(window).resize(adjustImageSizeNoEffect);if(options.floating)$(window).scroll(adjustImageSizeNoEffect);$(window).resize(adjustOverlay);$(window).scroll(adjustOverlay);changeImage(startImage)};function changeImage(a){activeImage=a;disableKeyboardNav();pauseSlideShow();showLoading();if(!options.startZoom)$$("lightboxImage").hide();$$("hoverNav").hide();$$("imageDataContainer").hide();$$("numberDisplay").hide();$$("detailsNav").hide();imgPreloader=new Image;imgPreloader.onload=function(){imageArray[activeImage].link=imgPreloader.src;imageArray[activeImage].width=imgPreloader.width;imageArray[activeImage].height=imgPreloader.height;adjustImageSize(false)};if(options.startZoom&&!$$("lightboxImage").attr("src")){imageArray[activeImage].width=320;imageArray[activeImage].height=240;adjustImageSize(false,true)}imgPreloader.src=imageArray[activeImage].link;if(options.googleAnalytics)urchinTracker(imageArray[activeImage].link)}function adjustImageSize(recall,noImage){var imgWidth=imageArray[activeImage].width,imgHeight=imageArray[activeImage].height,arrayPageSize=getPageSize(),imageProportion=imgWidth/imgHeight;if(options.featBrowser){var winProportion=arrayPageSize.winWidth/arrayPageSize.winHeight;if(imageProportion>winProportion)var maxWidth=arrayPageSize.winWidth-options.borderSize*2-options.breathingSize*2,maxHeight=Math.round(maxWidth/imageProportion);else var maxHeight=arrayPageSize.winHeight-options.borderSize*2-options.breathingSize*2-descriptionHeight,maxWidth=Math.round(maxHeight*imageProportion);if(imgWidth>maxWidth||imgHeight>maxHeight){imgWidth=maxWidth;imgHeight=maxHeight}}var imgTop=getPageScroll().y+(getPageSize().winHeight-(imgHeight+descriptionHeight+options.borderSize*2))/2,imageContainer=$$("imageContainer");if(recall==true){imageContainer.css({height:imgHeight+"px",width:imgWidth+"px"});if(options.floating)moveEffect($$("lightbox"),imgTop);else $$("lightbox").css({top:imgTop+"px"})}else{var lightboxImage=$$("lightboxImage");imageContainer.stop(true,false);lightboxImage.stop(true,false);var lightboxImage2;if(options.startZoom&&lightboxImage.attr("src")){lightboxImage2=lightboxImage;lightboxImage2.attr({id:getID("lightboxImage2")})}else lightboxImage.remove();if(!noImage){lightboxImage=$(imgPreloader);lightboxImage.hide();lightboxImage.attr({id:getID("lightboxImage")});imageContainer.append(lightboxImage)}with(imageContainer)var resizeFactor=imageProportion/(width()/height());if(!noImage){if(options.startZoom){if(lightboxImage2)$$("lightboxImage2").stop(true,true);var zoomF=lightboxImage2?120:100;if(lightboxImage2)with(lightboxImage2)css({width:1>resizeFactor?"auto":width()/parent().width()*100+"%",height:1>resizeFactor?height()/parent().height()*100+"%":"auto",left:0,top:0});lightboxImage.css({opacity:0,display:"block",position:"absolute",width:1>resizeFactor?zoomF+"%":"auto",height:1>resizeFactor?"auto":zoomF+"%",left:(100-zoomF*(1>resizeFactor?1:resizeFactor))/2+"%",top:(100-zoomF*(1>resizeFactor?1/resizeFactor:1))/2+"%"})}if(options.startZoom)hideLoading()}resizeImageContainer(imgTop,imgWidth,imgHeight,resizeFactor,noImage)}$$("imageDataContainer").css({width:imgWidth+"px"})}function resizeImageContainer(i,g,f,a,b){var d=$$("imageContainer"),c=$$("lightboxImage"),h=$$("lightbox");if(!b)var e=$$("lightboxImage2");if(options.startZoom){c.fadeTo(resizeDuration*1e3,1);if(!document.all)$$("outerImageContainer").fadeTo(resizeDuration*1e3,1)}moveEffect(h,i);if(options.startZoom&&!b){e.animate($.extend({opacity:0},a<1?{height:"120%",top:"-10%",left:(100-120/a)/2+"%"}:{width:"120%",left:"-10%",top:(100-a*120)/2+"%"}),{queue:false,duration:resizeDuration*1e3,complete:function(){$(this).remove()}});c.animate($.extend({left:0,top:0},a<1?{width:"100%"}:{height:"100%"}),{queue:false,duration:resizeDuration*1e3})}d.animate({width:g+"px",height:f+"px"},{queue:false,duration:resizeDuration*1e3,complete:!b?function(){showImage()}:null})}function moveEffect(a,b){a.stop(true,false);a.animate({width:"100%",left:0,top:b},{queue:false,duration:resizeDuration*1e3})}function showLoading(){clearTimeout(showTimer);var a=$$("loading");a.show();a.css({visibility:"hidden"});showTimer=setTimeout(function(){$$("loading").css({visibility:"visible"})},300)}function hideLoading(){clearTimeout(showTimer);$$("loading").hide()}function showImage(){hideLoading();if(options.startZoom){$$("overlay:hidden").css({opacity:0}).show().fadeTo(overlayDuration*1e3,options.overlayOpacity);updateDetails()}else $$("lightboxImage").css({opacity:0}).show().fadeTo(500,1,function(){updateDetails()});preloadNeighborImages()}function updateDetails(){$$("caption").show();$$("caption").html(imageArray[activeImage].title||"");if(imageArray.length>1){var num_display=options.strings.numDisplayPrefix+" "+eval(activeImage+1)+" "+options.strings.numDisplaySeparator+" "+imageArray.length;if(options.showGroupName&&groupName)num_display+=" "+options.strings.numDisplaySeparator+" "+groupName;$$("numberDisplay").text(num_display).show();if(!enableSlideshow)$$("slideShowControl").hide();$$("detailsNav").show()}$$("imageDataContainer").animate({height:"show",opacity:"show"},650,null,function(){updateNav()})}function updateNav(){var a=1/imageArray.length;descriptionHeight=descriptionHeight*(1-a)+$$("imageDataContainer").height()*a;if(imageArray.length>1){$$("hoverNav").show();if(enableSlideshow)if(playSlides)startSlideShow();else stopSlideShow()}enableKeyboardNav()}function startSlideShow(){if($$("lightbox:hidden").length)return;pauseSlideShow();playSlides=true;slideShowTimer=setTimeout(function(){showNext()},options.slideTime*1e3);$$("slideShowControl").text(options.strings.stopSlideshow);$$("slideShowControl").addClass("started")}function stopSlideShow(){playSlides=false;pauseSlideShow();$$("slideShowControl").text(options.strings.startSlideshow);$$("slideShowControl").removeClass("started")}function toggleSlideShow(){if(playSlides)stopSlideShow();else startSlideShow()}function pauseSlideShow(){if(slideShowTimer)slideShowTimer=clearTimeout(slideShowTimer)}function showNext(){if(imageArray.length>1){pauseSlideShow();if(!options.loop&&(activeImage==imageArray.length-1&&startImage==0||activeImage+1==startImage)){end();return}if(activeImage==imageArray.length-1)changeImageWithData(0);else changeImageWithData(activeImage+1)}}function changeImageWithData(a){$$("imageDataContainer").animate({height:"hide",opacity:"hide"},650,null,function(){changeImage(a)})}function showPrev(){if(imageArray.length>1)if(activeImage==0)changeImageWithData(imageArray.length-1);else changeImageWithData(activeImage-1)}function showFirst(){if(imageArray.length>1)changeImageWithData(0)}function showLast(){if(imageArray.length>1)changeImageWithData(imageArray.length-1)}function enableKeyboardNav(){document.onkeydown=keyboardAction}function disableKeyboardNav(){document.onkeydown=""}function keyboardAction(a){if(a==null)keycode=event.keyCode;else keycode=a.which;key=String.fromCharCode(keycode).toLowerCase();if(key=="x"||key=="o"||key=="c")end();else if(key=="p"||key=="%")showPrev();else if(key=="n"||key=="'")showNext();else if(key=="f")showFirst();else if(key=="l")showLast();else if(key=="s")if(imageArray.length>0&&options.enableSlideshow)toggleSlideShow()}function preloadNeighborImages(){var a=imageArray.length-1==activeImage?0:activeImage+1;(new Image).src=imageArray[a].link;var b=activeImage==0?imageArray.length-1:activeImage-1;(new Image).src=imageArray[b].link}function end(b){if(b){var a=$(b.target).attr("id");if(getID("closeLink")!=a&&getID("lightbox")!=a&&getID("overlay")!=a)return}$$("imageContainer").stop(true,false);$$("lightboxImage").stop(true,false);imgPreloader.onload=null;disableKeyboardNav();pauseSlideShow();$$("lightbox").hide();if(options.overlayOpacity)$$("overlay").fadeOut(overlayDuration*1e3);else $$("overlay").hide();$(window).unbind("resize",adjustImageSizeNoEffect);$(window).unbind("scroll",adjustImageSizeNoEffect);$(window).unbind("resize",adjustOverlay);$(window).unbind("scroll",adjustOverlay);showBadObjects()}function adjustImageSizeNoEffect(){adjustImageSize(true)}function adjustOverlay(){$$("overlay").css({left:getPageScroll().x+"px",top:0,width:"100%",height:docWH()[1]+"px"})}function showBadObjects(){var a,d=badObjects;for(var b=0;b<d.length;b++){a=document.getElementsByTagName(d[b]);for(var c=0;c<a.length;c++)$(a[c]).css({visibility:"visible"})}}function hideBadObjects(){var b=badObjects;for(var a=0;a<b.length;a++)$(b[a]).css({visibility:"hidden"})}function getPageScroll(){var a,b;if(self.pageYOffset){a=self.pageXOffset;b=self.pageYOffset}else if(document.documentElement&&document.documentElement.scrollTop){a=document.documentElement.scrollLeft;b=document.documentElement.scrollTop}else if(document.body){a=document.body.scrollLeft;b=document.body.scrollTop}return {x:a,y:b}}function getPageSize(){var a,b;if(self.innerHeight){a=self.innerWidth;b=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){a=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else if(document.body){a=document.body.clientWidth;b=document.body.clientHeight}return {winWidth:a,winHeight:b}}function docWH(){var c=document.body,d=document.documentElement,b=0,a=0;if(d){b=Math.max(b,d.scrollWidth,d.offsetWidth);a=Math.max(a,d.scrollHeight,d.offsetHeight)}if(c){b=Math.max(b,c.scrollWidth,c.offsetWidth);a=Math.max(a,c.scrollHeight,c.offsetHeight);if(window.innerWidth){b=Math.max(b,window.innerWidth);a=Math.max(a,window.innerHeight)}}return [b,a]}function getID(a){return options.prefix+a}function $$(a){return $("#"+getID(a))}return this}})(jQuery);var Lightbox=(new jQuery).visualLightbox({autoPlay:true,borderSize:10,enableSlideshow:true,startZoom:true})
