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

