/*
* CrossSlide jQuery plugin v0.6.2
*
* Copyright 2007-2010 by Tobia Conforto <tobia.conforto@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
(function(){var d=jQuery,e=(d.fn.startAnimation?"startAnimation":"animate"),b="pause plugin missing.";function a(g){for(var h=1;h<arguments.length;h++){g=g.replace(new RegExp("\\{"+(h-1)+"}","g"),arguments[h]);}return g;}function f(){arguments[0]="CrossSlide: "+arguments[0];throw new Error(a.apply(null,arguments));}function c(i){var h=1;var j=i.replace(/^\s*|\s*$/g,"").split(/\s+/);if(j.length>3){throw new Error();}if(j[0]=="center"){if(j.length==1){j=["center","center"];}else{if(j.length==2&&j[1].match(/^[\d.]+x$/i)){j=["center","center",j[1]];}}}if(j.length==3){h=parseFloat(j[2].match(/^([\d.]+)x$/i)[1]);}var g=j[0]+" "+j[1];if(g=="left top"||g=="top left"){return{xrel:0,yrel:0,zoom:h};}if(g=="left center"||g=="center left"){return{xrel:0,yrel:0.5,zoom:h};}if(g=="left bottom"||g=="bottom left"){return{xrel:0,yrel:1,zoom:h};}if(g=="center top"||g=="top center"){return{xrel:0.5,yrel:0,zoom:h};}if(g=="center center"){return{xrel:0.5,yrel:0.5,zoom:h};}if(g=="center bottom"||g=="bottom center"){return{xrel:0.5,yrel:1,zoom:h};}if(g=="right top"||g=="top right"){return{xrel:1,yrel:0,zoom:h};}if(g=="right center"||g=="center right"){return{xrel:1,yrel:0.5,zoom:h};}if(g=="right bottom"||g=="bottom right"){return{xrel:1,yrel:1,zoom:h};}return{xrel:parseInt(j[0].match(/^(\d+)%$/)[1])/100,yrel:parseInt(j[1].match(/^(\d+)%$/)[1])/100,zoom:h};}d.fn.crossSlide=function(l,g,k){var i=this,j=this.width(),m=this.height();if(i.length!=1){f("crossSlide() must be called on exactly 1 element");}i.get(0).crossSlideArgs=[l,g,k];g=d.map(g,function(n){return d.extend({},n);});if(!l.easing){l.easing=l.variant?"swing":"linear";}if(!k){k=function(){};}var h=true;(function(n){n();})(function(){if(!l.fade){f("missing fade parameter.");}if(l.speed&&l.sleep){f("you cannot set both speed and sleep at the same time.");}var p=Math.round(l.fade*1000);if(l.sleep){var s=Math.round(l.sleep*1000);}if(l.speed){var n=l.speed/1000,q=Math.round(p*n);}i.empty().css({overflow:"hidden",padding:0});if(!/^(absolute|relative|fixed)$/.test(i.css("position"))){i.css({position:"relative"});}if(!i.width()||!i.height()){f("container element does not have its own width and height");}if(l.shuffle){g.sort(function(){return Math.random()-0.5;});}function x(C){if(!C.src){f("missing src parameter in picture {0}.",o+1);}if(n){switch(C.dir){case"up":C.from={xrel:0.5,yrel:0,zoom:1};C.to={xrel:0.5,yrel:1,zoom:1};var z=C.height-m-2*q;break;case"down":C.from={xrel:0.5,yrel:1,zoom:1};C.to={xrel:0.5,yrel:0,zoom:1};var z=C.height-m-2*q;break;case"left":C.from={xrel:0,yrel:0.5,zoom:1};C.to={xrel:1,yrel:0.5,zoom:1};var z=C.width-j-2*q;break;case"right":C.from={xrel:1,yrel:0.5,zoom:1};C.to={xrel:0,yrel:0.5,zoom:1};var z=C.width-j-2*q;break;default:f("missing or malformed dir parameter in picture {0}.",o+1);}if(z<=0){f("impossible animation: either picture {0} is too small or div is too large or fade duration too long.",o+1);}C.time_ms=Math.round(z/n);}else{if(!s){if(!C.from||!C.to||!C.time){f("missing either speed/sleep option, or from/to/time params in picture {0}.",o+1);}try{C.from=c(C.from);}catch(B){f('malformed "from" parameter in picture {0}.',o+1);}try{C.to=c(C.to);}catch(B){f('malformed "to" parameter in picture {0}.',o+1);}if(!C.time){f('missing "time" parameter in picture {0}.',o+1);}C.time_ms=Math.round(C.time*1000);}}if(C.from){d.each([C.from,C.to],function(D,E){E.width=Math.round(C.width*E.zoom);E.height=Math.round(C.height*E.zoom);E.left=Math.round((j-E.width)*E.xrel);E.top=Math.round((m-E.height)*E.yrel);});}var A,y;y=A=d('<img src=""/>');if(C.href){y=d(a('<a href="{0}"></a>',C.href)).append(A);}if(C.onclick){y.click(C.onclick);}if(C.alt){A.attr("alt",C.alt);}if(C.rel){y.attr("rel",C.rel);}if(C.href&&C.target){y.attr("target",C.target);}y.appendTo(i);}for(var o=0;o<g.length;++o){x(g[o]);}delete n;function w(A,z){var y=[0,p/(A.time_ms+2*p),1-p/(A.time_ms+2*p),1][z];return{left:Math.round(A.from.left+y*(A.to.left-A.from.left)),top:Math.round(A.from.top+y*(A.to.top-A.from.top)),width:Math.round(A.from.width+y*(A.to.width-A.from.width)),height:Math.round(A.from.height+y*(A.to.height-A.from.height))};}var u=i.find("img").css({position:"absolute",visibility:"hidden",top:0,left:0,border:0});u.get(0).src=g[0].src;u.eq(0).css({visibility:"visible"});if(!s){u.eq(0).css(w(g[0],l.variant?0:1));}var v=l.loop;function r(E,D){if(E%2==0){if(s){var I=E/2,C=(I-1+g.length)%g.length,G=u.eq(I),H=u.eq(C);var y=function(){k(I,G.get(0));H.css("visibility","hidden");setTimeout(D,s);};}else{var Q=E/2,C=(Q-1+g.length)%g.length,z=u.eq(Q),H=u.eq(C),O=g[Q].time_ms,J=w(g[Q],l.variant?3:2);var y=function(){k(Q,z.get(0));H.css("visibility","hidden");z[e](J,O,l.easing,D);};}}else{var B=Math.floor(E/2),L=Math.ceil(E/2)%g.length,A=u.eq(B),P=u.eq(L),F={},M={visibility:"visible"},N={};if(L>B){M.opacity=0;N.opacity=1;if(l.doubleFade){F.opacity=0;}}else{F.opacity=0;if(l.doubleFade){M.opacity=0;N.opacity=1;}}if(!s){d.extend(M,w(g[L],0));if(!l.variant){d.extend(F,w(g[B],3));d.extend(N,w(g[L],1));}}if(d.isEmptyObject(N)){var y=function(){k(L,P.get(0),B,A.get(0));P.css(M);A[e](F,p,"linear",D);};}else{if(d.isEmptyObject(F)){var y=function(){P.get(0).src=g[L].src;k(L,P.get(0),B,A.get(0));P.css(M);P[e](N,p,"linear",D);};}else{var y=function(){k(L,P.get(0),B,A.get(0));P.css(M);P[e](N,p,"linear");A[e](F,p,"linear",D);};}}}if(l.loop&&E==g.length*2-2){var K=y;y=function(){if(--v){K();}};}if(E>0){return r(E-1,y);}else{return y;}}var t=r(g.length*2-1,function(){return t();});t();});return i;};d.fn.crossSlideFreeze=function(){this.find("img").stop();};d.fn.crossSlideStop=function(){this.find("img").stop().remove();};d.fn.crossSlideRestart=function(){this.find("img").stop().remove();d.fn.crossSlide.apply(this,this.get(0).crossSlideArgs);};d.fn.crossSlidePause=function(){if(!d.fn.pause){f(b);}this.find("img").pause();};d.fn.crossSlideResume=function(){if(!d.fn.pause){f(b);}this.find("img").resume();};})();
