var Rico = {}
//-------------------- ricoEffects.js
Rico.Effect = {};
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}
var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}
var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}
Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Rico.Effect.SizeAndPosition = Class.create();
Rico.Effect.SizeAndPosition.prototype = {

   initialize: function(element, x, y, w, h, duration, steps, options) {
      this.element = $(element);
      this.x = x;
      this.y = y;
      this.w = w;
      this.h = h;
      this.duration = duration;
      this.steps    = steps;
      this.options  = arguments[7] || {};
      this.sizeAndPosition();
   },
   sizeAndPosition: function() {
      if (this.isFinished()) {
         if(this.options.complete) this.options.complete(this);
         return;
      }
      if (this.timer)
         clearTimeout(this.timer);
      var stepDuration = Math.round(this.duration/this.steps) ;
      // Get original values: x,y = top left corner;  w,h = width height
      var currentX = this.element.offsetLeft;
      var currentY = this.element.offsetTop;
      var currentW = this.element.offsetWidth;
      var currentH = this.element.offsetHeight;
      // If values not set, or zero, we do not modify them, and take original as final as well
      this.x = (this.x) ? this.x : currentX;
      this.y = (this.y) ? this.y : currentY;
      this.w = (this.w) ? this.w : currentW;
      this.h = (this.h) ? this.h : currentH;
      // how much do we need to modify our values for each step?
      var difX = this.steps >  0 ? (this.x - currentX)/this.steps : 0;
      var difY = this.steps >  0 ? (this.y - currentY)/this.steps : 0;
      var difW = this.steps >  0 ? (this.w - currentW)/this.steps : 0;
      var difH = this.steps >  0 ? (this.h - currentH)/this.steps : 0;
      this.moveBy(difX, difY);
      this.resizeBy(difW, difH);
      this.duration -= stepDuration;
      this.steps--;
      this.timer = setTimeout(this.sizeAndPosition.bind(this), stepDuration);
   },
   isFinished: function() {
      return this.steps <= 0;
   },
   moveBy: function( difX, difY ) {
      var currentLeft = this.element.offsetLeft;
      var currentTop  = this.element.offsetTop;
      var intDifX     = parseInt(difX);
      var intDifY     = parseInt(difY);
      var style = this.element.style;
      if ( intDifX != 0 )
         style.left = (currentLeft + intDifX) + "px";
      if ( intDifY != 0 )
         style.top  = (currentTop + intDifY) + "px";
   },
   resizeBy: function( difW, difH ) {
      var currentWidth  = this.element.offsetWidth;
      var currentHeight = this.element.offsetHeight;
      var intDifW       = parseInt(difW);
      var intDifH       = parseInt(difH);
      var style = this.element.style;
      if ( intDifW != 0 )
         style.width   = (currentWidth  + intDifW) + "px";
      if ( intDifH != 0 )
         style.height  = (currentHeight + intDifH) + "px";
   }
}
Rico.Effect.Size = Class.create();
Rico.Effect.Size.prototype = {
   initialize: function(element, w, h, duration, steps, options) {
      new Rico.Effect.SizeAndPosition(element, null, null, w, h, duration, steps, options);
  }
}
/*
Rico.Effect.Position = Class.create();
Rico.Effect.Position.prototype = {

   initialize: function(element, x, y, duration, steps, options) {
      new Rico.Effect.SizeAndPosition(element, x, y, null, null, duration, steps, options);
  }
}
*/


var effectDone = false;
function toggleEffect(i) {
  if (i==1 ) {
	 startEffect();
  }
 else {
	 resetEffect();
 }
}
function startEffect() {
  new Rico.Effect.Size($('sizeMe'),159,null,500, 50, {complete:function() {setStatus();}} );
}
function setStatus() {
   $('extendedBox').style.display="block";
   new Rico.Effect.Size($('extendedBox'),null,72,400,40, {complete:function() {setFinal("block");}} );
}
function setFinal(i){
   $('container').style.display=i;

}
function resetEffect() {
  new Rico.Effect.Size($('extendedBox'),null,5,400,40, {complete:function() {resetStatus();}} );
}
function resetStatus() {
   $('extendedBox').style.display="none";
   $('extendedBox').style.height=0;	   
   new Rico.Effect.Size($('sizeMe'),12,null,500,50, {complete:function() {setFinal("none");}} );
}
