/**
 * Slideshowify is a jQuery plugin for generating a full-screen (well, browser dims) slideshow 
 * from images that match a selector. Images that don't fit the window proportions exactly (generally
 * the case) are cropped and panned across the screen.
 *
 * Author: Aleksandar Kolundzija 
 * version 0.8
 *
 * Should appear on subchild.com, github, and jQuery plugins page at some point soon.
 * Will likely be used on Gallerama.com in some shape or form as well.
 * 
 * @TODO add more configuration options: direction, css3 prog enhancement stuff
 * @TODO consider adding option to pass image data directly to $.slideshowify()
 * @TODO add zooming
 * @TODO use css3 animation if available
 */
(function(a){a.fn.slideshowify=function(){function j(b){var e=a(document),f=a(this),j=e.width(),l=e.height(),m=j/l,n=f.width()/f.height(),o=i.aniSpeedMin;n>m?(f.height(l+"px").width(b.w*(l/b.h)+"px"),marginPixels=(f.width()-j)*g,g===1?(f.css({"margin-left":marginPixels*-1+"px"}),marginAttr={"margin-left":"0px"}):marginAttr={"margin-left":marginPixels+"px"},i.direction==="alternate"&&(g*=-1)):(f.width(j+"px").height(b.h*(j/b.w)+"px"),marginPixels=(f.height()-l)*h,h===1?(f.css({"margin-top":marginPixels*-1+"px"}),marginAttr={"margin-top":"0px"}):marginAttr={"margin-top":marginPixels+"px"},i.direction==="alternate"&&(h*=-1)),o=Math.min(Math.max(marginPixels*50,i.aniSpeedMin),i.aniSpeedMax),f.fadeIn(i.fadeInSpeed,function(){f.css("z-index",-1),i.afterFadeIn(c[d])}).animate(marginAttr,{duration:o,queue:!1,complete:function(){i.beforeFadeOut(c[d]),a(this).fadeOut(i.fadeOutSpeed,function(){a(this).remove()}),k()}})}function k(){var b=new Image,g=new Image,h=c.length;d=d<h-1?d+1:0,clearTimeout(f),a(b).load(function(){i.transition==="into"?(a(this).css({position:"absolute","z-index":"-2"}),a("#"+i.containerId).append(this)):a("#"+i.containerId).empty().append(this),j.call(this,c[d])}).error(function(){throw new Error("Oops, can't load the image.")}).hide().attr("src",c[d].src),e=d+1,e<h-1&&(g.src=c[e].src)}var b=this,c=[],d=-1,e=0,f,g=-1,h=-1,i={containerId:"slideshowify-bg",containerCss:{position:"absolute",overflow:"hidden","z-index":"-2",left:"0",top:"0",width:"100%",height:"100%"},transition:"into",direction:"alternate",fadeInSpeed:2e3,fadeOutSpeed:2e3,aniSpeedMin:6e3,aniSpeedMax:8e3,afterFadeIn:function(){},beforeFadeOut:function(){}};return arguments[0]&&a.extend(i,arguments[0]),i.imgs?c=i.imgs:a(this).each(function(b,d){a(d).hide(),c.push({src:a(d).attr("src"),w:a(d).width(),h:a(d).height()})}),a("<div id='"+i.containerId+"'></div>").css(i.containerCss).appendTo("body"),k(),this}})(jQuery),$.slideshowify=function(a){var b=this,c={randomize:!1,dataUrl:"",dataType:"json",async:!0,filterFn:function(a){return a}};$.extend(c,a),$.ajax({url:c.dataUrl,dataType:c.dataType,async:c.async,success:function(a){c.imgs=c.filterFn(a),c.randomize&&c.imgs.sort(function(){return.5-Math.random()}),$({}).slideshowify(c)}})}
