/* http://keith-wood.name/imageCube.html
Image Cube for jQuery v2.0.0.
Written by Keith Wood (kbwood{at}iinet.com.au) June 2008.
Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license.
Please attribute the author if you use it. */
(function($){var U='imagecube';var V=0;var W=1;var X=2;var Y=3;$.JQPlugin.createPlugin({name:U,defaultOptions:{direction:'random',randomSelection:['up','down','left','right'],speed:2000,easing:'linear',repeat:true,pause:2000,selection:'forward',shading:true,opacity:0.8,imagePath:'',full3D:true,segments:20,reduction:30,expansion:10,lineHeight:[0.0,1.25],letterSpacing:[-0.4,0.0],beforeRotate:null,afterRotate:null},_getters:['current','next'],_instSettings:function(a,b){return{_position:a.css('position')}},_postAttach:function(b,c){b.css({position:'relative'}).children().each(function(){var a=$(this);a.data(U,{display:a.css('display'),width:a.css('width'),height:a.css('height'),position:a.css('position'),lineHeight:a.css('lineHeight'),letterSpacing:a.css('letterSpacing')}).css({display:'block',width:b.css('width'),height:b.css('height'),position:'absolute',lineHeight:c.options.lineHeight[1],letterSpacing:c.options.letterSpacing[1]})}).not(':first').hide();this._prepareRotation(b)},_optionsChanged:function(a,b,c){$.extend(b.options,c);this._prepareRotation(a)},_prepareRotation:function(b){b=$(b);b.children('.imageCubeShading,.imageCubeFrom,.imageCubeTo').remove();var c=this._getInst(b[0]);c.current=b.children(':visible')[0];c.current=(c.current?c.current:b.children(':first')[0]);var d=function(a){return(!a.length?a:a.filter(':eq('+Math.floor(Math.random()*a.length)+')'))};c.next=(c.options.selection=='random'?d(b.children(':hidden')):(c.options.selection=='backward'?$(c.current).prev():$(c.current).next()));c.next=(c.next.length?c.next:(c.options.selection=='random'?c.current:(c.options.selection=='backward'?b.children(':last'):b.children(':first'))))[0];if(c.options.repeat&&!c._timer){var e=this;c._timer=setTimeout(function(){e.rotate(b)},c.options.pause)}},rotate:function(a,b,c){a=$(a);if(!a.hasClass(this._getMarker())){return}if(typeof b=='function'){c=b;b=null}this.stop(a,true);var d=this._getInst(a[0]);if(b!=null){b=(typeof b=='number'?a.children(':eq('+b+')'):$(b));if(a.children().filter(function(){return this===b[0]}).length>0){d.next=b}}var e=[d.current,d.next];if($.isFunction(d.options.beforeRotate)){d.options.beforeRotate.apply(a[0],e)}var f={};f[U]=1.0;a.attr(U,0.0).stop(true,true).animate(f,d.options.speed,d.options.easing,function(){if($.isFunction(d.options.afterRotate)){d.options.afterRotate.apply(a[0],e)}if(c){c.apply(a[0])}})},current:function(a){a=$(a);return(a.hasClass(this._getMarker())?this._getInst(a[0]).current:null)},next:function(a){a=$(a);return(a.hasClass(this._getMarker())?this._getInst(a[0]).next:null)},stop:function(a,b){a=$(a);if(!a.hasClass(this._getMarker())){return}var c=this._getInst(a[0]);if(c._timer){clearTimeout(c._timer);c._timer=null}if(!b){c.options.repeat=false}},start:function(a){this.option(a,{repeat:true})},_preDestroy:function(b,c){this.stop(b);var c=this._getInst(b[0]);b.stop().css({position:c._position}).children('.imageCubeShading,.imageCubeFrom,.imageCubeTo').remove();b.children().each(function(){var a=$(this);a.css(a.data(U)).removeData(U)}).show()},_prepareAnimation:function(d){d=$(d);var e=this._getInst(d[0]);var f={left:0,top:0};d.parents().each(function(){var a=$(this);if(a.css('position')=='fixed'){f.left-=a.offset().left;f.top-=a.offset().top;return false}});var g={width:d.width(),height:d.height()};var h=(e.options.direction!='random'?e.options.direction:e.options.randomSelection[Math.floor(Math.random()*e.options.randomSelection.length)]);h=Math.max(0,$.inArray(h,['up','down','left','right']));e._curDirection=h;var j=(h==V||h==W);var k=(h==X||h==Y);var l=(h==V||h==X);var m=(l?0:e.options.opacity);var n=$(e.current);var o=$(e.next);var q=[];var r=function(p){var b=[0,0,0,0];if(p.css('border')!=undefined){$.each(['Left','Right','Top','Bottom'],function(i,a){b[i]=p.css('border'+a+'Width');b[i]=parseFloat({thin:1,medium:3,thick:5}[b[i]]||b[i])})}return b};q[0]=r(n);q[1]=r(o);var s=[];s[0]=[parseFloat(n.css('padding-left')),parseFloat(n.css('padding-right')),parseFloat(n.css('padding-top')),parseFloat(n.css('padding-bottom'))];s[1]=[parseFloat(o.css('padding-left')),parseFloat(o.css('padding-right')),parseFloat(o.css('padding-top')),parseFloat(o.css('padding-bottom'))];var t=[];t[0]=($.support.boxModel?[q[0][0]+q[0][1]+s[0][0]+s[0][1],q[0][2]+q[0][3]+s[0][2]+s[0][3]]:[0,0]);t[1]=($.support.boxModel?[q[1][0]+q[1][1]+s[1][0]+s[1][1],q[1][2]+q[1][3]+s[1][2]+s[1][3]]:[0,0]);var u=[];u[0]={elem:n[0],props:{left:{start:f.left,end:f.left+(h==Y?g.width:0),units:'px'},width:{start:g.width-t[0][0],end:(j?g.width-t[0][0]:0),units:'px'},top:{start:f.top,end:f.top+(h==W?g.height:0),units:'px'},height:{start:g.height-t[0][1],end:(j?0:g.height-t[0][1]),units:'px'},paddingLeft:{start:s[0][0],end:(k?0:s[0][0]),units:'px'},paddingRight:{start:s[0][1],end:(k?0:s[0][1]),units:'px'},paddingTop:{start:s[0][2],end:(j?0:s[0][2]),units:'px'},paddingBottom:{start:s[0][3],end:(j?0:s[0][3]),units:'px'},borderLeftWidth:{start:q[0][0],end:(k?0:q[0][0]),units:'px'},borderRightWidth:{start:q[0][1],end:(k?0:q[0][1]),units:'px'},borderTopWidth:{start:q[0][2],end:(j?0:q[0][2]),units:'px'},borderBottomWidth:{start:q[0][3],end:(j?0:q[0][3]),units:'px'},lineHeight:{start:e.options.lineHeight[1],end:(j?e.options.lineHeight[0]:e.options.lineHeight[1]),units:'em'},letterSpacing:{start:e.options.letterSpacing[1],end:(j?e.options.letterSpacing[1]:e.options.letterSpacing[0]),units:'em'}}};u[1]={elem:o[0],props:{left:{start:f.left+(h==X?g.width:0),end:f.left,units:'px'},width:{start:(j?g.width-t[1][0]:0),end:g.width-t[1][0],units:'px'},top:{start:f.top+(h==V?g.height:0),end:f.top,units:'px'},height:{start:(j?0:g.height-t[1][1]),end:g.height-t[1][1],units:'px'},paddingLeft:{start:(k?0:s[1][0]),end:s[1][0],units:'px'},paddingRight:{start:(k?0:s[1][1]),end:s[1][1],units:'px'},paddingTop:{start:(j?0:s[1][2]),end:s[1][2],units:'px'},paddingBottom:{start:(j?0:s[1][3]),end:s[1][3],units:'px'},borderLeftWidth:{start:(k?0:q[1][0]),end:q[1][0],units:'px'},borderRightWidth:{start:(k?0:q[1][1]),end:q[1][1],units:'px'},borderTopWidth:{start:(j?0:q[1][2]),end:q[1][2],units:'px'},borderBottomWidth:{start:(j?0:q[1][3]),end:q[1][3],units:'px'},lineHeight:{start:(j?e.options.lineHeight[0]:e.options.lineHeight[1]),end:e.options.lineHeight[1],units:'em'},letterSpacing:{start:(j?e.options.letterSpacing[1]:e.options.letterSpacing[0]),end:e.options.letterSpacing[1],units:'em'}}};if(e.options.shading){var v=function(a,b,c){return{left:{start:a.left.start,end:a.left.end,units:'px'},width:{start:a.width.start,end:a.width.end,units:'px'},top:{start:a.top.start,end:a.top.end,units:'px'},height:{start:a.height.start,end:a.height.end,units:'px'},paddingLeft:{start:a.paddingLeft.start+a.borderLeftWidth.start,end:a.paddingLeft.end+a.borderLeftWidth.end,units:'px'},paddingRight:{start:a.paddingRight.start+a.borderRightWidth.start,end:a.paddingRight.end+a.borderRightWidth.end,units:'px'},paddingTop:{start:a.paddingTop.start+a.borderTopWidth.start,end:a.paddingTop.end+a.borderTopWidth.end,units:'px'},paddingBottom:{start:a.paddingBottom.start+a.borderBottomWidth.start,end:a.paddingBottom.end+a.borderBottomWidth.end,units:'px'},opacity:{start:b,end:c,units:''}}};u[2]={elem:$((!$.support.opacity?'':'>'))[0],props:v(u[l?0:1].props,m,e.options.opacity-m)};u[3]={elem:$((!$.support.opacity?'':'>'))[0],props:v(u[l?1:0].props,e.options.opacity-m,m)}}if(e.options.full3D){for(var i=0;i