/*
 boxplus image transition engine
 @author  Levente Hunyadi
 @version 1.3.1
 @remarks Copyright (C) 2009-2010 Levente Hunyadi
 @remarks Licensed under GNU/GPLv3, see http://www.gnu.org/licenses/gpl-3.0.html
 @see     http://hunyadi.info.hu/projects/boxplus
*/
if(typeof __jQuery__=="undefined")var __jQuery__=jQuery;
(function(b){function F(a,p){var g=parseInt(a.css(p));return isNaN(g)?a[p]():g}var x="boxplus-disabled",z=Math.max,G=Math.floor,A=Math.ceil;b.fn.maxWidth=function(){var a=0;this.each(function(p,g){a=z(a,b(g).safeWidth())});return a};b.fn.maxHeight=function(){var a=0;this.each(function(p,g){a=z(a,b(g).safeHeight())});return a};b.fn.safeWidth=function(){return F(this,"width")};b.fn.safeHeight=function(){return F(this,"height")};b.fn.boxplusTransition=function(a){a=b.extend({navigation:"horizontal",
loop:true,contextmenu:true,orientation:"vertical",slices:15,effect:"fade",easing:"swing",duration:500,delay:4E3},a);this.filter("ul, ol").each(function(){function p(){return B("prev")}function g(){return B("next")}function C(h,j,y){var q=k.eq(e);h.css({backgroundImage:'url("'+q.attr("src")+'")',backgroundPosition:(n-q.safeWidth())/2-j+"px "+((o-q.safeHeight())/2-y)+"px"})}function D(h){var j=h.attr("longdesc");j&&h.attr("src",j).attr("longdesc","")}function B(h){function j(){l.css("opacity",0).show();
return{opacity:1}}function y(){l.css(f?"width":"height",0);return f?{width:n}:{height:o}}function q(){l.css(f?"height":"width",0);return f?{height:A(m)}:{width:A(m)}}var l=b(".boxplus-transition-bars",d);if(E){C(d,0,0);l.clearQueue().stop().css("visibility","hidden")}E=true;switch(h){case "first":e=0;break;case "prev":e=(e-1)%r;break;case "next":e=(e+1)%r;break;case "last":e=r-1;break;default:return}H();D(k.eq(e));D(k.eq((e-1)%r));D(k.eq((e+1)%r));l.css({opacity:1}).each(function(c){var s=b(this);
c=A(c*m+m)-G(c*m);s.css({height:f?c:o,width:f?n:c});c=s.position();C(s,c.left,c.top)});var t;switch(a.effect){case "fade":t=j();break;case "bars":t=y();break;case "bars+fade":t=b.extend(y(),j());break;case "shutter":t=q();break;case "shutter+fade":t=b.extend(q(),j())}l.css("visibility","visible");var I=function(c){return c};switch(h){case "first":case "prev":I=function(c){return u-1-c}}l.each(function(c){c=I(c);var s={duration:500,easing:a.easing};c==u-1&&b.extend(s,{complete:function(){E=false;C(d,
0,0);l.css("visibility","hidden")}});b(this).delay(c*J/u).animate(t,s)});return false}function H(){if(!a.loop){b(".boxplus-prev",d).toggleClass(x,e<=0);b(".boxplus-next",d).toggleClass(x,e>=r-1)}}var v=a.navigation=="vertical",f=a.orientation=="horizontal",u=a.slices,J=a.duration,w=a.delay,e=0,E=false,i=b(this).wrap("<div />").before("<div />").css("visibility","hidden"),L=i.parent().addClass("boxplus-transition-wrapper"),k=b("li",i).css({position:"absolute",left:0,top:0}).find("img:first"),d=i.prev().addClass("boxplus-transition").addClass(x),
r=k.length,n=k.maxWidth(),o=k.maxHeight();L.add(d).css({width:n,height:o});switch(a.navigation){case "horizontal":case "vertical":i="boxplus-"+a.navigation;d.addClass(i);d.prepend(b('<div class="boxplus-prev" /><div class="boxplus-next" />').addClass(i).addClass((v?n:o)<120?"boxplus-small":"boxplus-large"));b(".boxplus-prev",d).click(p);b(".boxplus-next",d).click(g)}a.contextmenu||b(document).bind("contextmenu",function(h){return!d.children().add(d).filter(h.target).size()});var m=(f?o:n)/u;for(v=
0;v<u;v++){i=G(v*m);b('<div class="boxplus-transition-bars" />').css({left:f?0:i,top:f?i:0,height:f?m:o,width:f?n:m,visibility:"hidden"}).appendTo(d)}H();d.click(function(){k.eq(e).click()}).removeClass(x);B("first");if(w>0){w=z(w,J+500);var K=window.setInterval(g,w);d.mouseover(function(){window.clearInterval(K)}).mouseout(function(){K=window.setInterval(g,w)})}});return this}})(__jQuery__);

