/*
* @file
* @brief    boxplus image slider 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.noConflict()}(function(b){var a="boxplus-disabled";b.fn.maxOuterWidth=function(){var c=0;this.each(function(d,e){c=Math.max(c,b(e).outerWidth(true))});return c};b.fn.maxOuterHeight=function(){var c=0;this.each(function(d,e){c=Math.max(c,b(e).outerHeight(true))});return c};b.fn.boxplusSlider=function(d){var e={rowCount:1,columnCount:2,orientation:"horizontal",navigation:"top",showButtons:true,showLinks:true,showPageCounter:true,showOverlayButtons:true,contextmenu:true,duration:800,delay:0,opacity:1};d=b.extend(e,d);var c=this.filter("ul, ol");c.each(function(){var m=d.rowCount;var B=d.columnCount;var k=m*B;var u=d.duration;var x=d.delay;var L=0;var w=b(this).wrap("<div />");var M=w.parent().addClass("boxplus-slider").addClass(a);M.wrapInner('<div class="boxplus-viewport" />');var E=b("li:visible",w);var q=E.find("img:first");var g=q.maxOuterWidth();var N=q.maxOuterHeight();E.css({width:g,height:N});g=E.maxOuterWidth();N=E.maxOuterHeight();function z(T,U,r){for(D=0;D<T;D++){for(Q=0;Q<U;Q++){E.eq(r?D*U+Q:Q*T+D).css({left:Q*g,top:D*N})}}}var H=E.length;var K,o,D,Q;var v=d.orientation=="vertical";if(v){o=B;K=Math.ceil(H/B);z(K,o,true)}else{o=Math.ceil(H/m);K=m;z(K,o)}w.css({width:o*g,height:K*N});b(".boxplus-viewport",M).css({width:B*g,height:m*N});M.css("width",B*g);function P(r){return'<a class="boxplus-'+r+'" href="javascript:void(0)" />'}function S(r){return'<div class="boxplus-'+r+'" />'}function t(T,r){return'<span class="boxplus-'+T+'">'+r+"</span>"}var O='<div class="boxplus-paging">'+(d.showButtons?S("first")+S("prev"):"")+(d.showLinks?P("first")+"&nbsp;"+P("prev")+" ":"")+(d.showPageCounter?t("current",1)+" / "+t("total",Math.ceil(H/k)):"")+(d.showLinks?" "+P("next")+"&nbsp;"+P("last"):"")+(d.showButtons?S("next")+S("last"):"")+"</div>";switch(d.navigation){case"both":M.prepend(O).append(O);break;case"top":M.prepend(O);break;default:M.append(O)}if(d.showOverlayButtons){b(".boxplus-viewport",M).append(b(S("prev")+S("next")).addClass((v?g:N)<120?"boxplus-small":"boxplus-large").addClass(v?"boxplus-vertical":"boxplus-horizontal"))}if(!d.contextmenu){b(document).bind("contextmenu",function(r){return !q.filter(r.target).size()})}var A=b(".boxplus-first",M).click(f);var s=b(".boxplus-prev",M).click(J);var R=b(".boxplus-next",M).click(p);var h=b(".boxplus-last",M).click(y);E.addClass("boxplus-loading").children().addClass(a);C(E.not(j(E).one("boxplus-load",l).get()));i();M.removeClass(a);w.css({top:0,left:0,visibility:"visible"});if(d.opacity<1){q.css("opacity",d.opacity);q.hover(function(){b(this).stop().animate({opacity:1},"slow")},function(){b(this).stop().animate({opacity:d.opacity},"slow")})}if(x>0){x=Math.max(x,u);var n=window.setInterval(F,x);M.mouseover(function(){window.clearInterval(n)}).mouseout(function(){n=window.setInterval(F,x)})}function j(r){return r.filter(function(){return/\.(gif|jpe?g|png)$/i.test(b("img:first",this).attr("longdesc"))})}function C(r){j(r).each(function(){var T=b("img:first",this);T.attr("src",T.attr("longdesc")).attr("longdesc","")});r.removeClass("boxplus-loading").children().removeClass(a);G()}function l(r){var U=b(r.target);var T=b("img:first",U);b(new Image()).load(function(){C(U)}).attr("src",T.attr("longdesc"))}function G(){E.slice(L,L+k).mouseenter().mouseleave()}function F(){I("cycle")}function f(){I("first")}function J(){I("prev")}function p(){I("next")}function y(){I("last")}function I(T){var V=H%k?H-H%k:H-k;switch(T){case"first":L=0;break;case"prev":L=(L>=k)?L-k:0;break;case"next":L=(L<V)?L+k:V;break;case"last":L=V;break;case"cycle":L=(L>=V)?0:L+k;break;default:return}var U=Math.max(0,L-k);var r=Math.min(H,L+2*k);E.slice(0,U).detach();E.slice(r).detach();var W=v?{top:-(L/B*N)}:{left:-(L/m*g)};switch(T){case"first":case"last":w.css(b.extend(W,{opacity:0}));i();w.prepend(E.slice(0,U)).append(E.slice(r));w.animate({opacity:1},u,"linear");break;default:i();w.animate(W,u,"swing",function(){w.prepend(E.slice(0,U)).append(E.slice(r))})}}function i(){var U=H%k?H-H%k:H-k;s.add(A).toggleClass(a,L<=0);R.add(h).toggleClass(a,L>=U);b(".boxplus-current",M).text(L/k+1);var T=Math.max(0,L-k);var r=Math.min(H,L+2*k);E.slice(T,r).trigger("boxplus-load");G()}});return this}})(__jQuery__);
