(function(e){e.fn.sudoSlider=function(g){if(typeof g!="object"&&g!=""&&g)this.each(function(){e(this).trigger("sudoSliderEvent",[g])});else{g=e.extend({prevNext:true,prevHtml:'<a href="#" class="prevBtn"> previous </a>',nextHtml:'<a href="#" class="nextBtn"> next </a>',controlsShow:true,controlsAttr:'id="controls"',controlsFadeSpeed:"400",controlsFade:true,insertAfter:true,firstShow:false,firstHtml:'<a href="#" class="firstBtn"> first </a>',lastShow:false,lastHtml:'<a href="#" class="lastBtn"> last </a>', numericAttr:'class="controls"',numericText:["1"],vertical:false,speed:"800",ease:"swing",auto:false,pause:"2000",continuous:true,clickableAni:false,numeric:false,updateBefore:false,history:false,speedhistory:"400",autoheight:true,customLink:false,fade:false,crossFade:true,fadespeed:"500",ajax:false,loadingText:false,preloadAjax:false,startSlide:false,imgAjaxFunction:false,docAjaxFunction:false,beforeAniFunc:false,afterAniFunc:false,uncurrentFunc:false,currentFunc:false},g);var L=g.controlsFadeSpeed, ha=g.controlsFade,ia=g.firstShow,ja=g.lastShow,V=g.vertical,E=g.speed,$=g.ease,A=g.auto,M=g.pause,F=g.continuous,ka=g.prevNext,Ba=g.numeric,Ca=g.numericAttr,B=g.numericText,N=g.history,O=g.speedhistory,P=g.autoheight,C=g.customLink,Da=g.fade,la=g.crossFade,v=g.fadespeed,aa=g.updateBefore,i=g.ajax,ma=g.startSlide,na=g.imgAjaxFunction,oa=g.docAjaxFunction,Q=g.beforeAniFunc,G=g.afterAniFunc,pa=g.uncurrentFunc,qa=g.currentFunc;return this.each(function(){function Ea(){var b=["Spinning up the hamster", "Programming the flux capacitor","Testing data on Timmy... ... ... We need another Timmy","Warming up Large Hadron Collider","It looks like you're waiting for something to load"];return g.loadingText?g.loadingText:b[Math.round(Math.random()*(b.length-1))]+"..."}function R(b,d){W||(Da?Fa(b,d):H(b,d,true))}function X(b,d){var f=e(b);S.prepend(f);f.click(function(){R(d,true);return false});return f}function T(b){if(parseInt(b))b=parseInt(b);else switch(b){case "fast":b=200;break;case "normal":b=400; break;case "medium":b=400;break;case "slow":b=600;break;default:b=400}return b}function ba(b,d){b.each(function(){var f=this.tagName.toLowerCase()==="img"?e(this):e("img",this),c=this,j=0,r=function(){typeof d==="function"&&d(c)};f.length?f.each(function(){var s=this,I=function(w){if(s.complete||s.readyState=="complete"&&w.type=="readystatechange")++j===f.length&&r();else s.readyState===undefined&&e(s).attr("src",e(s).attr("src"))};e(s).bind("load readystatechange",function(w){I(w)});I({type:"readystatechange"})}): r()})}function ra(b){var d=false,f=b.length,c=b.substr(f-4,4);if(c==".jpg"||c==".png"||c==".bmp"||c==".gif")d=true;c=b.substr(f-5,5);if(c==".jpeg")d=true;return d}function Y(b,d,f){if(f){f=Ga;var c=Ha,j="next",r="last",s=ja}else{f=Ia;c=Ja;j="prev";r="first";s=ia}if(!F){ka&&f.fadeTo(d,b,function(){b==0&&e(this).hide()});s&&c.fadeTo(d,b,function(){b==0&&e(this).hide()});C&&e(C).filter(function(){return e(this).attr("rel")==j||e(this).attr("rel")==r}).fadeTo(d,b,function(){b==0&&e(this).hide()})}}function sa(b, d){b==0?Y(0,d,false):Y(1,d,false);b==m?Y(0,d,true):Y(1,d,true)}function ca(b){b=parseInt(b>m?b=0:b<0?b=m:b)+1;for(var d=0;d<da.length;d++)ta(da[d],b);C&&ta(C,b)}function ta(b,d){e(b).filter(".current").removeClass("current").each(function(){e.isFunction(pa)&&pa.call(this,e(this).attr("rel"))});e(b).filter(function(){return e(this).attr("rel")==d}).addClass("current").each(function(){e.isFunction(qa)&&qa.call(this,d)})}function ua(b){for(var d=0,f=0;f<=n;f+=1)if(B[f]==b)d=f;return d}function J(b,d){if(b== n)b=0;var f=o.eq(b),c=f.height();c!=0&&va(c,d);ba(f,function(j){c=e(j).height();c!=0&&va(c,d)})}function va(b,d){q.animate({height:b},{queue:false,duration:d,easing:$})}function wa(){if(h>m)h=0;if(h<0)h=m;aa||ca(h);V?l.css("margin-top",h*U*-1):l.css("margin-left",h*y*-1);t=true;if(N&&xa)window.location.hash=B[h];x||e.isFunction(G)&&G.call(o.eq(h),h+1)}function ea(b,d){var f=h;switch(b){case "next":f=d>=m?F?f+1:m:f+1;break;case "prev":f=h<=0?F?f-1:0:f-1;break;case "first":f=0;break;case "last":f=m; break;default:f=parseInt(b)}return f}function u(b,d,f,c){var j=false;j=parseInt(b)||b==0?o.eq(b):b=="last"?e("li:last",q):e("li:first",q);var r=x?!la?parseInt(v*0.4):v:c,s=d+1;if(ra(i[d])){j.html(" ").append(e(new Image).attr("src",i[d]));ba(j,function(I){var w=e(I).children(),D=w.width(),ya=w.height();w.attr({oldheight:ya,oldwidth:D});D>y&&w.animate({width:y,height:ya/D*y},0);e.isFunction(na)&&na.call(e(I),s);P&&f&&J(h,r)})}else j.load(i[d],function(I,w,D){if(w=="error"||!e(this).html())e(this).html("Sorry but there was an error: "+ (D.status?D.status:"no content")+" "+D.statusText);w!="error"&&e.isFunction(oa)&&oa.call(e(this),s);e(this).height();P&&f&&J(d,r)})}function Fa(b,d){if(b!=h&&!W)if(t){Z=false;d&&clearTimeout(K);aa&&ca(ea(b,z));t=!d;var f=!d&&!A&&N?v*(O/E):v,c=ea(b,z);if(c>m)c=0;if(c<0)c=m;ha&&sa(c,L);if(P)if(i)i[c]||J(c,v);else J(c,v);var j=o.eq(c);e.isFunction(Q)&&Q.call(j,c+1);if(la){var r=j.clone().prependTo(q).css({"z-index":"100000",position:"absolute","list-style":"none",top:"0",left:"0"});if(i[c]){u(0,c,false, f);if(ra(i[c])){u(c+1,c,false,f);ba(o.eq(c+1),function(){P&&J(c,v)})}else u(c+1,c,true,f);i[c]=false}r.hide().fadeIn(v,function(){x=t=true;H(b,false,false);e(this).remove();if(N&&d)window.location.hash=B[h];x=false;e.isFunction(G)&&G.call(j,c+1)})}else{var s=parseInt(f*0.6);f=f-s;q.children().fadeTo(f,1.0E-5,function(){x=t=true;H(b,false,false);t=!d;q.children().fadeTo(s,1,function(){if(N&&d)window.location.hash=B[h];t=true;x=false;e.isFunction(G)&&G.call(j,c+1)})})}}}function H(b,d,f){if(t&&!W){Z= false;t=!d&&!A?true:g.clickableAni;xa=d;z=h;h=ea(b,z);aa&&ca(h);var c=Math.sqrt(Math.abs(z-h)),j=parseInt(c*E);if(!d&&!A)j=parseInt(c*O);f||(j=0);c=h;if(h>m)c=0;if(h<0)c=m;if(i){if(i[c]){u(c,c,true,j);i[c]=false;Z=true}if(!x){var r=0;if(z>h)for(a=h;a<=z;a++){if(a<=m&&a>=0)if(i[a]){u(a,a,false,j);i[a]=false;r++}if(r==10)a=z}else for(a=z;a<=h;a++){if(a<=m&&a>=0)if(i[a]){u(a,a,false,j);i[a]=false;r++}if(r==10)a=h}}if(c+1<=m&&!fa)if(i[c+1]){u(c+1,c+1,false,0);i[c+1]=false}if(c-1>=0&&!fa)if(i[c-1]){u(c- 1,c-1,false,0);i[c-1]=false}}if(!x)if(e.isFunction(Q)){Q.call(o.eq(c),c+1);if(h==-1||h==n)Q.call(l.children("li").eq(h==-1?0:-1),c+1)}if(V){p=h*U*-1;l.animate({marginTop:p},{queue:false,duration:j,easing:$,complete:wa})}else{P&&!x&&!Z&&J(h,j);p=h*y*-1;l.animate({marginLeft:p},{queue:false,duration:j,easing:$,complete:wa})}if(ha){j=L;if(!d&&!A)j=O/E*L;f||(j=0);if(x)j=parseInt(v*0.6);sa(h,j)}d&&clearTimeout(K);if(A&&b=="next"&&!d)K=ga(M+E)}}function ga(b){return setTimeout(function(){R("next",false)}, b)}function za(b){if(b=="stop")clearTimeout(K);else if(b=="start"){K=ga(M);A=true}else if(b=="block")t=false;else if(b=="unblock")t=true;else if(b=="action")alert("The slider just performed an action");else if(b=="destroy"){S.remove();W=true;e(C).die("click");if(F){l.children("li").eq(0).remove();l.children("li").eq(-1).remove()}}else if(t)R(b==parseInt(b)?b-1:b,true)}var fa=true;if(A)F=true;var q=e(this),l=q.children("ul"),o=l.children("li"),n=o.length,y=o.eq(0).width(),U=q.height();if(i){if(l.length== 0){q.append("<ul></ul>");l=q.children("ul")}if(i.length>n){for(var k=1;k<=i.length-n;k++)l.append("<li><p>"+Ea()+"</p></li>");o=l.children("li");n=o.length;y=o.eq(0).width()}}var h=0,z=h,m=n-1,t=true,xa=false,x=false,Z=false,da=[],Aa=false,W=false;q.css("overflow","hidden");q.css("position")=="static"&&q.css("position","relative");o.css("float","left");for(k=0;k<n;k++){if(B[k]==undefined)B[k]=k+1;if(i&&i[k]==undefined)i[k]=false}if(F){if(V){l.prepend(o.filter(":last-child").clone().css("margin-top", "-"+U+"px"));l.append(o.filter(":nth-child(2)").clone());l.height((n+1)*U)}else{l.prepend(o.filter(":last-child").clone().css("margin-left","-"+y+"px"));l.append(o.filter(":nth-child(2)").clone());l.width((n+1)*y)}if(i){i[0]&&u("last",0,false,0);if(i[n-1]){u("first",n-1,false,0);u(m,m,false,0);i[n-1]=false}}}else V?l.height(n*U):l.width(n*y);if(g.controlsShow){var S=e("<span "+g.controlsAttr+"></span>");g.insertAfter?e(q).after(S):e(q).before(S);if(Ba){Aa=S.prepend("<ol "+Ca+"></ol>").children(); for(k=0;k<n;k++)da[k]=e(document.createElement("li")).attr({rel:k+1}).html('<a href="#"><span>'+B[k]+"</span></a>").appendTo(Aa).click(function(){R(e(this).attr("rel")-1,true);return false})}if(ia)var Ja=X(g.firstHtml,"first");if(ja)var Ha=X(g.lastHtml,"last");if(ka)var Ga=X(g.nextHtml,"next"),Ia=X(g.prevHtml,"prev")}if(g.preloadAjax)for(k=0;k<=m;k++)if(i[k]){u(k,k,false,0);i[k]=false}L=T(L);E=T(E);M=T(M);O=T(O);v=T(v);var K;if(A)K=ga(M);C&&e(C).live("click",function(){var b=e(this).attr("rel");b&& za(b);return false});q.bind("sudoSliderEvent",function(b,d){za(d)});fa=false;if(N)e.address.init(function(b){b=ua(b.value);H(b,false,false)}).change(function(b){b=ua(b.value);b!=h&&R(b,false)});else ma?H(ma-1,false,false):H(0,false,false)})}}})(jQuery);
