1 $.speed = function(s,o) {
2 if ( o && o.constructor == Function ) { o = { onComplete: o }; }
4 var ss = {"crawl":1200,"xslow":850,"slow":600,"medium":400,"fast":200,"xfast":75,"normal":400};
5 o.duration = typeof s == "number" ? s : ss[s] || 400;
7 o.oldComplete = o.onComplete;
8 o.onComplete = function(){
10 if ( o.oldComplete && o.oldComplete.constructor == Function ) {
11 $.apply( this, o.oldComplete );
20 $.dequeue = function(elem,type){
23 if ( elem.$$queue && elem.$$queue[type] ) {
25 elem.$$queue[type].shift();
28 var f = elem.$$queue[type][0];
36 $.fn.queue = function(type,fn){
42 return this.each(function(){
43 if ( !this.$$queue ) {
47 if ( !this.$$queue[type] ) {
48 this.$$queue[type] = [];
51 this.$$queue[type].push( fn );
53 if ( this.$$queue[type].length == 1 ) {
59 $.fn._hide = $.fn.hide;
61 $.fn.hide = function(a,o) {
63 return a ? this.queue(function(){
64 new $.fx.FadeSize(this,o).hide();
68 $.fn._show = $.fn.show;
70 $.fn.show = function(a,o) {
72 return a ? this.queue(function(){
73 new $.fx.FadeSize(this,o).show();
77 $.fn.slideDown = function(a,o) {
79 return this.queue(function(){
80 new $.fx.Resize(this,o).show("height");
84 $.fn.slideUp = function(a,o) {
86 return this.queue(function(){
87 new $.fx.Resize(this,o).hide("height");
91 $.fn.fadeOut = function(a,o) {
93 return a ? this.queue(function(){
94 new $.fx.Opacity(this,o,1).hide();
98 $.fn.fadeIn = function(a,o) {
100 return a ? this.queue(function(){
101 new $.fx.Opacity(this,o,1).show();
105 $.fn.fadeTo = function(a,ev,o) {
107 return a ? this.queue(function(){
108 ef = new $.fx.Opacity(this,o);
109 ef.custom(ef.cur(),parseFloat(ev));
114 $.fn.center = function(f) {
115 return this.each(function(){
116 if ( !f && this.nodeName == 'IMG' &&
117 !this.offsetWidth && !this.offsetHeight ) {
119 setTimeout(function(){
120 $(self).center(true);
124 var p = this.parentNode;
125 if ( $.css(p,"position") == 'static' ) {
126 p.style.position = 'relative';
128 s.position = 'absolute';
129 s.left = (($.css(p,"width") - $.css(this,"width"))/2) + "px";
130 s.top = (($.css(p,"height") - $.css(this,"height"))/2) + "px";
135 $.setAuto = function(e,p) {
146 * I originally wrote fx() as a clone of moo.fx and in the process
147 * of making it small in size the code became illegible to sane
148 * people. You've been warned.
151 $.fx = function(el,op,ty){
157 duration: (op && op.duration) || 400,
158 onComplete: (op && op.onComplete) || op
167 // Simple function for setting a style value
169 z.el.style[ty] = z.now+'px';
172 // Figure out the maximum number to run to
173 z.max = function(){return z.el["$$orig"+ty]||z.cur();};
175 // Get the current size
176 z.cur = function(){return $.css(z.el,ty);};
178 // Start an animation from one number to another
179 z.custom = function(from,to){
180 z.startTime = (new Date()).getTime();
184 z.timer = setInterval(function(){
189 // Simple 'show' function
196 // Simple 'hide' function
198 // Remember where we started, so that we can go back to it later
199 z.el["$$orig"+ty] = this.cur();
201 // Begin the animation
205 // Toggle between showing and hiding an element
206 z.toggle = function(){
214 // IE has trouble with opacity if it doesn't have layout
215 if ( $.browser == "msie" && !z.el.currentStyle.hasLayout ) {
219 // Remember the overflow of the element
220 z.oldOverflow = y.overflow;
222 // Make sure that nothing sneaks out
223 y.overflow = "hidden";
225 // Each step of an animation
226 z.step = function(firstNum, lastNum){
227 var t = (new Date()).getTime();
229 if (t > z.o.duration + z.startTime) {
231 clearInterval(z.timer);
237 // Reset the overflow
238 y.overflow = z.oldOverflow;
240 // If the element was shown, and not using a custom number,
241 // set its height and/or width to auto
242 if ( (ty == "height" || ty == "width") && z.o.auto ) {
243 $.setAuto( z.el, ty );
246 // If a callback was provided, execute it
247 if( z.o.onComplete.constructor == Function ) {
249 // Yes, this is a weird place for this, but it needs to be executed
250 // only once per cluster of effects.
251 // If the element is, effectively, hidden - hide it
252 if ( y.height == "0px" || y.width == "0px" ) {
256 $.apply( z.el, z.o.onComplete );
259 // Figure out where in the animation we are and set the number
260 var p = (t - this.startTime) / z.o.duration;
261 z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
263 // Perform the next step of the animation
270 $.fx.fn = ["show","hide","toggle"];
271 $.fx.ty = ["Height","Width","Left","Top"];
274 for(var $i in $.fx.ty){(function(){
276 $.fx[c] = function(a,b){
277 return new $.fx(a,b,c.toLowerCase());
282 $.fx.Opacity = function(a,b,sv){
283 var o = new $.fx(a,b,"opacity");
284 o.cur = function(){return parseFloat(o.el.style.opacity);};
287 if (o.now == 1) { o.now = 0.9999; }
288 if (window.ActiveXObject) {
289 e.filter = "alpha(opacity=" + o.now*100 + ")";
293 o.io = o.now = (sv || o.cur());
298 $.fx.Resize = function(e,o){
300 var h = new $.fx.Height(e,o);
301 if(o) { o.onComplete = null; }
302 var w = new $.fx.Width(e,o);
303 function c(a,b,d){return (!a||a==d||b==d);}
304 for(var i in $.fx.fn){(function(){
306 z[j] = function(a,b){
307 if(c(a,b,"height")) { h[j](); }
308 if(c(a,b,"width")) { w[j](); }
313 $.fx.FadeSize = function(e,o){
315 var r = new $.fx.Resize(e,o);
316 if(o) { o.onComplete = null; }
317 var p = new $.fx.Opacity(e,o,1);
318 for(var i in $.fx.fn){(function(){
320 z[j] = function(a,b){p[j]();r[j](a,b);};