﻿/*
   SlideIn/SlideOut Effects
   version 1.0
   (C) Dexter, 2008
   www.dexter.hu
   All rights reserved.
   Requires: prototypejs 1.6+
*/

var DFXSlide = Class.create({
  initialize: function(elem) {
    elem = $(elem);
    this.origWidth = elem.offsetWidth;
    this.origHeight = elem.offsetHeight;
    this.currWidth = this.origWidth;
    this.currHeight = this.origHeight;

    this.box = document.createElement('div');
    this.box.style.overflow = 'hidden';
    elem.parentNode.replaceChild(this.box, elem);
    this.box.appendChild(elem);
  },

  show: function() {
    this.box.style.height = '';
    this.currHeight = this.origHeight;
  },
  
  timerFunc: function(e) {
    this.currHeight += this.step;
    var stop = false;
    if (this.currHeight <= 0)
    {
      this.currHeight = 0;
      stop = true;
    }
    if (this.currHeight >= this.origHeight)
    {
      this.currHeight = this.origHeight;
      stop = true;
    }
    this.box.style.height = this.currHeight + 'px';
    if (stop)
    {
      if (this.timer)
        window.clearInterval(this.timer);
      this.timer = null;
    }
  },
  
  slideIn: function() {
    this.step = 10;
    if (!this.timer)
      this.timer = window.setInterval(this.timerFunc.bindAsEventListener(this), 10);
  },
  slideOut: function() {
    this.step = -10;
    if (!this.timer)
      this.timer = window.setInterval(this.timerFunc.bindAsEventListener(this), 10);
  },
  
  hide: function() {
    this.box.style.height = '0px';
    this.currHeight = 0;
  }
  
});

function hasChild(p, e)
{
		return $A(p.getElementsByTagName('*')).indexOf(e) >= 0;
}
