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