Element.prototype.fadeIn = function (time) {
var dt = 40,
step = time / dt,
opacity = 0,
height = 0;
fadeStep = 1 / step,
self = this;
var interval = setInterval(function () {
self.style.display = "block";
self.style.opacity = opacity;
self.style.height = opacity * 100 + 'px';
opacity += fadeStep;
if (opacity >= 1) {
clearInterval(interval);
self.style.height = 'auto';
};
}, dt)
};
Element.prototype.fadeOut = function (time) {
var dt = 40,
step = time / dt,
opacity = 1,
height = this.clientHeight;
fadeStep = 1 / step,
self = this;
var interval = setInterval(function () {
self.style.opacity = opacity;
self.style.height = opacity * height + 'px';
self.style.overflow = 'hidden';
opacity -= fadeStep;
if (opacity <= 0) {
clearInterval(interval);
self.style.display = "none";
self.style.opacity = "";
};
}, dt)
};
var flag;
Element.prototype.fadeToggle = function (time) {
var dt = 40,
step = time / dt,
opacity = 1,
height = this.clientHeight,
fadeStep = 1 / step,
self = this;
var fadeOut = function () {
var interval = setInterval(function () {
self.style.opacity = opacity;
self.style.height = opacity * height + 'px';
self.style.overflow = 'hidden';
opacity -= fadeStep;
if (opacity <= 0) {
clearInterval(interval);
self.style.display = "none";
self.style.opacity = "";
flag = false;
};
}, dt)
};
var fadeIn = function () {
var interval = setInterval(function () {
self.style.display = "block";
self.style.opacity = opacity;
self.style.height = opacity * 100 + 'px';
opacity += fadeStep;
if (opacity >= 1) {
clearInterval(interval);
self.style.height = 'auto';
flag = true;
};
}, dt)
};
if (flag == undefined) {
fadeOut();
} else if (flag == true) {
fadeOut();
} else {
fadeIn();
}
};