(function(a){a.fn.foldinggallery=function(b){var c={autoPlay:true,loopPlay:true,autoHide:true,autoPlayVideo:true,foldAndButtons:"fold",captionStyle:"linebyline",logoWidth:142,logoHeight:80,menuWidth:200,playSpeed:5,modulePath:"",showMenu:"right"};var b=a.extend(c,b);return this.each(function(){function N(){k.empty();k.css({left:"",top:"",width:""});var d=a(a(f[o]).children(".photo")[p]);var e=d.attr("description");if(!e){e=d.children(".description").html()}if(!e){k.hide();return}else{k.show()}var g="";var h=-1;var i=-1;var j=e.substring(0,e.indexOf("\n")).toLowerCase();if(j.charCodeAt(j.length-1)==13||j.charCodeAt(j.length-1)==11){j=j.substring(0,j.length-1)}if(j=="upperleft"||j=="upperright"||j=="lowerleft"||j=="center"||j=="lowerright"){g=j}else{if(j.indexOf(",")>0){var l=j.split(",");if(l[0]*1>0&&l[1]*1>0){h=l[0]*1;i=l[1]*1}}}if(g!=""||h>0&&i>0){e=e.substring(e.indexOf("\n")+1,e.length)}var m="";var n=30;if(b.simpleCaption){m="<div class='simple'>"+e+"</div>";k.append(m);if(k.width()>c.width()/3){k.css("width",c.width()/3)}}else{var q=100;var r=e.split("\n");for(var s=0;s<r.length;s++){if(r[s]!=""){m+="<div class='line' style='margin-left:"+q*s+"px; margin-top:"+26*s+"px'><div class='left' /><div class='right'>"+r[s]+"</div></div>"}}k.append(m)}if(h<0||i<0){var t=L.albumsTop();if(g=="upperright"){h=c.width()-k.width()-n;i=n}else if(g=="upperleft"){h=n;i=n}else if(g=="lowerleft"){h=n;i=t-n-k.height()}else if(g=="center"){h=(c.width()-k.width())/2;i=(t-k.height())/2}else{h=c.width()-k.width()-n;i=t-n-k.height()}}k.css("left",h);k.css("top",i)}function M(a){if(a.length<1){return}a.parent().removeClass("nextItem");if(b.foldEffect)a.hide();else a.fadeTo("slow",0);var c=a[0].tagName.toLowerCase();if(c=="div"||c=="video"){a.remove()}}var c=a(this);c.append("<div class='images'></div><div class='caption'></div><div class='thumbnails'><div class='inner'><div class='innerinner'></div></div></div><div class='albums'></div><div class='loading'></div><div class='buttons'><div class='prev'></div><div class='play'></div><div class='next'></div></div>");var d=c.children(".albums");var e=c.children(".datahtml");var f=e.children(".album");var g=c.children(".thumbnails");var h=c.find(".thumbnails .inner");var i=c.find(".thumbnails .inner .innerinner");var j=c.children(".images");var k=c.children(".caption");var l=c.children(".buttons");var m=l.children(".play");e.hide();c.children(".preview").remove();var n=c.attr("ID");var o=-1;var p=-1;var q=0;var r=-1;var s=-1;var t=0;var u=false;var v=0;var w=5;var x=5;var y;var z;var A="";var B="left";var C;var D=false;var E=false;var F=true;var G=.858;var H=null;var I=false;var J;if(navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/iPad/i))J=true;else J=false;var K=J;var L=this;this.albumsTop=function(){if(d.css("visibility")!="hidden"){return c.height()-4-z}else{return c.height()}};this.showControls=function(){t=0;var a=Math.ceil(g.position().left);if(a<0){g.animate({left:0},"slow")}else if(a>=c.width()){g.animate({left:c.width()-g.width()},"slow")}if(d.position().top>c.height()-d.height()){d.animate({top:c.height()-d.height()},"slow")}};this.stopAutoHide=function(){if(s<0)return;window.clearInterval(s);s=-1};this.stopAutoPlay=function(){if(r<0)return;window.clearInterval(r);r=-1;m.removeClass("pause");m.removeClass("pauseactive");m.removeClass("playactive")};this.autoPlay=function(a){if(r>0){this.stopAutoPlay();v=0}else{if(a)u=false;m.addClass("pause");q=p;r=window.setInterval(n+".onInterval()",1e3)}};this.onInterval=function(){if(u)return;v+=1;if(v>=x){v=0;if(p+1>=i.children(".thumbnail").length){if(!b.loopPlay){if(q>0){q=0;this.loadPhotoAt(p+1)}else{this.stopAutoPlay()}}else{this.loadPhotoAt(p+1)}}else{this.loadPhotoAt(p+1)}}};this.onAutoHideInterval=function(){t+=1;if(t>w){var b=Math.ceil(g.position().left);if(b<=0){g.animate({left:g.width()*-1},"slow")}else if(b>=c.width()-g.width()){g.animate({left:c.width()},"slow")}var e=a(d.children(".tooltip")[0]).height();d.animate({top:c.height()+e},"slow")}};this.getResizedResolution=function(a){var b=a.width/a.maxWidth;var c=a.height/a.maxHeight;var d=F?Math.max(b,c):Math.min(b,c);var e=Math.round(a.width/d);var f=Math.round(a.height/d);a.newWidth=e;a.newHeight=f;return};this.showAlbumTitle=function(a){var b="tooltip"+a.attr("index");var c=d.children("#"+b);if(c.length<1){d.append("<div class='tooltip' id='"+b+"'><div class='left' /><div class='center'>"+a.attr("title")+"</div><div class='right' /></div>");c=d.children("#"+b);c.css("top",a.position().top-c.height());c.css("left",a.position().left+(a.width()-c.width())/2);c.show()}else{c.show()}};this.hideAlbumTitle=function(a){var b=a.attr("index");if(b==o){return}var c="tooltip"+b;var e=d.children("#"+c);if(e.length>0){e.hide()}};this.loadAlbum=function(e){o=e;p=-1;var g=d.children(".album");for(var k=0;k<g.length;k++){if(o==k)L.showAlbumTitle(a(g[k]));else L.hideAlbumTitle(a(g[k]))}j.empty();i.empty();var l=c.children(".fold");if(l.length>0){l.remove()}var m=a(f[o]).children(".photo");for(var k=0;k<m.length;k++){var n=a(m[k]);var q="thumbnail";if(k==m.length-1)q+=" lastItem";i.append("<div class='"+q+"' index='"+k+"'>"+n.attr("title")+"</div>")}if(i.height()<h.height()){i.css("top",(h.height()-i.height())/2)}else{i.css("top",0)}var s=i.children(".thumbnail");s.hover(function(){var b=a(this);if(b.attr("index")!=p)a(this).addClass("hover")},function(){a(this).removeClass("hover")});s.click(function(){L.stopAutoPlay();L.loadPhoto(a(this))});if(!D){D=true;var t=a(s[0]).height();if(t<=0){t=20}h.css("height",h.height()-h.height()%t)}L.loadPhotoAt(0);if(b.autoPlay&&r<=0)L.autoPlay(false)};this.isVideo=function(a){if(a.indexOf(".")>0){var b=a.toLowerCase().substring(a.length-4,a.length);if(b==".mp4"||b==".flv"){return true}}return false};this.loadPhotoAt=function(b){if(b==p)return;var c=i.children(".thumbnail");if(b<0)b=c.length-1;if(b>=c.length)b=0;v=0;var d=a(c[b]);this.loadPhoto(d)};this.loadPhoto=function(d){if(I)return;var e=d.attr("index")*1;if(e==p)return;u=true;var g=j.find("#img"+p);var h=a(f[o]).children(".photo");var i=a(h[e]);var k=i.attr("image");var l=i.attr("link");var m=i.attr("target");if(b.foldEffect){if(e==0&&p==h.length-1||e==p+1){}else{var n=p+1;if(n>=h.length)n=0;var q=j.find("#img"+n);q.hide();q.parent().removeClass("nextItem");q.parent().css({left:0,width:"auto"});q.css("left",q.attr("normalLeft"))}}var r=j.find("#img"+e);if(r.length==0){var k=i.attr("image");if(L.isVideo(k)){r=L.loadVideo(e,k,r,null);L.photoLoaded(e)}else{j.append(this.getImageNode(e,i));r=j.find("#img"+e);var s=new Image;s.onload=function(){L.alignPhoto(r,s);L.photoLoaded(e)};s.src=k}}else{if(b.foldEffect&&(e==0&&p==h.length-1||e==p+1)){var m=(c.width()+c.height())/G;var t=c.width();var v=r.parent();var w=c.children(".fold");I=true;if(B!="left"){w.animate({width:m,height:m},{step:function(a,b){var c=Math.floor(a*G);if(c>t)c=t;v.css({width:c,height:c})},duration:"slow",complete:function(){I=false;w.css({left:0,top:0,width:0,height:0});L.photoLoaded(e)}})}else{var x=c.width();var y=r.attr("normalLeft");w.animate({width:m,height:m},{step:function(a,b){w.css("left",x-a);var c=Math.floor(a*G);if(c>t)c=t;v.css({width:c,height:c,left:x-c});r.css("left",y-(x-c))},duration:"slow",complete:function(){I=false;w.css({left:0,top:0,width:0,height:0});L.photoLoaded(e)}})}}else{L.photoLoaded(e)}}};this.getImageNode=function(a,b){var c=b.attr("link");var d=b.attr("target");var e="";var f="";if(c!=undefined&&c!=""){var g="";if(d!=undefined&&d!=""){g="target='"+d+"'"}e="<a href='"+c+"' style='display:block;' "+g+">";f="</a>"}else{e="<div>";f="</div>"}return e+"<img class='image' id='img"+a+"' style='display:none; opacity:0; border:0px;' index='"+a+"' />"+f};this.photoLoaded=function(d){if(p>=0){var e=j.find("#img"+p);M(e)}var k=j.find("#img"+d);if(b.foldEffect){k.show();k.css("opacity","")}else{k.fadeTo("slow",1)}if(k.position().left!=k.attr("normalLeft"))k.css("left",k.attr("normalLeft"));var l=k.attr("src");var m=k.attr("video");if(m){if(k[0].tagName.toLowerCase()=="img"){var n=k.parent();n.empty();k=L.loadVideo(d,m,k,null)}}else{u=false}if(typeof UPG_onPhotoLoad!="undefined"){var q=a(a(f[o]).children(".photo")[d]).attr("umgid");UPG_onPhotoLoad(q)}if(g.is(":visible")){var r=i.children(".thumbnail");a(r[p]).removeClass("active");a(r[d]).addClass("active");var s=2;var t=false;var v;var w=a(i.children("div")[d]);if(i.height()>=h.height()){var x=d>p;if(w.position().top+w.height()+s*w.height()+i.position().top>=h.height()&&x){t=true;v=w.position().top*-1+s*w.height()}else if(w.position().top+i.position().top<=w.height()*s&&!x){t=true;v=h.height()-w.height()*(s+1)-w.position().top}else{}if(t){if(v+i.height()<h.height()){v=h.height()-i.height()}if(v>0){v=0}i.animate({top:v},"slow")}}}var y=a(f[o]).children(".photo");var z=d+1;if(z>=y.length)z=0;var k=j.find("#img"+z);if(k.length<1){var B=a(y[z]);if(k.length==0){var l=B.attr("image");j.append(this.getImageNode(z,B));k=j.find("#img"+z);var C=new Image;if(L.isVideo(B.attr("image"))){k.attr("video",B.attr("image"));l=A+"css/WidescreenTour2/white.png";C.name="video"}C.onload=function(){if(C.name=="video"){C.width=c.width();C.height=c.height()}L.alignPhoto(k,C);L.preloadFinished(k)};C.src=l}}else{if(d!=z){var D=j.find("div");var E=a(D[D.length-1]);k.parent().insertAfter(E);L.preloadFinished(k)}else{k.show()}}p=d;N()};this.preloadFinished=function(d){if(b.foldEffect){var e=c.children(".fold");if(e.length==0){var f;if(B!="left"){f="fold_upperleft.png"}else{f="fold_upperright.png"}a("<img class='fold' src='"+A+"css/WidescreenTour2/"+f+"' />").insertBefore(g);e=c.children(".fold");e.click(function(){L.stopAutoPlay();L.loadPhotoAt(p+1)})}e.css({left:0,top:0,width:0,height:0});var h=d.parent();h.addClass("nextItem");h.css({left:0,top:0,width:0,height:0});d.show();d.css("opacity","");if(B!="left"){var i=60;e.animate({width:i,height:i},{step:function(a,b){var c=Math.floor(a*G);h.css({width:c,height:c})},duration:1500})}else{var i=60;var j=c.width();d.css("position","absolute");e.animate({width:i,height:i},{step:function(a,b){e.css("left",j-a);var c=Math.floor(a*G);h.css({width:c,height:c,left:j-c});d.css("left",c-j)},duration:1500})}}else{d.hide()}};this.alignPhoto=function(a,b){var d=c.width();var e=c.height();if(b.width>d||b.height>e){var f={width:b.width,maxWidth:d,height:b.height,maxHeight:e};L.getResizedResolution(f);a.attr("width",f.newWidth);a.attr("height",f.newHeight)}else{a.attr("width",b.width);a.attr("height",b.height)}if(a.height()<L.albumsTop()){a.css("top",(L.albumsTop()-a.height())/2)}else if(a.height()<c.height()){a.css("top",0)}else{a.css("top",(c.height()-a.height())/2)}var g=Math.floor((d-a.width())/2);a.css("left",g);a.attr("normalLeft",g);a.attr("src",b.src)};this.loadVideo=function(a,d,e,f){k.hide();var g="";if(!K){var h="";if(!E){E=true;h="&notification=Double click to watch in full screen."}if(!b.autoPlayVideo){h+="&autoStart=False"}g="<div class='image' id='img"+a+"' style='left:0px; top:0px;' ><object allowFullScreen='True' allowScriptAccess='always' allowNetworking='all' width='"+c.width()+"' height='"+c.height()+"'><param name='movie' value='"+A+"SimpleVideo.swf' /><param name='allowFullScreen' value='true' /><param name='wmode' value='transparent' /><param name='flashvars' value='video="+d+"&albumsTop="+L.albumsTop()+"&sender="+n+h+"' /><embed src='"+A+"SimpleVideo.swf' type='application/x-shockwave-flash' allowFullScreen='True' allowScriptAccess='always' allowNetworking='all' width='"+c.width()+"' height='"+c.height()+"' wmode='transparent' flashvars='video="+d+"&albumsTop="+L.albumsTop()+"&sender="+n+h+"'></embed></object></div>"}else{var i="true";if(!b.autoPlayVideo){i+="false"}g="<video id='img"+a+"' src='"+d+"' type='video/mp4' width='"+c.width()+"px' height='"+c.height()+"px' autoplay='"+i+"' controls='controls' />"}if(!f){j.append(g)}else{f.append(g)}e=j.find("#img"+a);if(!f){e.attr("video",d)}if(K){var l=e[0];l.load();l.play();l.addEventListener("ended",L.videoEnd,false)}return e};this.videoEnd=function(){if(K&&r<0){L.loadPhotoAt(p+1)}else{u=false;v=x-1}};b.simpleCaption=b.captionStyle==""||b.captionStyle=="simple";b.foldEffect=b.foldAndButtons==""||b.foldAndButtons=="fold";b.showButtons=b.foldAndButtons=="buttons";if(b.logoWidth){y=b.logoWidth}if(b.logoHeight){z=b.logoHeight}if(b.menuWidth){g.css("width",b.menuWidth);h.css("width",b.menuWidth-h.position().left*2)}if(b.playSpeed){x=b.playSpeed*1}if(b.modulePath){A=b.modulePath}if(b.showMenu){B=b.showMenu}if(b.defaultAlbum){C=b.defaultAlbum}var O=Math.floor(c.width()/(y+4));for(var P=0;P<f.length;P++){if(P>O)break;var Q=a(f[P]);d.append("<div class='album' index='"+P+"' title='"+Q.attr("title")+"'><img style='margin-top:2px;' src='"+Q.attr("logo")+"'></div>")}var R=d.children("div");R.css("width",y+4);R.css("height",z+4);d.css("top",c.height()-d.height());d.css("left",(c.width()-d.width())/2);d.css("width",1e4);if(R.length==1){d.css("visibility","hidden")}else if(R.length==0){d.css("visibility","hidden");g.hide();l.hide();alert("No slides in gallery "+c.attr("ID"));return}else{R.click(function(){L.loadAlbum(a(this).attr("index"))});R.mouseover(function(){L.showAlbumTitle(a(this))});R.mouseout(function(){L.hideAlbumTitle(a(this))})}var S=h.css("top");h.css("height",this.albumsTop()-S.substring(0,S.indexOf("px"))*2);var T=false;if(C>0){for(var P=0;P<R.length;P++){if(a(f[P]).attr("umgid")==C){this.loadAlbum(P);T=true;break}}}if(!T){this.loadAlbum(0)}if(B=="right"){g.addClass("thumbonright");g.css("left",c.width()-g.width());l.css("left",10);l.css("top",10)}else{l.css("left",c.width()-l.width()-10);l.css("top",10);if(B=="none"){g.hide()}}if(b.showButtons){var U=l.children(".prev");U.hover(function(){a(this).addClass("prevactive")},function(){a(this).removeClass("prevactive")});m.hover(function(){a(this).addClass(r<0?"playactive":"pauseactive")},function(){a(this).removeClass(r<0?"playactive":"pauseactive")});var V=l.children(".next");V.hover(function(){a(this).addClass("nextactive")},function(){a(this).removeClass("nextactive")});U.click(function(){L.stopAutoPlay();L.loadPhotoAt(p-1)});V.click(function(){L.stopAutoPlay();L.loadPhotoAt(p+1)});m.click(function(){v=x-1;L.autoPlay(true)})}else{l.hide()}if(c.mousewheel){c.mousewheel(function(a,b){this.stopAutoPlay();if(b>0)this.loadPhotoAt(p-1);else if(b<0)this.loadPhotoAt(p+1);return false})}if(b.autoHide){s=window.setInterval(n+".onAutoHideInterval()",1e3);c.mouseover(this.showControls,null)}return})}})(jQuery)
