/*
* @file
* @brief    boxplus image transition engine
* @author   Levente Hunyadi
* @version  1.3.0
* @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.noConflict()}(function(c){var a="boxplus-disabled";c.fn.maxWidth=function(){var d=0;this.each(function(e,f){d=Math.max(d,c(f).safeWidth())});return d};c.fn.maxHeight=function(){var d=0;this.each(function(e,f){d=Math.max(d,c(f).safeHeight())});return d};function b(f,e){var d=parseInt(f.css(e));return isNaN(d)?f[e]():d}c.fn.safeWidth=function(){return b(this,"width")};c.fn.safeHeight=function(){return b(this,"height")};c.fn.boxplusTransition=function(e){var f={navigation:"horizontal",loop:true,slices:15,orientation:"vertical",effect:"fade",easing:"swing",duration:500,delay:4000};e=c.extend(f,e);var d=this.filter("ul, ol");d.each(function(){var k=e.navigation=="vertical";var t=e.orientation=="horizontal";var G=e.slices;var h=e.duration;var F=e.delay;var r=0;var z=false;var B=c(this).wrap("<div />").css("visibility","hidden");var w=c("li",B).find("img:first");var u=B.parent().addClass("boxplus-transition").addClass(a);var C=w.length;var p=w.maxWidth();var y=w.maxHeight();u.css({width:p,height:y});switch(e.navigation){case"horizontal":case"vertical":var l="boxplus-"+e.navigation;u.addClass(l);function s(J){return'<div class="boxplus-'+J+'" />'}u.prepend(c(s("prev")+s("next")).addClass(l).addClass((k?p:y)<120?"boxplus-small":"boxplus-large"));c(".boxplus-prev",u).click(D);c(".boxplus-next",u).click(m)}var I=(t?y:p)/G;for(var H=0;H<G;H++){var A=H*I;c('<div class="boxplus-transition-bars" />').css({left:t?0:A,top:t?A:0,height:t?I:y,width:t?p:I,visibility:"hidden"}).appendTo(u)}i();u.click(v).removeClass(a);n();if(F>0){F=Math.max(F,h+500);var x=window.setInterval(m,F);u.hover(function(){window.clearInterval(x)},function(){x=window.setInterval(m,F)})}function v(){w.eq(r).click()}function n(){return j("first")}function D(){return j("prev")}function m(){return j("next")}function E(){return j("last")}function o(L,J,M){var K=w.eq(r);L.css({backgroundImage:'url("'+K.attr("src")+'")',backgroundPosition:((p-K.safeWidth())/2-J)+"px "+((y-K.safeHeight())/2-M)+"px"})}function q(K){var J=K.attr("longdesc");if(J){K.attr("src",J).attr("longdesc","")}}function g(){q(w.eq(r));q(w.eq((r-1)%C));q(w.eq((r+1)%C))}function j(N){var L=c(".boxplus-transition-bars",u);if(z){o(u,0,0);L.clearQueue().stop().css("visibility","hidden")}z=true;switch(N){case"first":r=0;break;case"prev":r=(r-1)%C;break;case"next":r=(r+1)%C;break;case"last":r=C-1;break;default:return}i();g();L.css({height:t?I:y,width:t?p:I,opacity:1}).each(function(){var R=c(this);var Q=R.position();o(R,Q.left,Q.top)});function P(){L.css("opacity",0).show();return{opacity:1}}function M(){L.css(t?"width":"height",0);if(t){return{width:p}}else{return{height:y}}}function J(){L.css(t?"height":"width",0);if(t){return{height:I}}else{return{width:I}}}var O;switch(e.effect){case"fade":O=P();break;case"bars":O=M();break;case"bars+fade":O=c.extend(M(),P());break;case"shutter":O=J();break;case"shutter+fade":O=c.extend(J(),P());break}L.css("visibility","visible");var K=function(Q){return Q};switch(N){case"first":case"prev":K=function(Q){return G-1-Q};break}L.each(function(S){var Q=K(S);var R={duration:500,easing:e.easing};if(Q==G-1){c.extend(R,{complete:function(){z=false;o(u,0,0);L.css("visibility","hidden")}})}c(this).delay(Q*h/G).animate(O,R)});return false}function i(){if(!e.loop){c(".boxplus-prev",u).toggleClass(a,r<=0);c(".boxplus-next",u).toggleClass(a,r>=C-1)}}});return this}})(__jQuery__);
