Changeset 2504

Show
Ignore:
Timestamp:
09/17/07 23:30:36 (6 years ago)
Author:
joaopacheco
Message:

Update JavaScripts? for Lightbox2 & Download Box Animation

Location:
website/templates/default/media/js
Files:
5 added
1 removed
1 modified

Legend:

Unmodified
Added
Removed
  • website/templates/default/media/js/effects.js

    r1975 r2504  
    11// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 
    2 // 
    3 // Parts (c) 2005 Justin Palmer (http://encytemedia.com/) 
    4 // Parts (c) 2005 Mark Pilgrim (http://diveintomark.org/) 
     2// Contributors: 
     3//  Justin Palmer (http://encytemedia.com/) 
     4//  Mark Pilgrim (http://diveintomark.org/) 
     5//  Martin Bialasinki 
    56//  
    6 // Permission is hereby granted, free of charge, to any person obtaining 
    7 // a copy of this software and associated documentation files (the 
    8 // "Software"), to deal in the Software without restriction, including 
    9 // without limitation the rights to use, copy, modify, merge, publish, 
    10 // distribute, sublicense, and/or sell copies of the Software, and to 
    11 // permit persons to whom the Software is furnished to do so, subject to 
    12 // the following conditions: 
    13 //  
    14 // The above copyright notice and this permission notice shall be 
    15 // included in all copies or substantial portions of the Software. 
    16 //  
    17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
    21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
    22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
    24  
    25  
    26 Effect = {} 
    27 Effect2 = Effect; // deprecated 
     7// See scriptaculous.js for full license.   
     8 
     9/* ------------- element ext -------------- */   
     10  
     11// converts rgb() and #xxx to #xxxxxx format,   
     12// returns self (or first argument) if not convertable   
     13String.prototype.parseColor = function() {   
     14  var color = '#';   
     15  if(this.slice(0,4) == 'rgb(') {   
     16    var cols = this.slice(4,this.length-1).split(',');   
     17    var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);   
     18  } else {   
     19    if(this.slice(0,1) == '#') {   
     20      if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();   
     21      if(this.length==7) color = this.toLowerCase();   
     22    }   
     23  }   
     24  return(color.length==7 ? color : (arguments[0] || this));   
     25} 
     26 
     27Element.collectTextNodes = function(element) {   
     28  return $A($(element).childNodes).collect( function(node) { 
     29    return (node.nodeType==3 ? node.nodeValue :  
     30      (node.hasChildNodes() ? Element.collectTextNodes(node) : '')); 
     31  }).flatten().join(''); 
     32} 
     33 
     34Element.collectTextNodesIgnoreClass = function(element, className) {   
     35  return $A($(element).childNodes).collect( function(node) { 
     36    return (node.nodeType==3 ? node.nodeValue :  
     37      ((node.hasChildNodes() && !Element.hasClassName(node,className)) ?  
     38        Element.collectTextNodes(node) : '')); 
     39  }).flatten().join(''); 
     40} 
     41 
     42Element.setStyle = function(element, style) { 
     43  element = $(element); 
     44  for(k in style) element.style[k.camelize()] = style[k]; 
     45} 
     46 
     47Element.setContentZoom = function(element, percent) {   
     48  Element.setStyle(element, {fontSize: (percent/100) + 'em'});    
     49  if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);   
     50} 
     51 
     52Element.getOpacity = function(element){   
     53  var opacity; 
     54  if (opacity = Element.getStyle(element, 'opacity'))   
     55    return parseFloat(opacity);   
     56  if (opacity = (Element.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/))   
     57    if(opacity[1]) return parseFloat(opacity[1]) / 100;   
     58  return 1.0;   
     59} 
     60 
     61Element.setOpacity = function(element, value){   
     62  element= $(element);   
     63  if (value == 1){ 
     64    Element.setStyle(element, { opacity:  
     65      (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ?  
     66      0.999999 : null }); 
     67    if(/MSIE/.test(navigator.userAgent))   
     68      Element.setStyle(element, {filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')});   
     69  } else {   
     70    if(value < 0.00001) value = 0;   
     71    Element.setStyle(element, {opacity: value}); 
     72    if(/MSIE/.test(navigator.userAgent))   
     73     Element.setStyle(element,  
     74       { filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') + 
     75                 'alpha(opacity='+value*100+')' });   
     76  }    
     77 
     78  
     79Element.getInlineOpacity = function(element){   
     80  return $(element).style.opacity || ''; 
     81 
     82 
     83Element.childrenWithClassName = function(element, className) {   
     84  return $A($(element).getElementsByTagName('*')).select( 
     85    function(c) { return Element.hasClassName(c, className) }); 
     86} 
     87 
     88Array.prototype.call = function() { 
     89  var args = arguments; 
     90  this.each(function(f){ f.apply(this, args) }); 
     91} 
     92 
     93/*--------------------------------------------------------------------------*/ 
     94 
     95var Effect = { 
     96  tagifyText: function(element) { 
     97    var tagifyStyle = 'position:relative'; 
     98    if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ';zoom:1'; 
     99    element = $(element); 
     100    $A(element.childNodes).each( function(child) { 
     101      if(child.nodeType==3) { 
     102        child.nodeValue.toArray().each( function(character) { 
     103          element.insertBefore( 
     104            Builder.node('span',{style: tagifyStyle}, 
     105              character == ' ' ? String.fromCharCode(160) : character),  
     106              child); 
     107        }); 
     108        Element.remove(child); 
     109      } 
     110    }); 
     111  }, 
     112  multiple: function(element, effect) { 
     113    var elements; 
     114    if(((typeof element == 'object') ||  
     115        (typeof element == 'function')) &&  
     116       (element.length)) 
     117      elements = element; 
     118    else 
     119      elements = $(element).childNodes; 
     120       
     121    var options = Object.extend({ 
     122      speed: 0.1, 
     123      delay: 0.0 
     124    }, arguments[2] || {}); 
     125    var masterDelay = options.delay; 
     126 
     127    $A(elements).each( function(element, index) { 
     128      new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay })); 
     129    }); 
     130  }, 
     131  PAIRS: { 
     132    'slide':  ['SlideDown','SlideUp'], 
     133    'blind':  ['BlindDown','BlindUp'], 
     134    'appear': ['Appear','Fade'] 
     135  }, 
     136  toggle: function(element, effect) { 
     137    element = $(element); 
     138    effect = (effect || 'appear').toLowerCase(); 
     139    var options = Object.extend({ 
     140      queue: { position:'end', scope:(element.id || 'global') } 
     141    }, arguments[2] || {}); 
     142    Effect[Element.visible(element) ?  
     143      Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options); 
     144  } 
     145}; 
     146 
     147var Effect2 = Effect; // deprecated 
    28148 
    29149/* ------------- transitions ------------- */ 
     
    41161} 
    42162Effect.Transitions.flicker = function(pos) { 
    43   return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random(0.25); 
     163  return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 
    44164} 
    45165Effect.Transitions.wobble = function(pos) { 
     
    47167} 
    48168Effect.Transitions.pulse = function(pos) { 
    49    return (Math.floor(pos*10) % 2 == 0 ?  
     169  return (Math.floor(pos*10) % 2 == 0 ?  
    50170    (pos*10-Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10))); 
    51171} 
    52  
    53172Effect.Transitions.none = function(pos) { 
    54     return 0; 
     173  return 0; 
    55174} 
    56175Effect.Transitions.full = function(pos) { 
    57     return 1; 
     176  return 1; 
    58177} 
    59178 
    60179/* ------------- core effects ------------- */ 
     180 
     181Effect.ScopedQueue = Class.create(); 
     182Object.extend(Object.extend(Effect.ScopedQueue.prototype, Enumerable), { 
     183  initialize: function() { 
     184    this.effects  = []; 
     185    this.interval = null; 
     186  }, 
     187  _each: function(iterator) { 
     188    this.effects._each(iterator); 
     189  }, 
     190  add: function(effect) { 
     191    var timestamp = new Date().getTime(); 
     192     
     193    var position = (typeof effect.options.queue == 'string') ?  
     194      effect.options.queue : effect.options.queue.position; 
     195     
     196    switch(position) { 
     197      case 'front': 
     198        // move unstarted effects after this effect   
     199        this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) { 
     200            e.startOn  += effect.finishOn; 
     201            e.finishOn += effect.finishOn; 
     202          }); 
     203        break; 
     204      case 'end': 
     205        // start effect after last queued effect has finished 
     206        timestamp = this.effects.pluck('finishOn').max() || timestamp; 
     207        break; 
     208    } 
     209     
     210    effect.startOn  += timestamp; 
     211    effect.finishOn += timestamp; 
     212    this.effects.push(effect); 
     213    if(!this.interval)  
     214      this.interval = setInterval(this.loop.bind(this), 40); 
     215  }, 
     216  remove: function(effect) { 
     217    this.effects = this.effects.reject(function(e) { return e==effect }); 
     218    if(this.effects.length == 0) { 
     219      clearInterval(this.interval); 
     220      this.interval = null; 
     221    } 
     222  }, 
     223  loop: function() { 
     224    var timePos = new Date().getTime(); 
     225    this.effects.invoke('loop', timePos); 
     226  } 
     227}); 
     228 
     229Effect.Queues = { 
     230  instances: $H(), 
     231  get: function(queueName) { 
     232    if(typeof queueName != 'string') return queueName; 
     233     
     234    if(!this.instances[queueName]) 
     235      this.instances[queueName] = new Effect.ScopedQueue(); 
     236       
     237    return this.instances[queueName]; 
     238  } 
     239} 
     240Effect.Queue = Effect.Queues.get('global'); 
     241 
     242Effect.DefaultOptions = { 
     243  transition: Effect.Transitions.sinoidal, 
     244  duration:   1.0,   // seconds 
     245  fps:        25.0,  // max. 25fps due to Effect.Queue implementation 
     246  sync:       false, // true for combining 
     247  from:       0.0, 
     248  to:         1.0, 
     249  delay:      0.0, 
     250  queue:      'parallel' 
     251} 
    61252 
    62253Effect.Base = function() {}; 
    63254Effect.Base.prototype = { 
    64   setOptions: function(options) { 
    65     this.options = { 
    66       transition: Effect.Transitions.sinoidal, 
    67       duration:   1.0,   // seconds 
    68       fps:        25.0,  // max. 100fps 
    69       sync:       false, // true for combining 
    70       from:       0.0, 
    71       to:         1.0 
    72     }.extend(options || {}); 
    73   }, 
     255  position: null, 
    74256  start: function(options) { 
    75     this.setOptions(options || {}); 
    76     this.currentFrame    = 0; 
    77     this.startOn  = new Date().getTime(); 
    78     this.finishOn = this.startOn + (this.options.duration*1000); 
    79     if(this.options.beforeStart) this.options.beforeStart(this); 
    80     if(!this.options.sync) this.loop();   
    81   }, 
    82   loop: function() { 
    83     timePos = new Date().getTime(); 
    84     if(timePos >= this.finishOn) { 
    85       this.render(this.options.to); 
    86       if(this.finish) this.finish();  
    87       if(this.options.afterFinish) this.options.afterFinish(this); 
    88       return;   
     257    this.options      = Object.extend(Object.extend({},Effect.DefaultOptions), options || {}); 
     258    this.currentFrame = 0; 
     259    this.state        = 'idle'; 
     260    this.startOn      = this.options.delay*1000; 
     261    this.finishOn     = this.startOn + (this.options.duration*1000); 
     262    this.event('beforeStart'); 
     263    if(!this.options.sync) 
     264      Effect.Queues.get(typeof this.options.queue == 'string' ?  
     265        'global' : this.options.queue.scope).add(this); 
     266  }, 
     267  loop: function(timePos) { 
     268    if(timePos >= this.startOn) { 
     269      if(timePos >= this.finishOn) { 
     270        this.render(1.0); 
     271        this.cancel(); 
     272        this.event('beforeFinish'); 
     273        if(this.finish) this.finish();  
     274        this.event('afterFinish'); 
     275        return;   
     276      } 
     277      var pos   = (timePos - this.startOn) / (this.finishOn - this.startOn); 
     278      var frame = Math.round(pos * this.options.fps * this.options.duration); 
     279      if(frame > this.currentFrame) { 
     280        this.render(pos); 
     281        this.currentFrame = frame; 
     282      } 
    89283    } 
    90     pos   = (timePos - this.startOn) / (this.finishOn - this.startOn); 
    91     frame = Math.round(pos * this.options.fps * this.options.duration); 
    92     if(frame > this.currentFrame) { 
    93       this.render(pos); 
    94       this.currentFrame = frame; 
     284  }, 
     285  render: function(pos) { 
     286    if(this.state == 'idle') { 
     287      this.state = 'running'; 
     288      this.event('beforeSetup'); 
     289      if(this.setup) this.setup(); 
     290      this.event('afterSetup'); 
    95291    } 
    96     this.timeout = setTimeout(this.loop.bind(this), 10); 
    97   }, 
    98   render: function(pos) { 
    99     if(this.options.transition) pos = this.options.transition(pos); 
    100     pos  = pos * (this.options.to-this.options.from); 
    101     pos += this.options.from;  
    102     if(this.options.beforeUpdate) this.options.beforeUpdate(this); 
    103     if(this.update) this.update(pos); 
    104     if(this.options.afterUpdate) this.options.afterUpdate(this);   
     292    if(this.state == 'running') { 
     293      if(this.options.transition) pos = this.options.transition(pos); 
     294      pos *= (this.options.to-this.options.from); 
     295      pos += this.options.from; 
     296      this.position = pos; 
     297      this.event('beforeUpdate'); 
     298      if(this.update) this.update(pos); 
     299      this.event('afterUpdate'); 
     300    } 
    105301  }, 
    106302  cancel: function() { 
    107     if(this.timeout) clearTimeout(this.timeout); 
     303    if(!this.options.sync) 
     304      Effect.Queues.get(typeof this.options.queue == 'string' ?  
     305        'global' : this.options.queue.scope).remove(this); 
     306    this.state = 'finished'; 
     307  }, 
     308  event: function(eventName) { 
     309    if(this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this); 
     310    if(this.options[eventName]) this.options[eventName](this); 
     311  }, 
     312  inspect: function() { 
     313    return '#<Effect:' + $H(this).inspect() + ',options:' + $H(this.options).inspect() + '>'; 
    108314  } 
    109315} 
    110316 
    111317Effect.Parallel = Class.create(); 
    112   Effect.Parallel.prototype = (new Effect.Base()).extend({ 
    113     initialize: function(effects) { 
    114       this.effects = effects || []; 
    115        this.start(arguments[1]); 
    116     }, 
    117     update: function(position) { 
    118        for (var i = 0; i < this.effects.length; i++) 
    119         this.effects[i].render(position);   
    120     }, 
    121     finish: function(position) { 
    122        for (var i = 0; i < this.effects.length; i++) 
    123           if(this.effects[i].finish) this.effects[i].finish(position); 
    124     } 
    125   }); 
     318Object.extend(Object.extend(Effect.Parallel.prototype, Effect.Base.prototype), { 
     319  initialize: function(effects) { 
     320    this.effects = effects || []; 
     321    this.start(arguments[1]); 
     322  }, 
     323  update: function(position) { 
     324    this.effects.invoke('render', position); 
     325  }, 
     326  finish: function(position) { 
     327    this.effects.each( function(effect) { 
     328      effect.render(1.0); 
     329      effect.cancel(); 
     330      effect.event('beforeFinish'); 
     331      if(effect.finish) effect.finish(position); 
     332      effect.event('afterFinish'); 
     333    }); 
     334  } 
     335}); 
    126336 
    127337Effect.Opacity = Class.create(); 
    128 Effect.Opacity.prototype = (new Effect.Base()).extend({ 
     338Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), { 
    129339  initialize: function(element) { 
    130340    this.element = $(element); 
    131     options = { 
    132       from: 0.0, 
     341    // make this work on IE on elements without 'layout' 
     342    if(/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout)) 
     343      Element.setStyle(this.element, {zoom: 1}); 
     344    var options = Object.extend({ 
     345      from: Element.getOpacity(this.element) || 0.0, 
    133346      to:   1.0 
    134     }.extend(arguments[1] || {}); 
     347    }, arguments[1] || {}); 
    135348    this.start(options); 
    136349  }, 
    137350  update: function(position) { 
    138     this.setOpacity(position); 
    139   },  
    140   setOpacity: function(opacity) { 
    141     opacity = (opacity == 1) ? 0.99999 : opacity; 
    142     this.element.style.opacity = opacity; 
    143     this.element.style.filter = "alpha(opacity:"+opacity*100+")"; 
     351    Element.setOpacity(this.element, position); 
    144352  } 
    145353}); 
    146354 
    147 Effect.MoveBy = Class.create(); 
    148  Effect.MoveBy.prototype = (new Effect.Base()).extend({ 
    149    initialize: function(element, toTop, toLeft) { 
    150      this.element      = $(element); 
    151      this.originalTop  = parseFloat(this.element.style.top || '0'); 
    152      this.originalLeft = parseFloat(this.element.style.left || '0'); 
    153      this.toTop        = toTop; 
    154      this.toLeft       = toLeft; 
    155      if(this.element.style.position == "") 
    156        this.element.style.position = "relative"; 
    157      this.start(arguments[3]); 
    158    }, 
    159    update: function(position) { 
    160      topd  = this.toTop  * position + this.originalTop; 
    161      leftd = this.toLeft * position + this.originalLeft; 
    162      this.setPosition(topd, leftd); 
    163    }, 
    164    setPosition: function(topd, leftd) { 
    165      this.element.style.top  = topd  + "px"; 
    166      this.element.style.left = leftd + "px"; 
    167    } 
     355Effect.Move = Class.create(); 
     356Object.extend(Object.extend(Effect.Move.prototype, Effect.Base.prototype), { 
     357  initialize: function(element) { 
     358    this.element = $(element); 
     359    var options = Object.extend({ 
     360      x:    0, 
     361      y:    0, 
     362      mode: 'relative' 
     363    }, arguments[1] || {}); 
     364    this.start(options); 
     365  }, 
     366  setup: function() { 
     367    // Bug in Opera: Opera returns the "real" position of a static element or 
     368    // relative element that does not have top/left explicitly set. 
     369    // ==> Always set top and left for position relative elements in your stylesheets  
     370    // (to 0 if you do not need them)  
     371    Element.makePositioned(this.element); 
     372    this.originalLeft = parseFloat(Element.getStyle(this.element,'left') || '0'); 
     373    this.originalTop  = parseFloat(Element.getStyle(this.element,'top')  || '0'); 
     374    if(this.options.mode == 'absolute') { 
     375      // absolute movement, so we need to calc deltaX and deltaY 
     376      this.options.x = this.options.x - this.originalLeft; 
     377      this.options.y = this.options.y - this.originalTop; 
     378    } 
     379  }, 
     380  update: function(position) { 
     381    Element.setStyle(this.element, { 
     382      left: this.options.x  * position + this.originalLeft + 'px', 
     383      top:  this.options.y  * position + this.originalTop  + 'px' 
     384    }); 
     385  } 
    168386}); 
    169387 
     388// for backwards compatibility 
     389Effect.MoveBy = function(element, toTop, toLeft) { 
     390  return new Effect.Move(element,  
     391    Object.extend({ x: toLeft, y: toTop }, arguments[3] || {})); 
     392}; 
     393 
    170394Effect.Scale = Class.create(); 
    171 Effect.Scale.prototype = (new Effect.Base()).extend({ 
     395Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), { 
    172396  initialize: function(element, percent) { 
    173397    this.element = $(element) 
    174     options = { 
     398    var options = Object.extend({ 
    175399      scaleX: true, 
    176400      scaleY: true, 
     
    178402      scaleFromCenter: false, 
    179403      scaleMode: 'box',        // 'box' or 'contents' or {} with provided values 
    180       scaleFrom: 100.0 
    181     }.extend(arguments[2] || {}); 
    182     this.originalTop    = this.element.offsetTop; 
    183     this.originalLeft   = this.element.offsetLeft; 
    184     if (this.element.style.fontSize=="") this.sizeEm = 1.0; 
    185     if (this.element.style.fontSize && this.element.style.fontSize.indexOf("em")>0) 
    186        this.sizeEm      = parseFloat(this.element.style.fontSize); 
    187     this.factor = (percent/100.0) - (options.scaleFrom/100.0); 
    188     if(options.scaleMode=='box') { 
    189       this.originalHeight = this.element.clientHeight; 
    190       this.originalWidth  = this.element.clientWidth;  
    191     } else  
    192     if(options.scaleMode=='contents') { 
    193       this.originalHeight = this.element.scrollHeight; 
    194       this.originalWidth  = this.element.scrollWidth; 
    195     } else { 
    196       this.originalHeight = options.scaleMode.originalHeight; 
    197       this.originalWidth  = options.scaleMode.originalWidth; 
    198     } 
     404      scaleFrom: 100.0, 
     405      scaleTo:   percent 
     406    }, arguments[2] || {}); 
    199407    this.start(options); 
    200408  }, 
    201  
     409  setup: function() { 
     410    this.restoreAfterFinish = this.options.restoreAfterFinish || false; 
     411    this.elementPositioning = Element.getStyle(this.element,'position'); 
     412     
     413    this.originalStyle = {}; 
     414    ['top','left','width','height','fontSize'].each( function(k) { 
     415      this.originalStyle[k] = this.element.style[k]; 
     416    }.bind(this)); 
     417       
     418    this.originalTop  = this.element.offsetTop; 
     419    this.originalLeft = this.element.offsetLeft; 
     420     
     421    var fontSize = Element.getStyle(this.element,'font-size') || '100%'; 
     422    ['em','px','%'].each( function(fontSizeType) { 
     423      if(fontSize.indexOf(fontSizeType)>0) { 
     424        this.fontSize     = parseFloat(fontSize); 
     425        this.fontSizeType = fontSizeType; 
     426      } 
     427    }.bind(this)); 
     428     
     429    this.factor = (this.options.scaleTo - this.options.scaleFrom)/100; 
     430     
     431    this.dims = null; 
     432    if(this.options.scaleMode=='box') 
     433      this.dims = [this.element.offsetHeight, this.element.offsetWidth]; 
     434    if(/^content/.test(this.options.scaleMode)) 
     435      this.dims = [this.element.scrollHeight, this.element.scrollWidth]; 
     436    if(!this.dims) 
     437      this.dims = [this.options.scaleMode.originalHeight, 
     438                   this.options.scaleMode.originalWidth]; 
     439  }, 
    202440  update: function(position) { 
    203     currentScale = (this.options.scaleFrom/100.0) + (this.factor * position); 
    204     if(this.options.scaleContent && this.sizeEm)  
    205       this.element.style.fontSize = this.sizeEm*currentScale + "em"; 
    206     this.setDimensions( 
    207      this.originalWidth * currentScale,  
    208      this.originalHeight * currentScale); 
    209   }, 
    210  
    211   setDimensions: function(width, height) { 
    212     if(this.options.scaleX) this.element.style.width = width + 'px'; 
    213     if(this.options.scaleY) this.element.style.height = height + 'px'; 
     441    var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position); 
     442    if(this.options.scaleContent && this.fontSize) 
     443      Element.setStyle(this.element, {fontSize: this.fontSize * currentScale + this.fontSizeType }); 
     444    this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale); 
     445  }, 
     446  finish: function(position) { 
     447    if (this.restoreAfterFinish) Element.setStyle(this.element, this.originalStyle); 
     448  }, 
     449  setDimensions: function(height, width) { 
     450    var d = {}; 
     451    if(this.options.scaleX) d.width = width + 'px'; 
     452    if(this.options.scaleY) d.height = height + 'px'; 
    214453    if(this.options.scaleFromCenter) { 
    215       topd  = (height - this.originalHeight)/2; 
    216       leftd = (width  - this.originalWidth)/2; 
    217       if(this.element.style.position=='absolute') { 
    218         if(this.options.scaleY) this.element.style.top = this.originalTop-topd + "px"; 
    219         if(this.options.scaleX) this.element.style.left = this.originalLeft-leftd + "px"; 
     454      var topd  = (height - this.dims[0])/2; 
     455      var leftd = (width  - this.dims[1])/2; 
     456      if(this.elementPositioning == 'absolute') { 
     457        if(this.options.scaleY) d.top = this.originalTop-topd + 'px'; 
     458        if(this.options.scaleX) d.left = this.originalLeft-leftd + 'px'; 
    220459      } else { 
    221         if(this.options.scaleY) this.element.style.top = -topd + "px"; 
    222         if(this.options.scaleX) this.element.style.left = -leftd + "px"; 
     460        if(this.options.scaleY) d.top = -topd + 'px'; 
     461        if(this.options.scaleX) d.left = -leftd + 'px'; 
    223462      } 
    224463    } 
     464    Element.setStyle(this.element, d); 
    225465  } 
    226466}); 
    227467 
    228468Effect.Highlight = Class.create(); 
    229 Effect.Highlight.prototype = (new Effect.Base()).extend({ 
     469Object.extend(Object.extend(Effect.Highlight.prototype, Effect.Base.prototype), { 
    230470  initialize: function(element) { 
    231471    this.element = $(element); 
    232      
    233     // try to parse current background color as default for endcolor 
    234     // browser stores this as: "rgb(255, 255, 255)", convert to "#ffffff" format 
    235     var endcolor = "#ffffff"; 
    236     var current = this.element.style.backgroundColor; 
    237     if(current && current.slice(0,4) == "rgb(") { 
    238       endcolor = "#"; 
    239       var cols = current.slice(4,current.length-1).split(','); 
    240       var i=0; do { endcolor += parseInt(cols[i]).toColorPart() } while (++i<3); } 
    241        
    242     var options = { 
    243       startcolor: "#ffff99", 
    244       endcolor:   endcolor 
    245     }.extend(arguments[1] || {}); 
    246      
     472    var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {}); 
     473    this.start(options); 
     474  }, 
     475  setup: function() { 
     476    // Prevent executing on elements not in the layout flow 
     477    if(Element.getStyle(this.element, 'display')=='none') { this.cancel(); return; } 
     478    // Disable background image during the effect 
     479    this.oldStyle = { 
     480      backgroundImage: Element.getStyle(this.element, 'background-image') }; 
     481    Element.setStyle(this.element, {backgroundImage: 'none'}); 
     482    if(!this.options.endcolor) 
     483      this.options.endcolor = Element.getStyle(this.element, 'background-color').parseColor('#ffffff'); 
     484    if(!this.options.restorecolor) 
     485      this.options.restorecolor = Element.getStyle(this.element, 'background-color'); 
    247486    // init color calculations 
    248     this.colors_base = [ 
    249       parseInt(options.startcolor.slice(1,3),16), 
    250       parseInt(options.startcolor.slice(3,5),16), 
    251       parseInt(options.startcolor.slice(5),16) ]; 
    252     this.colors_delta = [ 
    253       parseInt(options.endcolor.slice(1,3),16)-this.colors_base[0], 
    254       parseInt(options.endcolor.slice(3,5),16)-this.colors_base[1], 
    255       parseInt(options.endcolor.slice(5),16)-this.colors_base[2] ]; 
    256  
    257     this.start(options); 
     487    this._base  = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this)); 
     488    this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this)); 
    258489  }, 
    259490  update: function(position) { 
    260     var colors = [ 
    261       Math.round(this.colors_base[0]+(this.colors_delta[0]*position)), 
    262       Math.round(this.colors_base[1]+(this.colors_delta[1]*position)), 
    263       Math.round(this.colors_base[2]+(this.colors_delta[2]*position)) ]; 
    264     this.element.style.backgroundColor = "#" + 
    265       colors[0].toColorPart() + colors[1].toColorPart() + colors[2].toColorPart(); 
     491    Element.setStyle(this.element,{backgroundColor: $R(0,2).inject('#',function(m,v,i){ 
     492      return m+(Math.round(this._base[i]+(this._delta[i]*position)).toColorPart()); }.bind(this)) }); 
     493  }, 
     494  finish: function() { 
     495    Element.setStyle(this.element, Object.extend(this.oldStyle, { 
     496      backgroundColor: this.options.restorecolor 
     497    })); 
    266498  } 
    267499}); 
    268500 
    269  
    270 /* ------------- prepackaged effects ------------- */ 
    271  
    272 Effect.Fade =  function(element) { 
    273   options = { 
    274   from: 1.0, 
     501Effect.ScrollTo = Class.create(); 
     502Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), { 
     503  initialize: function(element) { 
     504    this.element = $(element); 
     505    this.start(arguments[1] || {}); 
     506  }, 
     507  setup: function() { 
     508    Position.prepare(); 
     509    var offsets = Position.cumulativeOffset(this.element); 
     510    if(this.options.offset) offsets[1] += this.options.offset; 
     511    var max = window.innerHeight ?  
     512      window.height - window.innerHeight : 
     513      document.body.scrollHeight -  
     514        (document.documentElement.clientHeight ?  
     515          document.documentElement.clientHeight : document.body.clientHeight); 
     516    this.scrollStart = Position.deltaY; 
     517    this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart; 
     518  }, 
     519  update: function(position) { 
     520    Position.prepare(); 
     521    window.scrollTo(Position.deltaX,  
     522      this.scrollStart + (position*this.delta)); 
     523  } 
     524}); 
     525 
     526/* ------------- combination effects ------------- */ 
     527 
     528Effect.Fade = function(element) { 
     529  var oldOpacity = Element.getInlineOpacity(element); 
     530  var options = Object.extend({ 
     531  from: Element.getOpacity(element) || 1.0, 
    275532  to:   0.0, 
    276   afterFinish: function(effect)  
    277     { Element.hide(effect.element); 
    278       effect.setOpacity(1); }  
    279   }.extend(arguments[1] || {}); 
    280   new Effect.Opacity(element,options); 
    281 } 
    282  
    283 Effect.Appear =  function(element) { 
    284   options = { 
    285   from: 0.0, 
     533  afterFinishInternal: function(effect) { with(Element) {  
     534    if(effect.options.to!=0) return; 
     535    hide(effect.element); 
     536    setStyle(effect.element, {opacity: oldOpacity}); }} 
     537  }, arguments[1] || {}); 
     538  return new Effect.Opacity(element,options); 
     539} 
     540 
     541Effect.Appear = function(element) { 
     542  var options = Object.extend({ 
     543  from: (Element.getStyle(element, 'display') == 'none' ? 0.0 : Element.getOpacity(element) || 0.0), 
    286544  to:   1.0, 
    287   beforeStart: function(effect)   
    288     { effect.setOpacity(0); 
    289       Element.show(effect.element); }, 
    290   afterUpdate: function(effect)   
    291     { Element.show(effect.element); } 
    292   }.extend(arguments[1] || {}); 
    293   new Effect.Opacity(element,options); 
     545  beforeSetup: function(effect) { with(Element) { 
     546    setOpacity(effect.element, effect.options.from); 
     547    show(effect.element); }} 
     548  }, arguments[1] || {}); 
     549  return new Effect.Opacity(element,options); 
    294550} 
    295551 
    296552Effect.Puff = function(element) { 
    297   new Effect.Parallel( 
    298    [ new Effect.Scale(element, 200, { sync: true, scaleFromCenter: true }),  
    299      new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0 } ) ],  
    300      { duration: 1.0,  
    301       afterUpdate: function(effect)  
    302        { effect.effects[0].element.style.position = 'absolute'; }, 
    303       afterFinish: function(effect) 
    304        { Element.hide(effect.effects[0].element); } 
    305      } 
     553  element = $(element); 
     554  var oldStyle = { opacity: Element.getInlineOpacity(element), position: Element.getStyle(element, 'position') }; 
     555  return new Effect.Parallel( 
     556   [ new Effect.Scale(element, 200,  
     557      { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }),  
     558     new Effect.Opacity(element, { sync: true, to: 0.0 } ) ],  
     559     Object.extend({ duration: 1.0,  
     560      beforeSetupInternal: function(effect) { with(Element) { 
     561        setStyle(effect.effects[0].element, {position: 'absolute'}); }}, 
     562      afterFinishInternal: function(effect) { with(Element) { 
     563         hide(effect.effects[0].element); 
     564         setStyle(effect.effects[0].element, oldStyle); }} 
     565     }, arguments[1] || {}) 
    306566   ); 
    307567} 
    308568 
    309569Effect.BlindUp = function(element) { 
    310   $(element).style.overflow = 'hidden'; 
    311   new Effect.Scale(element, 0,  
    312     { scaleContent: false,  
     570  element = $(element); 
     571  Element.makeClipping(element); 
     572  return new Effect.Scale(element, 0,  
     573    Object.extend({ scaleContent: false,  
    313574      scaleX: false,  
    314       afterFinish: function(effect)  
    315         { Element.hide(effect.element) }  
    316     }.extend(arguments[1] || {}) 
     575      restoreAfterFinish: true, 
     576      afterFinishInternal: function(effect) { with(Element) { 
     577        [hide, undoClipping].call(effect.element); }}  
     578    }, arguments[1] || {}) 
    317579  ); 
    318580} 
    319581 
    320582Effect.BlindDown = function(element) { 
    321   $(element).style.height   = '0px'; 
    322   $(element).style.overflow = 'hidden'; 
    323   Element.show(element); 
    324   new Effect.Scale(element, 100,  
    325     { scaleContent: false,  
    326       scaleX: false,  
    327       scaleMode: 'contents', 
    328       scaleFrom: 0 
    329     }.extend(arguments[1] || {}) 
     583  element = $(element); 
     584  var oldHeight = Element.getStyle(element, 'height'); 
     585  var elementDimensions = Element.getDimensions(element); 
     586  return new Effect.Scale(element, 100,  
     587    Object.extend({ scaleContent: false,  
     588      scaleX: false, 
     589      scaleFrom: 0, 
     590      scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 
     591      restoreAfterFinish: true, 
     592      afterSetup: function(effect) { with(Element) { 
     593        makeClipping(effect.element); 
     594        setStyle(effect.element, {height: '0px'}); 
     595        show(effect.element);  
     596      }},   
     597      afterFinishInternal: function(effect) { with(Element) { 
     598        undoClipping(effect.element); 
     599        setStyle(effect.element, {height: oldHeight}); 
     600      }} 
     601    }, arguments[1] || {}) 
    330602  ); 
    331603} 
    332604 
    333605Effect.SwitchOff = function(element) { 
    334   new Effect.Appear(element, 
    335     { duration: 0.4, 
    336      transition: Effect.Transitions.flicker, 
    337      afterFinish: function(effect) 
    338       {  effect.element.style.overflow = 'hidden'; 
    339         new Effect.Scale(effect.element, 1,  
    340          { duration: 0.3, scaleFromCenter: true, 
    341           scaleX: false, scaleContent: false, 
    342           afterUpdate: function(effect) {  
    343            if(effect.element.style.position=="") 
    344              effect.element.style.position = 'relative'; }, 
    345           afterFinish: function(effect) { Element.hide(effect.element); } 
    346          } ) 
    347       } 
    348     } ) 
     606  element = $(element); 
     607  var oldOpacity = Element.getInlineOpacity(element); 
     608  return new Effect.Appear(element, {  
     609    duration: 0.4, 
     610    from: 0, 
     611    transition: Effect.Transitions.flicker, 
     612    afterFinishInternal: function(effect) { 
     613      new Effect.Scale(effect.element, 1, {  
     614        duration: 0.3, scaleFromCenter: true, 
     615        scaleX: false, scaleContent: false, restoreAfterFinish: true, 
     616        beforeSetup: function(effect) { with(Element) { 
     617          [makePositioned,makeClipping].call(effect.element); 
     618        }}, 
     619        afterFinishInternal: function(effect) { with(Element) { 
     620          [hide,undoClipping,undoPositioned].call(effect.element); 
     621          setStyle(effect.element, {opacity: oldOpacity}); 
     622        }} 
     623      }) 
     624    } 
     625  }); 
    349626} 
    350627 
    351628Effect.DropOut = function(element) { 
    352   new Effect.Parallel( 
    353     [ new Effect.MoveBy(element, 100, 0, { sync: true }),  
    354       new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0 } ) ],  
    355     { duration: 0.5,  
    356      afterFinish: function(effect) 
    357        { Element.hide(effect.effects[0].element); }  
    358     }); 
     629  element = $(element); 
     630  var oldStyle = { 
     631    top: Element.getStyle(element, 'top'), 
     632    left: Element.getStyle(element, 'left'), 
     633    opacity: Element.getInlineOpacity(element) }; 
     634  return new Effect.Parallel( 
     635    [ new Effect.Move(element, {x: 0, y: 100, sync: true }),  
     636      new Effect.Opacity(element, { sync: true, to: 0.0 }) ], 
     637    Object.extend( 
     638      { duration: 0.5, 
     639        beforeSetup: function(effect) { with(Element) { 
     640          makePositioned(effect.effects[0].element); }}, 
     641        afterFinishInternal: function(effect) { with(Element) { 
     642          [hide, undoPositioned].call(effect.effects[0].element); 
     643          setStyle(effect.effects[0].element, oldStyle); }}  
     644      }, arguments[1] || {})); 
    359645} 
    360646 
    361647Effect.Shake = function(element) { 
    362   new Effect.MoveBy(element, 0, 20,  
    363     { duration: 0.05, afterFinish: function(effect) { 
    364   new Effect.MoveBy(effect.element, 0, -40,  
    365     { duration: 0.1, afterFinish: function(effect) {  
    366   new Effect.MoveBy(effect.element, 0, 40,  
    367     { duration: 0.1, afterFinish: function(effect) {   
    368   new Effect.MoveBy(effect.element, 0, -40,  
    369     { duration: 0.1, afterFinish: function(effect) {   
    370   new Effect.MoveBy(effect.element, 0, 40,  
    371     { duration: 0.1, afterFinish: function(effect) {   
    372   new Effect.MoveBy(effect.element, 0, -20,  
    373     { duration: 0.05, afterFinish: function(effect) {   
    374   }}) }}) }}) }}) }}) }}); 
     648  element = $(element); 
     649  var oldStyle = { 
     650    top: Element.getStyle(element, 'top'), 
     651    left: Element.getStyle(element, 'left') }; 
     652          return new Effect.Move(element,  
     653            { x:  20, y: 0, duration: 0.05, afterFinishInternal: function(effect) { 
     654          new Effect.Move(effect.element, 
     655            { x: -40, y: 0, duration: 0.1,  afterFinishInternal: function(effect) { 
     656          new Effect.Move(effect.element, 
     657            { x:  40, y: 0, duration: 0.1,  afterFinishInternal: function(effect) { 
     658          new Effect.Move(effect.element, 
     659            { x: -40, y: 0, duration: 0.1,  afterFinishInternal: function(effect) { 
     660          new Effect.Move(effect.element, 
     661            { x:  40, y: 0, duration: 0.1,  afterFinishInternal: function(effect) { 
     662          new Effect.Move(effect.element, 
     663            { x: -20, y: 0, duration: 0.05, afterFinishInternal: function(effect) { with(Element) { 
     664        undoPositioned(effect.element); 
     665        setStyle(effect.element, oldStyle); 
     666  }}}) }}) }}) }}) }}) }}); 
    375667} 
    376668 
    377669Effect.SlideDown = function(element) { 
    378   $(element).style.height   = '0px'; 
    379   $(element).style.overflow = 'hidden'; 
    380   $(element).firstChild.style.position = 'relative'; 
    381   Element.show(element); 
    382   new Effect.Scale(element, 100,  
    383    { scaleContent: false,  
     670  element = $(element); 
     671  Element.cleanWhitespace(element); 
     672  // SlideDown need to have the content of the element wrapped in a container element with fixed height! 
     673  var oldInnerBottom = Element.getStyle(element.firstChild, 'bottom'); 
     674  var elementDimensions = Element.getDimensions(element); 
     675  return new Effect.Scale(element, 100, Object.extend({  
     676    scaleContent: false,  
    384677    scaleX: false,  
    385     scaleMode: 'contents', 
    386678    scaleFrom: 0, 
    387     afterUpdate: function(effect)  
    388       { effect.element.firstChild.style.bottom =  
    389           (effect.originalHeight - effect.element.clientHeight) + 'px'; } 
    390     }.extend(arguments[1] || {}) 
     679    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, 
     680    restoreAfterFinish: true, 
     681    afterSetup: function(effect) { with(Element) { 
     682      makePositioned(effect.element); 
     683      makePositioned(effect.element.firstChild); 
     684      if(window.opera) setStyle(effect.element, {top: ''}); 
     685      makeClipping(effect.element); 
     686      setStyle(effect.element, {height: '0px'}); 
     687      show(element); }}, 
     688    afterUpdateInternal: function(effect) { with(Element) { 
     689      setStyle(effect.element.firstChild, {bottom: 
     690        (effect.dims[0] - effect.element.clientHeight) + 'px' }); }}, 
     691    afterFinishInternal: function(effect) { with(Element) { 
     692      undoClipping(effect.element);  
     693      undoPositioned(effect.element.firstChild); 
     694      undoPositioned(effect.element); 
     695      setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); }} 
     696    }, arguments[1] || {}) 
    391697  ); 
    392698} 
    393699   
    394700Effect.SlideUp = function(element) { 
    395   $(element).style.overflow = 'hidden'; 
    396   $(element).firstChild.style.position = 'relative'; 
    397   Element.show(element); 
    398   new Effect.Scale(element, 0,  
    399    { scaleContent: false,  
     701  element = $(element); 
     702  Element.cleanWhitespace(element); 
     703  var oldInnerBottom = Element.getStyle(element.firstChild, 'bottom'); 
     704  return new Effect.Scale(element, 0,  
     705   Object.extend({ scaleContent: false,  
    400706    scaleX: false,  
    401     afterUpdate: function(effect)  
    402       { effect.element.firstChild.style.bottom =  
    403           (effect.originalHeight - effect.element.clientHeight) + 'px'; }, 
    404     afterFinish: function(effect) 
    405       { Element.hide(effect.element); } 
    406    }.extend(arguments[1] || {}) 
     707    scaleMode: 'box', 
     708    scaleFrom: 100, 
     709    restoreAfterFinish: true, 
     710    beforeStartInternal: function(effect) { with(Element) { 
     711      makePositioned(effect.element); 
     712      makePositioned(effect.element.firstChild); 
     713      if(window.opera) setStyle(effect.element, {top: ''}); 
     714      makeClipping(effect.element); 
     715      show(element); }},   
     716    afterUpdateInternal: function(effect) { with(Element) { 
     717      setStyle(effect.element.firstChild, {bottom: 
     718        (effect.dims[0] - effect.element.clientHeight) + 'px' }); }}, 
     719    afterFinishInternal: function(effect) { with(Element) { 
     720        [hide, undoClipping].call(effect.element);  
     721        undoPositioned(effect.element.firstChild); 
     722        undoPositioned(effect.element); 
     723        setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); }} 
     724   }, arguments[1] || {}) 
    407725  ); 
    408726} 
    409727 
     728// Bug in opera makes the TD containing this element expand for a instance after finish  
    410729Effect.Squish = function(element) { 
    411  new Effect.Scale(element, 0,  
    412    { afterFinish: function(effect) { Element.hide(effect.element); } }); 
     730  return new Effect.Scale(element, window.opera ? 1 : 0,  
     731    { restoreAfterFinish: true, 
     732      beforeSetup: function(effect) { with(Element) { 
     733        makeClipping(effect.element); }},   
     734      afterFinishInternal: function(effect) { with(Element) { 
     735        hide(effect.element);  
     736        undoClipping(effect.element); }} 
     737  }); 
    413738} 
    414739 
    415740Effect.Grow = function(element) { 
    416741  element = $(element); 
    417   var options = arguments[1] || {}; 
    418    
    419   var originalWidth = element.clientWidth; 
    420   var originalHeight = element.clientHeight; 
    421   element.style.overflow = 'hidden'; 
    422   Element.show(element); 
    423    
    424   var direction = options.direction || 'center'; 
    425   var moveTransition = options.moveTransition || Effect.Transitions.sinoidal; 
    426   var scaleTransition = options.scaleTransition || Effect.Transitions.sinoidal; 
    427   var opacityTransition = options.opacityTransition || Effect.Transitions.full; 
    428    
     742  var options = Object.extend({ 
     743    direction: 'center', 
     744    moveTransistion: Effect.Transitions.sinoidal, 
     745    scaleTransition: Effect.Transitions.sinoidal, 
     746    opacityTransition: Effect.Transitions.full 
     747  }, arguments[1] || {}); 
     748  var oldStyle = { 
     749    top: element.style.top, 
     750    left: element.style.left, 
     751    height: element.style.height, 
     752    width: element.style.width, 
     753    opacity: Element.getInlineOpacity(element) }; 
     754 
     755  var dims = Element.getDimensions(element);     
    429756  var initialMoveX, initialMoveY; 
    430757  var moveX, moveY; 
    431758   
    432   switch (direction) { 
     759  switch (options.direction) { 
    433760    case 'top-left': 
    434761      initialMoveX = initialMoveY = moveX = moveY = 0;  
    435762      break; 
    436763    case 'top-right': 
    437       initialMoveX = originalWidth; 
     764      initialMoveX = dims.width; 
    438765      initialMoveY = moveY = 0; 
    439       moveX = -originalWidth; 
     766      moveX = -dims.width; 
    440767      break; 
    441768    case 'bottom-left': 
    442769      initialMoveX = moveX = 0; 
    443       initialMoveY = originalHeight; 
    444       moveY = -originalHeight; 
     770      initialMoveY = dims.height; 
     771      moveY = -dims.height; 
    445772      break; 
    446773    case 'bottom-right': 
    447       initialMoveX = originalWidth; 
    448       initialMoveY = originalHeight; 
    449       moveX = -originalWidth; 
    450       moveY = -originalHeight; 
     774      initialMoveX = dims.width; 
     775      initialMoveY = dims.height; 
     776      moveX = -dims.width; 
     777      moveY = -dims.height; 
    451778      break; 
    452779    case 'center': 
    453       initialMoveX = originalWidth / 2; 
    454       initialMoveY = originalHeight / 2; 
    455       moveX = -originalWidth / 2; 
    456       moveY = -originalHeight / 2; 
     780      initialMoveX = dims.width / 2; 
     781      initialMoveY = dims.height / 2; 
     782      moveX = -dims.width / 2; 
     783      moveY = -dims.height / 2; 
    457784      break; 
    458785  } 
    459786   
    460   new Effect.MoveBy(element, initialMoveY, initialMoveX, {  
     787  return new Effect.Move(element, { 
     788    x: initialMoveX, 
     789    y: initialMoveY, 
    461790    duration: 0.01,  
    462     beforeUpdate: function(effect) { $(element).style.height = '0px'; }, 
    463     afterFinish: function(effect) { 
     791    beforeSetup: function(effect) { with(Element) { 
     792      hide(effect.element); 
     793      makeClipping(effect.element); 
     794      makePositioned(effect.element); 
     795    }}, 
     796    afterFinishInternal: function(effect) { 
    464797      new Effect.Parallel( 
    465         [ new Effect.Opacity(element, { sync: true, to: 1.0, from: 0.0, transition: opacityTransition }), 
    466           new Effect.MoveBy(element, moveY, moveX, { sync: true, transition: moveTransition }), 
    467           new Effect.Scale(element, 100, {  
    468             scaleMode: { originalHeight: originalHeight, originalWidth: originalWidth },  
    469             sync: true, scaleFrom: 0, scaleTo: 100, transition: scaleTransition })], 
    470         options); } 
    471     }); 
     798        [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }), 
     799          new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }), 
     800          new Effect.Scale(effect.element, 100, { 
     801            scaleMode: { originalHeight: dims.height, originalWidth: dims.width },  
     802            sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true}) 
     803        ], Object.extend({ 
     804             beforeSetup: function(effect) { with(Element) { 
     805               setStyle(effect.effects[0].element, {height: '0px'}); 
     806               show(effect.effects[0].element); }}, 
     807             afterFinishInternal: function(effect) { with(Element) { 
     808               [undoClipping, undoPositioned].call(effect.effects[0].element);  
     809               setStyle(effect.effects[0].element, oldStyle); }} 
     810           }, options) 
     811      ) 
     812    } 
     813  }); 
    472814} 
    473815 
    474816Effect.Shrink = function(element) { 
    475817  element = $(element); 
    476   var options = arguments[1] || {}; 
    477    
    478   var originalWidth = element.clientWidth; 
    479   var originalHeight = element.clientHeight; 
    480   element.style.overflow = 'hidden'; 
    481   Element.show(element); 
    482  
    483   var direction = options.direction || 'center'; 
    484   var moveTransition = options.moveTransition || Effect.Transitions.sinoidal; 
    485   var scaleTransition = options.scaleTransition || Effect.Transitions.sinoidal; 
    486   var opacityTransition = options.opacityTransition || Effect.Transitions.none; 
    487    
     818  var options = Object.extend({ 
     819    direction: 'center', 
     820    moveTransistion: Effect.Transitions.sinoidal, 
     821    scaleTransition: Effect.Transitions.sinoidal, 
     822    opacityTransition: Effect.Transitions.none 
     823  }, arguments[1] || {}); 
     824  var oldStyle = { 
     825    top: element.style.top, 
     826    left: element.style.left, 
     827    height: element.style.height, 
     828    width: element.style.width, 
     829    opacity: Element.getInlineOpacity(element) }; 
     830 
     831  var dims = Element.getDimensions(element); 
    488832  var moveX, moveY; 
    489833   
    490   switch (direction) { 
     834  switch (options.direction) { 
    491835    case 'top-left': 
    492836      moveX = moveY = 0; 
    493837      break; 
    494838    case 'top-right': 
    495       moveX = originalWidth; 
     839      moveX = dims.width; 
    496840      moveY = 0; 
    497841      break; 
    498842    case 'bottom-left': 
    499843      moveX = 0; 
    500       moveY = originalHeight; 
     844      moveY = dims.height; 
    501845      break; 
    502846    case 'bottom-right': 
    503       moveX = originalWidth; 
    504       moveY = originalHeight; 
     847      moveX = dims.width; 
     848      moveY = dims.height; 
    505849      break; 
    506850    case 'center':   
    507       moveX = originalWidth / 2; 
    508       moveY = originalHeight / 2; 
     851      moveX = dims.width / 2; 
     852      moveY = dims.height / 2; 
    509853      break; 
    510854  } 
    511855   
    512   new Effect.Parallel( 
    513     [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: opacityTransition }), 
    514       new Effect.Scale(element, 0, { sync: true, transition: moveTransition }), 
    515       new Effect.MoveBy(element, moveY, moveX, { sync: true, transition: scaleTransition }) ], 
    516     options); 
     856  return new Effect.Parallel( 
     857    [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }), 
     858      new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}), 
     859      new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }) 
     860    ], Object.extend({             
     861         beforeStartInternal: function(effect) { with(Element) { 
     862           [makePositioned, makeClipping].call(effect.effects[0].element) }}, 
     863         afterFinishInternal: function(effect) { with(Element) { 
     864           [hide, undoClipping, undoPositioned].call(effect.effects[0].element); 
     865           setStyle(effect.effects[0].element, oldStyle); }} 
     866       }, options) 
     867  ); 
    517868} 
    518869 
    519870Effect.Pulsate = function(element) { 
     871  element = $(element); 
    520872  var options    = arguments[1] || {}; 
     873  var oldOpacity = Element.getInlineOpacity(element); 
    521874  var transition = options.transition || Effect.Transitions.sinoidal; 
    522875  var reverser   = function(pos){ return transition(1-Effect.Transitions.pulse(pos)) }; 
    523876  reverser.bind(transition); 
    524   new Effect.Opacity(element,  
    525     {  duration: 3.0, 
    526        afterFinish: function(effect) { Element.show(effect.element); } 
    527     }.extend(options).extend({transition: reverser})); 
     877  return new Effect.Opacity(element,  
     878    Object.extend(Object.extend({  duration: 3.0, from: 0, 
     879      afterFinishInternal: function(effect) { Element.setStyle(effect.element, {opacity: oldOpacity}); } 
     880    }, options), {transition: reverser})); 
    528881} 
    529882 
    530883Effect.Fold = function(element) { 
    531  $(element).style.overflow = 'hidden'; 
    532  new Effect.Scale(element, 5, {    
    533    scaleContent: false, 
    534    scaleTo: 100, 
    535    scaleX: false, 
    536    afterFinish: function(effect) { 
    537    new Effect.Scale(element, 1, {  
    538      scaleContent: false,  
    539      scaleTo: 0, 
    540      scaleY: false, 
    541      afterFinish: function(effect) { Element.hide(effect.element) } }); 
    542  }}.extend(arguments[1] || {})); 
    543 } 
    544  
    545 // old: new Effect.ContentZoom(element, percent) 
    546 // new: Element.setContentZoom(element, percent)  
    547  
    548 Element.setContentZoom = function(element, percent) { 
    549   var element = $(element); 
    550   element.style.fontSize = (percent/100) + "em";   
    551   if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); 
    552 } 
     884  element = $(element); 
     885  var oldStyle = { 
     886    top: element.style.top, 
     887    left: element.style.left, 
     888    width: element.style.width, 
     889    height: element.style.height }; 
     890  Element.makeClipping(element); 
     891  return new Effect.Scale(element, 5, Object.extend({    
     892    scaleContent: false, 
     893    scaleX: false, 
     894    afterFinishInternal: function(effect) { 
     895    new Effect.Scale(element, 1, {  
     896      scaleContent: false,  
     897      scaleY: false, 
     898      afterFinishInternal: function(effect) { with(Element) { 
     899        [hide, undoClipping].call(effect.element);  
     900        setStyle(effect.element, oldStyle); 
     901      }} }); 
     902  }}, arguments[1] || {})); 
     903}