jQuery.extend({roundabout_shape:{def:'lazySusan',lazySusan:function(r,a,t){return{x:Math.sin(r+a),y:(Math.sin(r+3*Math.PI/2+a)/8)*t,z:(Math.cos(r+a)+1)/2,scale:(Math.sin(r+Math.PI/2+a)/2)+0.5}}}});jQuery.fn.roundabout=function(){var f=(typeof arguments[0]!='object')?{}:arguments[0];f={bearing:(typeof f.bearing=='undefined')?0.0:jQuery.roundabout_toFloat(f.bearing%360.0),tilt:(typeof f.tilt=='undefined')?0.0:jQuery.roundabout_toFloat(f.tilt),minZ:(typeof f.minZ=='undefined')?100:parseInt(f.minZ,10),maxZ:(typeof f.maxZ=='undefined')?400:parseInt(f.maxZ,10),minOpacity:(typeof f.minOpacity=='undefined')?0.70:jQuery.roundabout_toFloat(f.minOpacity),maxOpacity:(typeof f.maxOpacity=='undefined')?1.00:jQuery.roundabout_toFloat(f.maxOpacity),minScale:(typeof f.minScale=='undefined')?0.30:jQuery.roundabout_toFloat(f.minScale),maxScale:(typeof f.maxScale=='undefined')?1.00:jQuery.roundabout_toFloat(f.maxScale),duration:(typeof f.duration=='undefined')?600:parseInt(f.duration,10),btnNext:f.btnNext||null,btnPrev:f.btnPrev||null,easing:f.easing||'swing',clickToFocus:(f.clickToFocus!==false),focusBearing:(typeof f.focusBearing=='undefined')?0.0:jQuery.roundabout_toFloat(f.focusBearing%360.0),shape:f.shape||'lazySusan',debug:f.debug||false,childSelector:f.childSelector||'li',startingChild:(typeof f.startingChild=='undefined')?null:parseInt(f.startingChild,10),reflect:(typeof f.reflect=='undefined'||f.reflect===false)?false:true};this.each(function(i){var b=jQuery(this);var c=jQuery.roundabout_toFloat(360.0/b.children(f.childSelector).length);var d=(f.startingChild===null)?f.bearing:f.startingChild*c;b.addClass('roundabout-holder').css('padding',0).css('position','relative').css('z-index',f.minZ);b.data('roundabout',{'bearing':d,'tilt':f.tilt,'minZ':f.minZ,'maxZ':f.maxZ,'minOpacity':f.minOpacity,'maxOpacity':f.maxOpacity,'minScale':f.minScale,'maxScale':f.maxScale,'duration':f.duration,'easing':f.easing,'clickToFocus':f.clickToFocus,'focusBearing':f.focusBearing,'animating':0,'childInFocus':-1,'shape':f.shape,'period':c,'debug':f.debug,'childSelector':f.childSelector,'reflect':f.reflect});if(f.clickToFocus===true){b.children(f.childSelector).each(function(i){jQuery(this).click(function(e){var a=(f.reflect===true)?360.0-(c*i):c*i;a=jQuery.roundabout_toFloat(a);if(!jQuery.roundabout_isInFocus(b,a)){e.preventDefault();if(b.data('roundabout').animating===0){b.roundabout_animateAngleToFocus(a)}return false}})})}if(f.btnNext){jQuery(f.btnNext).bind('click.roundabout',function(e){e.preventDefault();if(b.data('roundabout').animating===0){b.roundabout_animateToNextChild()}return false})}if(f.btnPrev){jQuery(f.btnPrev).bind('click.roundabout',function(e){e.preventDefault();if(b.data('roundabout').animating===0){b.roundabout_animateToPreviousChild()}return false})}});this.roundabout_startChildren();if(typeof arguments[1]==='function'){var g=arguments[1],ref=this;setTimeout(function(){g(ref)},0)}return this};jQuery.fn.roundabout_startChildren=function(){this.each(function(i){var b=jQuery(this);var c=b.data('roundabout');var d=b.children(c.childSelector);d.each(function(i){var a=(c.reflect===true)?360.0-(c.period*i):c.period*i;jQuery(this).addClass('roundabout-moveable-item').css('position','absolute');jQuery(this).data('roundabout',{'startWidth':jQuery(this).width(),'startHeight':jQuery(this).height(),'startFontSize':parseInt(jQuery(this).css('font-size'),10),'degrees':a})});b.roundabout_updateChildPositions()});return this};jQuery.fn.roundabout_setTilt=function(a){this.each(function(i){jQuery(this).data('roundabout').tilt=a;jQuery(this).roundabout_updateChildPositions()});if(typeof arguments[1]==='function'){var b=arguments[1],ref=this;setTimeout(function(){b(ref)},0)}return this};jQuery.fn.roundabout_setBearing=function(a){this.each(function(i){jQuery(this).data('roundabout').bearing=jQuery.roundabout_toFloat(a%360,2);jQuery(this).roundabout_updateChildPositions()});if(typeof arguments[1]==='function'){var b=arguments[1],ref=this;setTimeout(function(){b(ref)},0)}return this};jQuery.fn.roundabout_adjustBearing=function(a){a=jQuery.roundabout_toFloat(a);if(a!==0){this.each(function(i){jQuery(this).data('roundabout').bearing=jQuery.roundabout_getBearing(jQuery(this))+a;jQuery(this).roundabout_updateChildPositions()})}if(typeof arguments[1]==='function'){var b=arguments[1],ref=this;setTimeout(function(){b(ref)},0)}return this};jQuery.fn.roundabout_adjustTilt=function(a){a=jQuery.roundabout_toFloat(a);if(a!==0){this.each(function(i){jQuery(this).data('roundabout').tilt=jQuery.roundabout_toFloat(jQuery(this).roundabout_get('tilt')+a);jQuery(this).roundabout_updateChildPositions()})}if(typeof arguments[1]==='function'){var b=arguments[1],ref=this;setTimeout(function(){b(ref)},0)}return this};jQuery.fn.roundabout_animateToBearing=function(d){d=jQuery.roundabout_toFloat(d);var e=new Date();var f=(typeof arguments[1]=='undefined')?null:arguments[1];var g=(typeof arguments[2]=='undefined')?null:arguments[2];var h=(typeof arguments[3]!=='object')?null:arguments[3];this.each(function(i){var a=jQuery(this),data=a.data('roundabout'),timer,easingFn,newBearing;var b=(f===null)?data.duration:f;var c=(g!==null)?g:data.easing||'swing';if(h===null){h={timerStart:e,start:jQuery.roundabout_getBearing(a),totalTime:b}}timer=e-h.timerStart;if(timer<b){data.animating=1;if(typeof jQuery.easing.def=='string'){easingFn=jQuery.easing[c]||jQuery.easing[jQuery.easing.def];newBearing=easingFn(null,timer,h.start,d-h.start,h.totalTime)}else{newBearing=jQuery.easing[c]((timer/h.totalTime),timer,h.start,d-h.start,h.totalTime)}a.roundabout_setBearing(newBearing,function(){a.roundabout_animateToBearing(d,b,c,h)})}else{d=(d<0)?d+360:d%360;data.animating=0;a.roundabout_setBearing(d)}});return this};jQuery.fn.roundabout_animateToDelta=function(a){var b=arguments[1],easing=arguments[2];this.each(function(i){a=jQuery.roundabout_getBearing(jQuery(this))+jQuery.roundabout_toFloat(a);jQuery(this).roundabout_animateToBearing(a,b,easing)});return this};jQuery.fn.roundabout_animateToChild=function(c){var d=arguments[1],easing=arguments[2];this.each(function(i){var a=jQuery(this),data=a.data('roundabout');if(data.childInFocus!==c&&data.animating===0){var b=jQuery(a.children(data.childSelector)[c]);a.roundabout_animateAngleToFocus(b.data('roundabout').degrees,d,easing)}});return this};jQuery.fn.roundabout_animateToNearbyChild=function(f,g){var h=f[0],easing=f[1];this.each(function(i){var a=jQuery(this).data('roundabout');var b=jQuery.roundabout_toFloat(360.0-jQuery.roundabout_getBearing(jQuery(this)));var c=a.period,j=0,range;var d=a.reflect;var e=jQuery(this).children(a.childSelector).length;b=(d===true)?b%360.0:b;if(a.animating===0){if((d===false&&g==='next')||(d===true&&g!=='next')){b=(b===0)?360:b;while(true&&j<e){range={lower:jQuery.roundabout_toFloat(c*j),upper:jQuery.roundabout_toFloat(c*(j+1))};range.upper=(j==e-1)?360.0:range.upper;if(b<=range.upper&&b>range.lower){jQuery(this).roundabout_animateToDelta(b-range.lower,h,easing);break}j++}}else{while(true){range={lower:jQuery.roundabout_toFloat(c*j),upper:jQuery.roundabout_toFloat(c*(j+1))};range.upper=(j==e-1)?360.0:range.upper;if(b>=range.lower&&b<range.upper){jQuery(this).roundabout_animateToDelta(b-range.upper,h,easing);break}j++}}}});return this};jQuery.fn.roundabout_animateToNextChild=function(){return this.roundabout_animateToNearbyChild(arguments,'next')};jQuery.fn.roundabout_animateToPreviousChild=function(){return this.roundabout_animateToNearbyChild(arguments,'previous')};jQuery.fn.roundabout_animateAngleToFocus=function(b){var c=arguments[1],easing=arguments[2];this.each(function(i){var a=jQuery.roundabout_getBearing(jQuery(this))-b;a=(Math.abs(360.0-a)<Math.abs(0.0-a))?360.0-a:0.0-a;a=(a>180)?-(360.0-a):a;if(a!==0){jQuery(this).roundabout_animateToDelta(a,c,easing)}});return this};jQuery.fn.roundabout_updateChildPositions=function(){this.each(function(i){var a=jQuery(this),data=a.data('roundabout');var b=-1;var c={bearing:jQuery.roundabout_getBearing(a),tilt:data.tilt,stage:{width:Math.floor(a.width()*0.9),height:Math.floor(a.height()*0.9)},animating:data.animating,inFocus:data.childInFocus,focusBearingRad:jQuery.roundabout_degToRad(data.focusBearing),shape:jQuery.roundabout_shape[data.shape]||jQuery.roundabout_shape[jQuery.roundabout_shape.def]};c.midStage={width:c.stage.width/2,height:c.stage.height/2};c.nudge={width:c.midStage.width+c.stage.width*0.05,height:c.midStage.height+c.stage.height*0.05};c.zValues={min:data.minZ,max:data.maxZ,diff:data.maxZ-data.minZ};c.opacity={min:data.minOpacity,max:data.maxOpacity,diff:data.maxOpacity-data.minOpacity};c.scale={min:data.minScale,max:data.maxScale,diff:data.maxScale-data.minScale};a.children(data.childSelector).each(function(i){if(jQuery.roundabout_updateChildPosition(jQuery(this),a,c,i)&&c.animating===0){b=i;jQuery(this).addClass('roundabout-in-focus')}else{jQuery(this).removeClass('roundabout-in-focus')}});if(b!==c.inFocus){jQuery.roundabout_triggerEvent(a,c.inFocus,'blur');if(b!==-1){jQuery.roundabout_triggerEvent(a,b,'focus')}data.childInFocus=b}});return this};jQuery.roundabout_getBearing=function(a){return jQuery.roundabout_toFloat(a.data('roundabout').bearing)%360};jQuery.roundabout_degToRad=function(a){return(a%360.0)*Math.PI/180.0};jQuery.roundabout_isInFocus=function(a,b){return(jQuery.roundabout_getBearing(a)%360===(b%360))};jQuery.roundabout_triggerEvent=function(a,b,c){return(b<0)?this:jQuery(a.children(a.data('roundabout').childSelector)[b]).trigger(c)};jQuery.roundabout_toFloat=function(a){a=Math.round(parseFloat(a)*1000)/1000;return parseFloat(a.toFixed(2))};jQuery.roundabout_updateChildPosition=function(a,b,c,d){var e=jQuery(a),data=e.data('roundabout'),out=[];var f=jQuery.roundabout_degToRad((360.0-e.data('roundabout').degrees)+c.bearing);while(f<0){f=f+Math.PI*2}while(f>Math.PI*2){f=f-Math.PI*2}var g=c.shape(f,c.focusBearingRad,c.tilt);g.scale=(g.scale>1)?1:g.scale;g.adjustedScale=(c.scale.min+(c.scale.diff*g.scale)).toFixed(4);g.width=(g.adjustedScale*data.startWidth).toFixed(4);g.height=(g.adjustedScale*data.startHeight).toFixed(4);e.css('left',((g.x*c.midStage.width+c.nudge.width)-g.width/2.0).toFixed(1)+'px').css('top',((g.y*c.midStage.height+c.nudge.height)-g.height/2.0).toFixed(1)+'px').css('width',g.width+'px').css('height',g.height+'px').css('opacity',(c.opacity.min+(c.opacity.diff*g.scale)).toFixed(2)).css('z-index',Math.round(c.zValues.min+(c.zValues.diff*g.z))).css('font-size',(g.adjustedScale*data.startFontSize).toFixed(2)+'px').attr('current-scale',g.adjustedScale);if(b.data('roundabout').debug===true){out.push('<div style="font-weight: normal; font-size: 10px; padding: 2px; width: '+e.css('width')+'; background-color: #ffc;">');out.push('<strong style="font-size: 12px; white-space: nowrap;">Child '+d+'</strong><br />');out.push('<strong>left:</strong> '+e.css('left')+'<br /><strong>top:</strong> '+e.css('top')+'<br />');out.push('<strong>width:</strong> '+e.css('width')+'<br /><strong>opacity:</strong> '+e.css('opacity')+'<br />');out.push('<strong>z-index:</strong> '+e.css('z-index')+'<br /><strong>font-size:</strong> '+e.css('font-size')+'<br />');out.push('<strong>scale:</strong> '+e.attr('current-scale'));out.push('</div>');e.html(out.join(''))}return jQuery.roundabout_isInFocus(b,e.data('roundabout').degrees)};
