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

