jQuery.extend({roundabout_shape:{def:"lazySusan",lazySusan:function(a,b,c){return{x:Math.sin(a+b),y:Math.sin(a+3*Math.PI/2+b)/8*c,z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},theJuggler:function(a,b,c){return{x:Math.sin(a+b),y:Math.tan(Math.exp(Math.log(a))+b)/(c-1),z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},figure8:function(a,b,c){return{x:Math.sin(a*2+b),y:Math.sin(a+Math.PI/2+b)/8*c,z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},waterWheel:function(a,
b,c){return{x:Math.sin(a+Math.PI/2+b)/8*c,y:Math.sin(a+b)/(Math.PI/2),z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},square:function(a,b,c){var g;if(a<=Math.PI/2){b=2/Math.PI*a;g=-(2/Math.PI)*a+1;a=-(1/Math.PI)*a+1}else if(a>Math.PI/2&&a<=Math.PI){b=-(2/Math.PI)*a+2;g=-(2/Math.PI)*a+1;a=-(1/Math.PI)*a+1}else{b=a>Math.PI&&a<=3*Math.PI/2?-(2/Math.PI)*a+2:2/Math.PI*a-4;g=2/Math.PI*a-3;a=1/Math.PI*a-1}return{x:b,y:g*c,z:a,scale:a}},conveyorBeltLeft:function(a,b,c){return{x:-Math.cos(a+b),
y:Math.cos(a+3*Math.PI/2+b)/8*c,z:(Math.sin(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},conveyorBeltRight:function(a,b,c){return{x:Math.cos(a+b),y:Math.cos(a+3*Math.PI/2+b)/8*c,z:(Math.sin(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},goodbyeCruelWorld:function(a,b,c){return{x:Math.sin(a+b),y:Math.tan(a+3*Math.PI/2+b)/8*(c+0.5),z:(Math.sin(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},diagonalRingLeft:function(a,b,c){return{x:Math.sin(a+b),y:-Math.cos(a+Math.tan(Math.cos(b)))/(c+1.5),z:(Math.cos(a+
b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},diagonalRingRight:function(a,b,c){return{x:Math.sin(a+b),y:Math.cos(a+Math.tan(Math.cos(b)))/(c+1.5),z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},rollerCoaster:function(a,b,c){return{x:Math.sin(a+b),y:Math.sin((2+c)*a),z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}},tearDrop:function(a,b,c){return{x:Math.sin(a+b),y:-Math.sin(a/2+c)+0.35,z:(Math.cos(a+b)+1)/2,scale:Math.sin(a+Math.PI/2+b)/2+0.5}}}});
jQuery.fn.roundabout=function(a){var b=typeof a!="object"?{}:a;b={bearing:typeof b.bearing=="undefined"?0:parseFloat(b.bearing%360,4),tilt:typeof b.tilt=="undefined"?0:parseFloat(b.tilt,4),minZ:typeof b.minZ=="undefined"?100:parseInt(b.minZ,10),maxZ:typeof b.maxZ=="undefined"?400:parseInt(b.maxZ,10),minOpacity:typeof b.minOpacity=="undefined"?0.4:parseFloat(b.minOpacity,2),maxOpacity:typeof b.maxOpacity=="undefined"?1:parseFloat(b.maxOpacity,2),minScale:typeof b.minScale=="undefined"?0.4:parseFloat(b.minScale,
2),maxScale:typeof b.maxScale=="undefined"?1:parseFloat(b.maxScale,2),duration:typeof b.duration=="undefined"?600:parseInt(b.duration,10),btnNext:b.btnNext||null,btnPrev:b.btnPrev||null,easing:b.easing||"swing",clickToFocus:b.clickToFocus!==false,focusBearing:typeof b.focusBearing=="undefined"?0:parseFloat(b.focusBearing%360,4),shape:b.shape||"lazySusan",debug:b.debug||false,childSelector:b.childSelector||"li",startingChild:typeof b.startingChild=="undefined"?null:parseInt(b.startingChild,10)};this.each(function(){var c=
jQuery(this),g=c.children(b.childSelector),f=360/g.length,d=b.startingChild===null?b.bearing:b.startingChild*f;c.addClass("roundabout-holder").css("padding",0).css("position","relative").css("z-index",b.minZ).attr("bearing",d).attr("tilt",b.tilt).attr("minZ",b.minZ).attr("maxZ",b.maxZ).attr("minOpacity",b.minOpacity).attr("maxOpacity",b.maxOpacity).attr("minScale",b.minScale).attr("maxScale",b.maxScale).attr("duration",b.duration).attr("easing",b.easing).attr("clickToFocus",b.clickToFocus).attr("focusBearing",
b.focusBearing).attr("animating","0").attr("childInFocus",-1).attr("shape",b.shape).attr("period",f).attr("debug",b.debug).attr("childSelector",b.childSelector);g.each(function(e){var h=f*e;jQuery(this).addClass("roundabout-moveable-item").css("position","absolute").attr("degrees",h);e=[jQuery(this).width(),jQuery(this).height(),parseInt(jQuery(this).css("font-size"),10)];jQuery(this).attr("startPos",e.join(","));b.clickToFocus===true&&jQuery(this).click(function(i){if(!jQuery.roundabout_isInFocus(c,
h)){i.preventDefault();c.attr("animating")=="0"&&c.roundabout_animateAngleToFocus(h);return false}})});b.btnNext&&jQuery(b.btnNext).click(function(e){e.preventDefault();c.attr("animating")=="0"&&c.roundabout_animateToNextChild();return false});b.btnPrev&&jQuery(b.btnPrev).click(function(e){e.preventDefault();c.attr("animating")=="0"&&c.roundabout_animateToPreviousChild();return false});c.roundabout_updateChildPositions()});return this};
jQuery.fn.roundabout_setTilt=function(a){this.each(function(){jQuery(this).attr("tilt",a);jQuery(this).roundabout_updateChildPositions()});return this};jQuery.fn.roundabout_setBearing=function(a,b){this.each(function(){jQuery(this).attr("bearing",parseFloat(a%360,4));jQuery(this).roundabout_updateChildPositions()});typeof b==="function"&&setTimeout(function(){b()},0);return this};
jQuery.fn.roundabout_adjustBearing=function(a){a=parseFloat(a,4);a!==0&&this.each(function(){jQuery(this).attr("bearing",jQuery.roundabout_getBearing(jQuery(this))+a);jQuery(this).roundabout_updateChildPositions()});return this};jQuery.fn.roundabout_adjustTilt=function(a){a=parseFloat(a,4);this.each(function(){jQuery(this).attr("tilt",parseFloat(jQuery(this).attr("tilt"),4)+a);jQuery(this).roundabout_updateChildPositions()});return this};
jQuery.fn.roundabout_animateToBearing=function(a,b,c,g){a=parseFloat(a,4);var f=new Date,d=typeof g!=="object"?null:g,e=typeof b=="undefined"?null:b,h=typeof c!="undefined"?c:null;this.each(function(){var i=jQuery(this),j,m,k=e===null?parseInt(i.attr("duration"),10):e,l=h!==null?h:i.attr("easing")||"swing";if(d===null)d={timerStart:f,start:jQuery.roundabout_getBearing(i),totalTime:k};j=f-d.timerStart;if(j<k){i.attr("animating","1");if(typeof jQuery.easing.def=="string"){m=jQuery.easing[l]||jQuery.easing[jQuery.easing.def];
j=m(null,j,d.start,a-d.start,d.totalTime)}else j=jQuery.easing[l](j/d.totalTime,j,d.start,a-d.start,d.totalTime);i.roundabout_setBearing(j,function(){i.roundabout_animateToBearing(a,k,l,d)})}else{a=a<0?a+360:a%360;i.attr("animating","0");i.roundabout_setBearing(a)}});return this};
jQuery.fn.roundabout_animateToDelta=function(a,b,c){var g,f;if(typeof b!=="undefined")g=b;if(typeof c!=="undefined")f=c;this.each(function(){a=jQuery.roundabout_getBearing(jQuery(this))+a;jQuery(this).roundabout_animateToBearing(a,g,f)});return this};
jQuery.fn.roundabout_animateToChild=function(a,b,c){var g,f;if(typeof b!=="undefined")g=b;if(typeof c!=="undefined")f=c;this.each(function(){var d=jQuery(this);if(parseInt(d.attr("childInFocus"),10)!==a&&d.attr("animating","0")){var e=jQuery(d.children(d.attr("childSelector"))[a]);d.roundabout_animateAngleToFocus(parseFloat(e.attr("degrees"),4),g,f)}});return this};
jQuery.fn.roundabout_animateToNextChild=function(a,b){var c,g;if(typeof a!=="undefined")c=a;if(typeof b!=="undefined")g=b;this.each(function(){if(jQuery(this).attr("animating","0"))for(var f=360-jQuery.roundabout_getBearing(jQuery(this)),d=parseFloat(jQuery(this).attr("period"),4),e=0,h;;){h={lower:d*e,upper:d*(e+1)};if(f<=h.upper&&f>h.lower){jQuery(this).roundabout_animateToDelta(f-h.lower,c,g);break}e++}});return this};
jQuery.fn.roundabout_animateToPreviousChild=function(a,b){var c,g;if(typeof a!=="undefined")c=a;if(typeof b!=="undefined")g=b;this.each(function(){if(jQuery(this).attr("animating","0"))for(var f=360-jQuery.roundabout_getBearing(jQuery(this)),d=parseFloat(jQuery(this).attr("period"),4),e=0,h;;){h={lower:d*e,upper:d*(e+1)};if(f>=h.lower&&f<h.upper){jQuery(this).roundabout_animateToDelta(f-h.upper,c,g);break}e++}});return this};
jQuery.fn.roundabout_animateAngleToFocus=function(a,b,c){var g,f;if(typeof b!=="undefined")g=b;if(typeof c!=="undefined")f=c;this.each(function(){var d=jQuery.roundabout_getBearing(jQuery(this))-a;d=Math.abs(360-d)<Math.abs(0-d)?360-d:0-d;d=d>180?-(360-d):d;d!==0&&jQuery(this).roundabout_animateToDelta(d,g,f)});return this};
jQuery.fn.roundabout_updateChildPositions=function(){this.each(function(){var a=jQuery(this),b=-1,c={bearing:jQuery.roundabout_getBearing(a),tilt:parseFloat(a.attr("tilt"),4),stage:{width:Math.floor(a.width()*0.9),height:Math.floor(a.height()*0.9)},animating:a.attr("animating"),inFocus:parseInt(a.attr("childInFocus"),10),focusBearingRad:jQuery.roundabout_degToRad(parseFloat(a.attr("focusBearing"),4)),shape:jQuery.roundabout_shape[a.attr("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:parseInt(a.attr("minZ"),10),max:parseInt(a.attr("maxZ"),10)};c.zValues.diff=c.zValues.max-c.zValues.min;c.opacity={min:parseFloat(a.attr("minOpacity"),2),max:parseFloat(a.attr("maxOpacity"),2)};c.opacity.diff=c.opacity.max-c.opacity.min;c.scale={min:parseFloat(a.attr("minScale"),2),max:parseFloat(a.attr("maxScale"),2)};c.scale.diff=
c.scale.max-c.scale.min;a.children(a.attr("childSelector")).each(function(g){if(jQuery.roundabout_updateChildPosition(jQuery(this),a,c,g)&&c.animating=="0"){b=g;jQuery(this).addClass("roundabout-in-focus")}else jQuery(this).removeClass("roundabout-in-focus")});if(b!==c.inFocus){jQuery.roundabout_triggerEvent(a,c.inFocus,"blur");b!==-1&&jQuery.roundabout_triggerEvent(a,b,"focus");a.attr("childInFocus",b)}});return this};
jQuery.roundabout_getBearing=function(a){return parseFloat(a.attr("bearing"),4)%360};jQuery.roundabout_degToRad=function(a){return a%360*Math.PI/180};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.attr("childSelector"))[b]).trigger(c)};
jQuery.roundabout_updateChildPosition=function(a,b,c,g){a=jQuery(a);var f=[],d=a.attr("startPos").split(",");d={startWidth:d[0],startHeight:d[1],startFontSize:d[2],degrees:parseFloat(a.attr("degrees"),4)};for(var e=jQuery.roundabout_degToRad(360-d.degrees+c.bearing);e<0;)e+=Math.PI*2;for(;e>Math.PI*2;)e-=Math.PI*2;e=c.shape(e,c.focusBearingRad,c.tilt);e.scale=e.scale>1?1:e.scale;e.adjustedScale=(c.scale.min+c.scale.diff*e.scale).toFixed(4);e.width=e.adjustedScale*d.startWidth;e.height=e.adjustedScale*
d.startHeight;a.css("left",(e.x*c.midStage.width+c.nudge.width-e.width/2).toFixed(2)+"px").css("top",(e.y*c.midStage.height+c.nudge.height-e.height/2).toFixed(2)+"px").css("width",e.width.toFixed(2)+"px").css("height",e.height.toFixed(2)+"px").css("opacity",(c.opacity.min+c.opacity.diff*e.scale).toFixed(2)).css("z-index",parseInt(c.zValues.min+c.zValues.diff*e.z,10)).css("font-size",(e.adjustedScale*d.startFontSize).toFixed(2)+"px").attr("current-scale",e.adjustedScale);if(b.attr("debug")=="true"){f.push('<div style="font-weight: normal; font-size: 10px; padding: 2px; width: '+
a.css("width")+'; background-color: #ffc;">');f.push('<strong style="font-size: 12px; white-space: nowrap;">Child '+g+"</strong><br />");f.push("<strong>left:</strong> "+a.css("left")+"<br /><strong>top:</strong> "+a.css("top")+"<br />");f.push("<strong>width:</strong> "+a.css("width")+"<br /><strong>opacity:</strong> "+a.css("opacity")+"<br />");f.push("<strong>z-index:</strong> "+a.css("z-index")+"<br /><strong>font-size:</strong> "+a.css("font-size")+"<br />");f.push("<strong>scale:</strong> "+
a.attr("current-scale"));f.push("</div>");a.html(f.join(""))}return jQuery.roundabout_isInFocus(b,d.degrees)};
