(function($) { $.fn.galleryViewer = function(setup) { var imgArr = new Array(); setup = jQuery.extend({ galleryfolder:'templates/', overlayBgColor:'#000', overlayOpacity:0.8, imageBtnPrev:'templates/?img=prev', imageBtnNext:'templates/?img=next', imageBtnSlideShow:'templates/?img=play', imageBtnSlideShowPause:'templates/?img=pause', imageBtnClose:'templates/?img=close', imageBlank:'templates/?img=blank', containerBorderSize:10, containerResizeSpeed:400, slideshow:false, slideshowAutoStart:false, slideShowDuration:6000, imageInfo:false, imageInfoLink:'templates/?info=', showShare:false, shareLink:'templates/?share=', showDownloadLink:true, downloadLink:'templates/?download=', txtDownload:'Save Photo', txtImageInfo:'Image Info', txtImageInfoHide:'Hide Info', txtShare:'Share', txtShareHide:'Hide Sharing', txtAuthor:'by', txtImage:'Image', txtOf:'of', imageArray:imgArr, currentImage:0 },setup); var dimensions = jQuery.extend({ pWidth:0, pHeight:0, wWidth:0, wHeight:0, posTop:0, posLeft:0, scroll:0 },dimensions); var imgElements = this; var resizing = false; var origImgWidth = 0; var origImgHeight = 0; var myPlayer = null; function executeLink() { initViewer(this,imgElements); return false; } function initViewer(elClicked,imgElements) { $('embed,object,select').css({'visibility':'hidden'}); createViewer(); setup.imageArray.length = 0; setup.currentImage = 0; for( var i = 0; i < imgElements.length; i++ ) { setup.imageArray.push(new Array( $(imgElements[i]).attr('href') , $(imgElements[i]).attr('title') , $(imgElements[i]).attr('caption') , $(imgElements[i]).attr('author') , $(imgElements[i]).attr('orig') , $(imgElements[i]).attr('video') )); } while( setup.currentImage < (setup.imageArray.length-1) && setup.imageArray[setup.currentImage][0] != $(elClicked).attr('href') ) { setup.currentImage++; } viewImage(); } function createViewer() { getWindowDimensions(); $('
').appendTo("body").css({ backgroundColor:setup.overlayBgColor, opacity:setup.overlayOpacity, width:dimensions.pWidth, height:dimensions.pHeight }).click(function() { closeOverlay(); }).fadeIn(); viewer = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; $('
').html(viewer).appendTo("body").css({ top:dimensions.posTop, left:dimensions.posLeft }).click(function() { closeOverlay(); }).show(); $("#imgInfoBox").click(function(event){ event.stopPropagation(); }); $("#downloadLinkRef").click( function(event) { alert('testing!'); }); //myPlayer = _V_("videoPlayer"); if(setup.imageInfo) { $('').appendTo('#imgInfo'); $(''+setup.txtImageInfo+'').appendTo('#viewExif').click(function(event) { imageInfo(); return false; }); } if(setup.showShare) { $('').appendTo('#imgInfo'); $(''+setup.txtShare+'').appendTo('#viewShare').click(function(event) { showShare(); return false; }); } if(setup.showDownloadLink) { /**/ $(''+setup.txtDownload+'').appendTo('#imgInfo'); } if(setup.slideshow) { var ssLink = $('').appendTo("#imgSlideShow").click(function() { startSlideShow(); }).show(); if(setup.slideshowAutoStart) ssLink.trigger('click'); } $('').appendTo("#viewerClose").click(function() { closeOverlay(); }).show(); // resizing window $(window).resize(function() { getWindowDimensions(); $('#gJv2overlay').css({ width:dimensions.wWidth, height:dimensions.wHeight }); if(resizing != true) { resizing = true; $.gDoTimeout( 'resize', 1000 , function(){ resizeViewer(false); resizing = false; }); } }); } function getWindowDimensions() { dimensions.wWidth = $(window).width(); dimensions.wHeight = $(window).height(); dimensions.pWidth = $(document).width(); dimensions.pHeight = $(document).height(); dimensions.scroll = $(window).scrollTop(); dimensions.posTop = dimensions.scroll + (dimensions.wHeight / 10); dimensions.posLeft = $(window).scrollLeft(); } function videoPlayer() { $('#imgDiv').hide(); if(myPlayer != null) { if(myPlayer.techName == "html5") { myPlayer.tag.src = ""; myPlayer.tech.removeTriggers(); myPlayer.load(); } //myPlayer.tech.destroy(); myPlayer.destroy(); $(myPlayer.el).remove(); } var code = '
'; $(code).prependTo('#imgDivWrap'); $("#gJv2videoPlayerWrap").click(function(event){ event.stopPropagation(); }); myPlayer = _V_("videoPlayer"); } function viewImage() { removeImageInfo(); $('#imgLoading').show(); $('#imgImg, #imgNav, #imgInfoBox').hide(); var preloadImage = new Image(); preloadImage.onload = function() { if(setup.imageArray[setup.currentImage][5] != null) { videoPlayer(); } else { $('#gJv2videoPlayerWrap').remove(); myPlayer = null; $('#imgDiv').show(); $('#imgImg').attr('src', setup.imageArray[setup.currentImage][0]); } origImgWidth = preloadImage.width; origImgHeight = preloadImage.height; resizeViewer(true); preloadImage.onload=function(){}; }; preloadImage.src = setup.imageArray[setup.currentImage][0]; }; function imageMaxSize(imgWidth,imgHeight) { var extraHeight = 60; var imgTotalMargin = (setup.containerBorderSize*4); var maxHeight = dimensions.wHeight - imgTotalMargin - extraHeight; var maxWidth = dimensions.wWidth - imgTotalMargin; if( imgHeight > maxHeight ) { var newHeight = maxHeight; var newWidth = Math.floor((newHeight / imgHeight) * imgWidth); if( newWidth > maxWidth ) { newWidth = maxWidth; newHeight = Math.floor((newWidth / imgWidth) * imgHeight); } dimensions.imgHeight = newHeight; dimensions.imgWidth = newWidth; } else if( imgWidth > maxWidth ) { var newWidth = maxWidth; var newHeight = Math.floor((newWidth / imgWidth) * imgHeight); if( newHeight > maxHeight ) { newHeight = maxHeight; newWidth = Math.floor((newHeight / imgHeight) * newWidth); } dimensions.imgHeight = newHeight; dimensions.imgWidth = newWidth; } else { dimensions.imgHeight = imgHeight; dimensions.imgWidth = imgWidth; } } function resizeViewer(initImg) { var extraHeight = 60; var imgMargin = (setup.containerBorderSize*2); imageMaxSize(origImgWidth,origImgHeight); var imgWrapWidth = (dimensions.imgWidth + imgMargin); var imgWrapHeight = (dimensions.imgHeight + imgMargin); dimensions.posTop = dimensions.scroll + ((dimensions.wHeight - imgWrapHeight)/2) - (extraHeight/2); if(dimensions.posTop < imgMargin) dimensions.posTop = imgMargin; $('#gJv2imgViewer').animate({ top: dimensions.posTop }, setup.containerResizeSpeed); if(!initImg) $('#imgImg').animate({ width:dimensions.imgWidth, height:dimensions.imgHeight }, setup.containerResizeSpeed); $('#imgDivWrap').animate({ width: imgWrapWidth }); $('#imgNav').css({ height: imgWrapHeight }); $('#imgDiv').animate({ width: dimensions.imgWidth, height: dimensions.imgHeight }, setup.containerResizeSpeed, function() { if(initImg) showImg(dimensions.imgWidth,dimensions.imgHeight); }); if(myPlayer != null) { myPlayer.width(dimensions.imgWidth); myPlayer.height(dimensions.imgHeight); } $('#imgInfoBox').css({ width: dimensions.imgWidth }); $('#imgPrevious, #imgNext').css({ height: dimensions.imgHeight + (setup.containerBorderSize * 2) }); }; function showImg(w,h) { $('#imgLoading').hide(); $('#imgImg').css({width:w,height:h}).fadeIn(function() { $('#imgNav').show(); $('#imgPrevious, #imgNext').css({'background':'transparent url(' + setup.imageBlank + ') no-repeat'}); if( setup.currentImage != 0 ) { $('#imgPrevious').unbind().hover(function() { $(this).css({ 'background':'url('+setup.imageBtnPrev+') left 15% no-repeat' }); },function() { $(this).css({ 'background':'transparent url('+setup.imageBlank+') no-repeat' }); }).show().bind('click',function() { if(setup.sshowOn) stopSlideshow(); setup.currentImage--; viewImage(); return false; }); } if( setup.currentImage != setup.imageArray.length-1 ) { $('#imgNext').unbind().hover(function() { $(this).css({ 'background':'url('+setup.imageBtnNext+') right 15% no-repeat' }); },function() { $(this).css({ 'background':'transparent url('+setup.imageBlank+') no-repeat' }); }).show().bind('click',function() { if(setup.sshowOn) stopSlideshow(); setup.currentImage++; viewImage(); return false; }); } $(document).keydown(function(objEvent) { eventKeyPress(objEvent); }); $('#imgInfoBox').slideDown('fast'); //This function was not returning true therefore not changing the download link (changed the array from 1 to 0) //alert('1st'); if( setup.imageArray[setup.currentImage][0] ) { //alert('2st'); $('#imgTitle').html(setup.imageArray[setup.currentImage][1]).show(); if(setup.imageArray[setup.currentImage][2]!=null) $('#imgCaption').html(setup.imageArray[setup.currentImage][2]).show(); else $('#imgCaption').html('').show(); if(setup.imageArray[setup.currentImage][3]!=null) $('#imgAuthor').html(' '+setup.txtAuthor+' '+setup.imageArray[setup.currentImage][3]).show(); else $('#imgAuthor').html('').show(); var origVal = setup.imageArray[setup.currentImage][4].replace(setup.galleryfolder,''); $('#imgCurrentOriginal').val(origVal); if(setup.showDownloadLink) //alert('dll ' + setup.downloadLink+origVal); //The download was linked to the incorrect file path on this line $('#downloadLinkRef').attr('href', 'photos/'+origVal); } if( setup.imageArray.length > 1 ) $('#imgCount').html(setup.txtImage+' '+(setup.currentImage+1)+' '+setup.txtOf+' '+setup.imageArray.length).show(); }); preloadNextPrev(); }; function imageInfo() { if($('#exifBg').length == 0) { removeShare(); var src = $('#imgCurrentOriginal').val(); src = escape(src); var w = $('#imgDiv').width(); var h = $('#imgDiv').height(); $('
').css({ opacity:0.5, width:w, height:h }).appendTo('#imgNav'); $('
').css({ width:(w-40), height:(h-40) }).load(setup.imageInfoLink+src.replace(setup.galleryfolder,'')).appendTo('#imgNav').bind('click',function(event){event.stopPropagation();removeImageInfo();}); $('#viewExif a').text(setup.txtImageInfoHide); } else { removeImageInfo(); } } function removeImageInfo() { $('#exifInfo').remove(); $('#exifBg').remove(); $('#viewExif a').text(setup.txtImageInfo); } function showShare() { if($('#shareBg').length == 0) { removeImageInfo(); var src = $('#imgCurrentOriginal').val(); src = escape(src); var w = $('#imgDiv').width(); var h = $('#imgDiv').height(); $('
').css({ opacity:0.5, width:w, height:h }).appendTo('#imgNav'); $('
').css({ width:(w-40), height:(h-40) }).load(setup.shareLink+src.replace(setup.galleryfolder,'')).appendTo('#imgNav').bind('click',function(event){event.stopPropagation();removeShare();}); $('#viewShare a').text(setup.txtShareHide); } else { removeShare(); } } function removeShare() { $('#shareInfo').remove(); $('#shareBg').remove(); $('#viewShare a').text(setup.txtShare); } function clearImage() { $('#imgTitle').html(''); $('#imgCaption').html(''); $('#imgAuthor').html(''); } function nextSlide() { clearImage(); setup.currentImage++; viewImage(); if(setup.sshowOn && setup.currentImage < setup.imageArray.length-1) { $.gDoTimeout( 'sss', setup.slideShowDuration , function(){ nextSlide(); }); } return false; } function startSlideShow() { setup.sshowOn = true; $("#imgSlideShow img").remove(); $('').appendTo("#imgSlideShow").click(function() { stopSlideshow(); }).show(); $.gDoTimeout( 'ss', setup.slideShowDuration , function(){ nextSlide(); }); } function stopSlideshow() { setup.sshowOn = false; $.gDoTimeout( 'ss' ); $.gDoTimeout( 'sss' ); $("#imgSlideShow img").remove(); $('').appendTo("#imgSlideShow").click(function() { startSlideShow(); }).show(); } function preloadNextPrev() { if ( (setup.imageArray.length -1) > setup.currentImage ) { objNext = new Image(); objNext.src = setup.imageArray[setup.currentImage + 1][0]; } if ( setup.currentImage > 0 ) { objPrev = new Image(); objPrev.src = setup.imageArray[setup.currentImage -1][0]; } } function closeOverlay() { $('#gJv2imgViewer').fadeOut(200,function() { $(this).remove(); $('#gJv2overlay').fadeOut(500,function() { $(this).remove(); }); }); $('embed, object, select').css({ 'visibility':'visible' }); } function eventKeyPress(objEvent) { if( objEvent == null ) { keycode = event.keyCode; escapeKey = 27; } else { keycode = objEvent.keyCode; escapeKey = objEvent.DOM_VK_ESCAPE; } if(keycode == escapeKey) closeOverlay(); else if(keycode==39 && setup.currentImage!=(setup.imageArray.length-1) ) { setup.currentImage++; viewImage(); $(document).unbind(); } else if(keycode==37 && setup.currentImage!=0) { setup.currentImage--; viewImage(); $(document).unbind(); } } return this.unbind('click').click(executeLink); }; })(jQuery); function uploadAnother( ref ) { var tempFile = window.document.createElement( 'INPUT' ); tempFile.setAttribute( 'type', 'file' ); tempFile.className = 'fileupload'; tempFile.setAttribute( 'name', 'fileupload[]' ); var tempForm = false; var tempParent = false; var ok = true; try { while( ok == true ) { if( tempParent == false ) { tempParent = ref.parentNode; } else if ( tempParent.nodeName.toLowerCase() == 'form' ) { tempForm = tempParent; ok = false; } else { tempParent = tempParent.parentNode; } } // ends while } catch( e ) {}; ok = null; tempForm.insertBefore( tempFile, ref ); if (tempForm.length-1 >= 5){ tempForm.removeChild(ref); } return false; } // ends uploadAnother /* * jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010 * http://benalman.com/projects/jquery-dotimeout-plugin/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){var a={},c="gDoTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);