﻿// Adapted from moo.fx

var Effects = {
  fadeRemove: function(element) {
    new Fx.Opacity(element, { duration: 350, onComplete: function() {
      element.parentNode.removeChild(element);
    } }).custom(1, 0);
  },
  
  appendAppear: function(element, container) {
    var effect  = new Fx.Opacity(element, { duration: 350 });
    
    effect.setStyle(element, 'opacity', 0);
    container.appendChild(element);
    effect.custom(0, 1);
  }
};


// Effects.Base = Class.create({
// 
//  setOptions: function(options){
//    var defaults = {
//      onStart: function(){},
//      onComplete: function(){},
//      transition: Effects.Transitions.sineInOut,
//      duration: 500,
//      unit: 'px',
//      wait: true,
//      fps: 50
//    };
//    
//    this.options = {};
//    for (var prop in defaults) {
//      this.options[prop] = options[prop] || defaults[prop];
//    }
//  },
// 
//  step: function(){
//    var time = new Date().getTime(), object = this;
//    if (time < this.time + this.options.duration){
//      this.cTime = time - this.time;
//      this.setNow();
//    } else {
//      setTimeout(function() {
//        object.options.onComplete(object.element);
//      }, 10);
//      this.clearTimer();
//      this.now = this.to;
//    }
//    this.increase();
//  },
// 
//  setNow: function(){
//    this.now = this.compute(this.from, this.to);
//  },
// 
//  compute: function(from, to){
//    var change = to - from;
//    return this.options.transition(this.cTime, from, change, this.options.duration);
//  },
// 
//  clearTimer: function(){
//    clearInterval(this.timer);
//    this.timer = null;
//    return this;
//  },
// 
//  _start: function(from, to){
//    var object = this;
//    if (!this.options.wait) this.clearTimer();
//    if (this.timer) return;
//    setTimeout(function() {
//      object.options.onStart(object.element);
//    }, 10);
//    this.from = from;
//    this.to = to;
//    this.time = new Date().getTime();
//    this.timer = setInterval(function() {
//      object.step();
//    }, Math.round(1000/this.options.fps));
//    return this;
//  },
// 
//  custom: function(from, to){
//    return this._start(from, to);
//  },
// 
//  set: function(to){
//    this.now = to;
//    this.increase();
//    return this;
//  },
// 
//  hide: function(){
//    return this.set(0);
//  },
// 
//  setStyle: function(e, p, v){
//    if (p == 'opacity'){
//      //if (v == 0 && e.style.visibility != "hidden") e.style.visibility = "hidden";
//      //else if (e.style.visibility != "visible") e.style.visibility = "visible";
//      if (window.ActiveXObject) e.style.filter = "alpha(opacity=" + v*100 + ")";
//      e.style.opacity = v;
//    } else e.style[p] = v+this.options.unit;
//  }
// 
// });
// 
// Effects.Style = Effects.Base.extend({
// 
//  initialize: function(el, property, options){
//    this.element = el;
//    this.setOptions(options);
//    //this.property = property.camelize();
//    this.property = property;
//  },
// 
//  increase: function(){
//    this.setStyle(this.element, this.property, this.now);
//  }
// 
// });
// 
// Effects.Styles = Effects.Base.extend({
// 
//  initialize: function(el, options){
//    this.element = el;
//    this.setOptions(options);
//    this.now = {};
//  },
// 
//  setNow: function(){
//    for (p in this.from) this.now[p] = this.compute(this.from[p], this.to[p]);
//  },
// 
//  custom: function(obj){
//    if (this.timer && this.options.wait) return;
//    var from = {};
//    var to = {};
//    for (p in obj){
//      from[p] = obj[p][0];
//      to[p] = obj[p][1];
//    }
//    return this._start(from, to);
//  },
// 
//  increase: function(){
//    for (var p in this.now) this.setStyle(this.element, p, this.now[p]);
//  }
// 
// });
// 
// //Transitions (c) 2003 Robert Penner (http://www.robertpenner.com/easing/), BSD License.
// 
// Effects.Transitions = {
//  linear: function(t, b, c, d) { return c*t/d + b; },
//  sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; }
// };
// 
// Effects.Opacity = Effects.Base.extend({
// 
//  initialize: function(el, options){
//    this.element = el;
//    this.setOptions(options);
//    this.now = 1;
//  },
// 
//  toggle: function(){
//    if (this.now > 0) return this.custom(1, 0);
//    else return this.custom(0, 1);
//  },
// 
//  show: function(){
//    return this.set(1);
//  },
//  
//  increase: function(){
//    this.setStyle(this.element, 'opacity', this.now);
//  }
// });