(function($){$.fn.ncGallery=function(options){opts=$.extend({},$.fn.ncGallery.defaults,options);opts.thumbDisplayed=opts.thumbDisplayed||$.fn.ncGallery.thumbDisplayed;opts.getCaption=opts.getCaption||$.fn.ncGallery.getCaption;opts.displayCaption=opts.displayCaption||$.fn.ncGallery.displayCaption;if(opts.lgContainer==null){wrapper=$('<div>').insertBefore(this)}else{wrapper=$(opts.lgContainer)}if(wrapper.css('position')=='static'){wrapper.css('position','relative')}opts.before=opts.before?[opts.before]:[];opts.after=opts.after?[opts.after]:[];var transition=$.fn.ncGallery.transitions['simple'];if(opts.fx!=undefined){transition=$.fn.ncGallery.transitions[opts.fx]}if(!$.isFunction(transition)){return}transition();opts.cssBefore=opts.cssBefore||false;opts.cssAfter=opts.cssAfter||false;opts.animateIn=opts.animateIn||{};opts.animateOut=opts.animateOut||{};if(opts.easing){opts.easingIn=opts.easingOut=opts.easing}if(opts.speed){opts.speedIn=opts.speedOut=opts.speed}opts.after.push(function(previous,current,opts,data){if(opts.cssAfter){next.css(opts.cssAfter)}});matchedSet=$(this);return matchedSet.each(function(){$(this).find(opts.tbContainer).each(function(i){var container=$(this);var link=container.find('a');if(!link.is('a')){link=false}var thumb=container.find('img').css('display','none');var src=link?link.attr('href'):thumb.attr('src');var title=link?link.attr('title'):thumb.attr('title');var loader=new Image();$(loader).load(function(){var lgImg=$(this);lgImg.attr('alt',thumb.attr('alt'));thumb.bind(opts.thumbEvent,function(){loadImg(src,$(this),container);return false});if(opts.thumbEvent!='click'){thumb.click(function(){return false})}thumb.hover(function(){$(this).addClass(opts.hoverClass)},function(){$(this).removeClass(opts.hoverClass)});container.hover(function(){$(this).addClass(opts.hoverClass)},function(){$(this).removeClass(opts.hoverClass)});thumb.css('display','block');var data={thumb:thumb,thumbContainer:container,matchedSet:matchedSet,image:lgImg};opts.thumbDisplayed(data);if(opts.displayFirst){if(i==0){loadImg(src,thumb,container)}}else if(thumb.is('.active')){loadImg(src,thumb,container)}}).error(function(){container.empty().html('<span style="color: red">Could not load image "'+src+'".</span>')}).attr('src',src)})})};var opts={};var matchedSet=null;var wrapper=null;var currentLarge=null;function loadImg(src,thumb,thumbContainer){if(currentLarge==src){return}currentLarge=src;matchedSet.find('.'+opts.activeClass).removeClass('active');thumb.addClass(opts.activeClass);thumb.parents(opts.tbContainer).filter(':first').addClass(opts.activeClass);data={caption:'',thumb:thumb,thumbContainer:thumbContainer,image:null,matchedSet:matchedSet};data.caption=opts.getCaption(data);var img=new Image();$(img).load(function(){var current=$('img',wrapper);data.image=$(this);changeImage(current,$(this),data);opts.displayCaption(data)}).attr('src',src)};function changeImage(current,next,data){current.css('z-index',2);next.css({position:'absolute',top:0,left:0,zIndex:1});wrapper.append(next);if(opts.click){next.bind('click',function(){opts.click(opts,data)})}if(opts.before.length){$.each(opts.before,function(i,func){func.apply(next,[current,next,opts,data])})};if(opts.cssBefore){next.css(opts.cssBefore)}var fnIn=function(){next.animate(opts.animateIn,opts.speedIn,opts.easeIn,function(){if(opts.after.length){$.each(opts.after,function(i,func){func.apply(next,[current,next,opts,data])})}})};if(current.length>0){if(opts.animateOut){current.animate(opts.animateOut,opts.speedOut,opts.easeOut,function(){if(!opts.sync){fnIn()}current.remove()})}else{if(!opts.sync){fnIn()}}if(opts.sync){fnIn()}}else{fnIn()}};$.fn.ncGallery.thumbDisplayed=function(data){};$.fn.ncGallery.getCaption=function(data){return data.thumb.attr('title')};$.fn.ncGallery.displayCaption=function(data){if(opts.caption!=undefined){$(opts.caption).html(data.caption)}};$.fn.ncGallery.transitions={simple:function(){opts.before.push(function(){this.show()});opts.animateIn={opacity:1};opts.animateOut={opacity:0};opts.cssBefore={opacity:0};opts.speed=1},fade:function(){opts.before.push(function(){this.show()});opts.animateIn={opacity:1};opts.animateOut={opacity:0};opts.cssBefore={opacity:0}},scrollUp:function(){wrapper.css('overflow','hidden');opts.before.push(function(current,next,opts){this.show();opts.cssBefore.top=next.css('height');if(current.length>0){current=current.get(0);opts.animateOut.top=0-current.offsetHeight}});opts.cssBefore={top:0};opts.animateIn={top:0}},scrollDown:function(){wrapper.css('overflow','hidden');opts.before.push(function(current,next,opts){this.show();opts.cssBefore.top=0-next.get(0).offsetHeight;if(current.length>0){opts.animateOut.top=current.get(0).offsetHeight}});opts.cssBefore={top:0};opts.animateIn={top:0}},scrollLeft:function(){wrapper.css('overflow','hidden');opts.before.push(function(current,next,opts){this.show();opts.cssBefore.left=next.get(0).offsetWidth;if(current.length>0){opts.animateOut.left=0-current.get(0).offsetWidth}});opts.cssBefore={left:0};opts.animateIn={left:0}},scrollRight:function(){wrapper.css('overflow','hidden');opts.before.push(function(current,next,opts){this.show();opts.cssBefore.left=0-next.get(0).offsetWidth;if(current.length>0){opts.animateOut.left=current.get(0).offsetWidth}});opts.cssBefore={left:0};opts.animateIn={left:0}},turnDown:function(){opts.before.push(function(current,next,opts){this.show();current.css('z-index',1);opts.cssBefore.width=next.width();opts.animateIn.height=next.height()});opts.cssBefore={top:0,height:0,zIndex:2};opts.after.push(function(previous){previous.remove()})},turnRight:function(){opts.before.push(function(current,next,opts){this.show();current.css('z-index',1);opts.cssBefore.height=next.height();opts.animateIn.width=next.width()});opts.cssBefore={left:0,width:0,zIndex:2};opts.after.push(function(previous){previous.remove()})},curtainX:function(){opts.before.push(function(current,next,opts){next=next.get(0);if(current.length>0){current.css('zIndex',2);current=current.get(0);opts.animateOut={left:current.width/2,width:0,height:current.height}}opts.cssBefore={left:next.width/2,width:0,height:next.height,zIndex:1,display:'block'};opts.animateIn={left:0,width:next.width}});opts.sync=0},curtainY:function(){opts.before.push(function(current,next,opts){next=next.get(0);if(current.length>0){current.css('zIndex',2);current=current.get(0);opts.animateOut={top:current.height/2,height:0,width:current.width}}opts.cssBefore={top:next.height/2,height:0,width:next.width,zIndex:1,display:'block'};opts.animateIn={top:0,height:next.height}});opts.sync=0}};$.fn.ncGallery.defaults={tbContainer:'li',lgContainer:null,caption:null,activeClass:'active',hoverClass:'hover',displayFirst:1,thumbEvent:'click',before:null,after:null,fx:'fade',cssBefore:null,cssAfter:null,easing:null,easingIn:null,easingOut:null,speed:1000,speedIn:null,speedOut:null,animateIn:null,animateOut:null,sync:1,thumbDisplayed:null,getCaption:null,displayCaption:null,click:null};function debug(){if(window.console&&window.console.log){window.console.log('[ncGallery] '+Array.prototype.join.call(arguments,''))}}})(jQuery);