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