$.fn.imageMorph=(function(src,width,height,callback,SPEED){var SPEED=SPEED||300;return this.each(function(){var img=$(this),newImg=$('<img>'),throbber=img.parent().find('.throbber');if(img.hasClass('morpher')){img.remove();return;}
if(!throbber.length){throbber=$('<span class="throbber"></span>');img.parent().append(throbber);throbber.hide();}
var throbberTimeout=setTimeout(function(){throbber.show();},60);newImg.css({position:'absolute',top:0,left:0,width:img.width()+'px',height:img.height()+'px',opacity:0,cursor:'pointer'}).addClass('morpher');img.parent().append(newImg).css({width:img.width()+'px',height:img.height()+'px'});newImg.load(function(){var css={width:width+'px',height:height+'px',opacity:1};img.parent().stop().animate(css,SPEED);img.stop().animate(css,SPEED);clearTimeout(throbberTimeout);throbber.hide();newImg.animate(css,SPEED,function(){img.remove();newImg.removeClass('morpher');(callback||function(){})();});});newImg.attr('src',src);});});(function($){$(function(){$('.gallery').each(function(){var me=$(this),current=1,main,prev,next;function change(direction){if(typeof direction==='undefined'){if(current>=me.find('.images img').length){direction=-1*current+1;}
else{direction=1;}}
current=Math.min(Math.max(current+direction,1),me.find('.images img').length);var image=me.find('.images img').eq(current-1);main.find('img').imageMorph(image.attr('src'),image.attr('width'),image.attr('height'));prev.removeClass('inactive');next.removeClass('inactive');if(current===1){prev.addClass('inactive');}
else if(current===me.find('.images img').length){next.addClass('inactive');}
me.find('.caption p').text(image.attr('alt'));};function indicator_text(){return current+' of '+me.find('ul.thumbs li').length+' photos';};if(me.find('.images img').length){prev=$('<a>');next=$('<a>');me.find('.transport.prev').append(prev)
me.find('.transport.next').append(next);prev.click(function(){change(-1);});next.click(function(){change(1);});var initial=me.find('.images img').eq(0),img=initial.clone();main=$('<div>').html(img).addClass('main').css({height:initial.attr('height'),width:initial.attr('width'),cursor:'pointer'}).click(function(){change();});me.find('.transport.prev a').addClass('inactive');me.find('.images').before(main);me.find('.images').hide();}});});})(jQuery);
