/*
WebAnimation Core Library
Part of WebDesktop.NET(tm)
Version 2.5.2006
Copyright (c) 2005 Intersoft Solutions Corp. All rights reserved.

Last Mod: 5/17/2007
*/
//**Start Encode**
var Animation =
{
    Object: null,

    Do: function (el, type, stepInterval, onCompleted, customParam, forceFading)
    {
        var obj = new ISAnimatedObject1();
        el.LastAnimationType = type;
        obj.Element = el;
        obj.Speed = "Fast";
        obj.Style = "WinXPStyle";
        obj.Step = (type == "SlideUp" || type == "SlideDown") ? 3 : 20;
        obj.StepInterval = 3;
        obj.Height = el.offsetHeight;
        obj.Type = type;
        obj.EnableFading = !IS.ie || forceFading;

        if (stepInterval)
            obj.StepInterval = stepInterval;

        if (onCompleted)
            obj.OnCompleted = onCompleted;

        if (customParam)
        {
            for (var param in customParam)
                obj[param] = customParam[param];
        }

        if (Animation.Object != null && Animation.Object.Element == el && Animation.Object.Type == obj.Type && Animation.Object.IntervalId > 0)
            Animation.Object.Stop();

        obj.Play();

        Animation.Object = obj;
    }
};

/*
WebAnimation Core Library
Part of WebDesktop.NET(tm)
Version 2.5.2006
Copyright (c) 2005 Intersoft Solutions Corp. All rights reserved.

Last Mod: 5/17/2007
*/
//**Start Encode**

function ISAnimatedObject1()
{
    this.Element = null;
    this.ParentElement = null;
    this.Type = ""; // accepts: ShrinkExpand, SlideDown, SlideUp, SlideRight, SlideBottom, FadeIn, FadeOut, MSNSlideUp, MSNSlideDown
    this.Style = "WinXPStyle"; // accepts: Static, Accelerated, Decelerated, WinXPStyle
    this.Step = 0; // accepts: 2,3; currently apply to SlideDown/SlideUp, if Style = Accelerated or Decelerated
    this.OnCompleted = null; // function to invoke when animation has been played completely
    this.Speed = "Slow"; // accept Slow, Medium and Fast. Currently applied to Fading effect.
    this.StepInterval = 1;

    /* Being remarked temporary by Gusdianto since there's no UnitSize and OffsetLocation object for testing
    Note: These objects are available in ISCore.js
    */
    this.CurrentSize = new UnitSize();
    this.TargetSize = new UnitSize();
    this.CurrentLocation = new OffsetLocation();
    this.TargetLocation = new OffsetLocation();

    this.AnimateLocation = false; // whether to animate from current to target location
    this.AnimateSize = false; // whether to animate fro current to target size
    this.ShadowMode = true; // create a shadow copy for the real animated element, instead of animating the real element
    this.MaxStep = 10;
    this.Duration = 1;
    this.Height = 0;
    this.TimeoutInterval = 1;
    this.IntervalId = null;
    this.Canceled = false;
    this.EnableFading = false;
    this.MaxFadeInOpacity = 100;
    this.BorderColor = "";
    this.FromColor = "";
    this.ToColor = "";
    this.ElementStyle = "backgroundColor";

    // private
    this._ShadowElement = null;

    // public

    this.Play = function ()
    {
        this.Canceled = false;
        ISWebAnimationEngine.Play(this);
    };

    this.Stop = function ()
    {
        // currently supported by FadeOut only
        this.Canceled = true;
    };
}

// Enumeration for animation speed
var ISAnimationSpeed =
{
    Fast: 10,
    Medium: 20,
    Slow: 30,
    VerySlow: 50
};

var ISWebAnimationEngine =
{
    _ShadowElement: null, // for best performance, we only need to create a shadow once for all
    _beta: 0,

    Play: function (o)
    {
        switch (o.Type)
        {
            case "AnimateColor":
                ISWebAnimationEngine._PlayAnimateColor(o, 0);
                break;
            case "ShrinkExpand":
                ISWebAnimationEngine._PlayShrinkExpand(o, 0);
                break;
            case "SlideDown":
                clearTimeout(o.IntervalId);
                ISWebAnimationEngine._PlaySlideDown(o, 1);
                break;
            case "SlideUp":
                clearTimeout(o.IntervalId);
                ISWebAnimationEngine._PlaySlideUp(o, 1);
                break;
            case "FadeIn":
                o.Element.style.display = "";
                ISWebAnimationEngine._PlayFadeIn(o, 0);
                break;
            case "FadeOut":
                ISWebAnimationEngine._PlayFadeOut(o, o.MaxFadeInOpacity);
                break;
            case "MSNSlideUp":
                ISWebAnimationEngine._PlayMSNSlideUp(o, 0);
                break;
            case "MSNSlideDown":
                ISWebAnimationEngine._PlayMSNSlideDown(o, 0);
                break;
            case "ResizeUp":
                var i = (o.Speed == "Fast" ? 3 : (o.Speed == "Medium" ? 2 : 1));
                ISWebAnimationEngine._VResize(o, -1 * i);
                break;
            case "ResizeDown":
                var i = (o.Speed == "Fast" ? 3 : (o.Speed == "Medium" ? 2 : 1));
                ISWebAnimationEngine._VResize(o, i);
                break;
            case "MenuSlideUp":
                ISWebAnimationEngine._PlayMenuSlideUp(o, null);
                break;
            case "MenuSlideDown":
                ISWebAnimationEngine._PlayMenuSlideDown(o, null);
                break;
            case "MenuSlideRight":
                ISWebAnimationEngine._PlayMenuSlideRight(o, null);
                break;
            case "ZoomOut":
                ISWebAnimationEngine._PlayZoomOut(o, null);
                break;
            case "ZoomIn":
                ISWebAnimationEngine._PlayZoomIn(o, null);
                break;
        }
    },

    _Ease: function (step, begin, change, maxstep)
    {
        return begin + change * (step / maxstep);
    },

    _PlayAnimateColor: function (o, step)
    {
        var b = ISWebAnimationEngine.CssColor2rgb(o.FromColor);
        var e = ISWebAnimationEngine.CssColor2rgb(o.ToColor);
        var change0 = e[0] - b[0];
        var change1 = e[1] - b[1];
        var change2 = e[2] - b[2];
        var increase0 = ISWebAnimationEngine._Ease(step, b[0], change0, o.MaxStep);
        var increase1 = ISWebAnimationEngine._Ease(step, b[1], change1, o.MaxStep);
        var increase2 = ISWebAnimationEngine._Ease(step, b[2], change2, o.MaxStep);

        o.Element.style[o.ElementStyle] = 'rgb(' + parseInt(increase0) + ',' + parseInt(increase1) + ',' + parseInt(increase2) + ')';

        if (step > o.MaxStep)
            step = o.MaxStep;

        if (step == o.MaxStep || o.Canceled)
        {
            if (o.OnCompleted != null)
                o.OnCompleted(o);

            if (o.Canceled)
                clearTimeout(o.IntervalId);
            else
                ISAnimation_RemoveOpacity(o.Element);
            return;
        }

        o.IntervalId = setTimeout(function () { ISWebAnimationEngine._PlayAnimateColor(o, step + o.StepInterval); }, ISAnimationSpeed[o.Speed]);
    },

    _PlayFadeIn: function (o, step)
    {
        ISWebAnimationEngine.ChangeOpacity(step, o);

        if (step > o.MaxFadeInOpacity)
            step = o.MaxFadeInOpacity;

        if (step == o.MaxFadeInOpacity || o.Canceled)
        {
            if (o.OnCompleted != null)
                o.OnCompleted(o);

            if (o.Canceled)
                clearTimeout(o.IntervalId);
            else
                ISAnimation_RemoveOpacity(o.Element);
            return;
        }

        o.IntervalId = setTimeout(function () { ISWebAnimationEngine._PlayFadeIn(o, step + o.StepInterval); }, ISAnimationSpeed[o.Speed]);
    },

    _PlayFadeOut: function (o, step)
    {
        ISWebAnimationEngine.ChangeOpacity(step, o, true);

        if (step == 0 || o.Canceled)
        {
            if (o.OnCompleted != null)
                o.OnCompleted(o);

            if (o.Canceled)
                ISWebAnimationEngine.ChangeOpacity(100, o, true);

            return;
        }

        o.IntervalId = setTimeout(function () { ISWebAnimationEngine._PlayFadeOut(o, step - o.StepInterval); }, ISAnimationSpeed[o.Speed]);
    },

    _PlayMSNSlideUp: function (o, step)
    {
        var style = o.Element.style;

        if (step == 0)
        {
            if (!o.Element.OriginalTop)
            {
                o.Element.OriginalTop = ISPosLib.getTop(o.Element);
                o.Element.OriginalHeight = o.Element.offsetHeight;
            }

            style.display = "";
            style.position = "absolute";
            style.top = o.Element.OriginalTop + o.Element.OriginalHeight;
            style.height = 1;
        }
        else
        {
            style.top = style.posTop - step;
            style.height = style.posHeight + step;
        }

        if (style.posTop <= o.Element.OriginalTop)
        {
            style.top = o.Element.OriginalTop;
            style.height = o.Element.OriginalHeight;

            if (o.OnCompleted != null)
                o.OnCompleted();

            return;
        }

        var deltaHeight = style.posTop - o.Element.OriginalTop;
        deltaHeight /= 2;
        deltaHeight = Math.round(deltaHeight);

        setTimeout(function () { ISWebAnimationEngine._PlayMSNSlideUp(o, deltaHeight); }, 50);
    },

    _PlayMSNSlideDown: function (o, step)
    {
        var style = o.Element.style;

        if (step == 0)
        {
            if (!o.Element.OriginalTop)
            {
                o.Element.OriginalTop = ISPosLib.getTop(o.Element);
                o.Element.OriginalHeight = o.Element.offsetHeight;
            }

            style.position = "absolute";
            style.top = o.Element.OriginalTop;
            style.height = o.Element.OriginalHeight;
            style.display = "";
        }
        else
        {
            style.top = style.posTop + step;
            style.height = style.posHeight - step;
        }

        if (style.posHeight == 1)
        {
            style.top = o.Element.OriginalTop + o.Element.OriginalHeight - 2;
            style.display = "none";

            if (o.OnCompleted != null)
                o.OnCompleted();

            return;
        }

        var deltaHeight = style.posHeight;
        deltaHeight /= 2;
        deltaHeight = Math.round(deltaHeight);

        setTimeout(function () { ISWebAnimationEngine._PlayMSNSlideDown(o, deltaHeight); }, 50);
    },

    _PlayMenuSlideUp: function (o, step)
    {
        var style = o.Element.style;
        var initial = false;

        if (step == null)
        {
            if (!o.Element.OriginalTop)
            {
                o.Element.OriginalTop = ISPosLib.getTop(o.Element);
                o.Element.OriginalHeight = o.Element.offsetHeight;
            }

            step = o.Element.OriginalTop;
            initial = true;

            style.position = "absolute";
            style.visibility = "visible"
        }

        var destTop = step;

        if (destTop <= o.Element.OriginalTop - o.Element.OriginalHeight)
        {
            style.visibility = "hidden";
            style.clip = "rect(auto auto auto auto)";

            if (o.OnCompleted != null)
                o.OnCompleted();

            return;
        }
        else
        {
            var clipTop = (o.Element.OriginalTop - step) + "px";
            var clipBottom = "auto";
            var opacity = 0;

            style.top = destTop + "px";
            style.clip = "rect(" + clipTop + " auto " + clipBottom + " auto)";

            if (o.EnableFading)
            {
                opacity = 100 - ((destTop / (o.Element.OriginalTop - o.Element.OriginalHeight)) * 100);
                ISWebAnimationEngine.ChangeOpacity(opacity, o);
            }
        }

        var deltaHeight = (step + o.Element.OriginalHeight) - o.Element.OriginalTop;
        deltaHeight /= 2;
        deltaHeight = step - Math.round(deltaHeight);

        setTimeout(function () { ISWebAnimationEngine._PlayMenuSlideUp(o, deltaHeight); }, ISAnimationSpeed[o.Speed]);
    },

    _PlayMenuSlideDown: function (o, step)
    {
        var style = o.Element.style;
        var initial = false;

        if (step == null)
        {
            if (!o.Element.OriginalTop)
            {
                o.Element.OriginalTop = GetXHTMLTop(o.Element);
                o.Element.OriginalHeight = o.Element.offsetHeight;
            }

            step = o.Element.OriginalTop - o.Element.OriginalHeight;
            initial = true;

            style.position = "absolute";
            style.visibility = "visible";
        }

        var destTop = step;

        if (destTop >= o.Element.OriginalTop)
        {
            style.top = o.Element.OriginalTop + "px";
            style.clip = "rect(auto auto auto auto)";

            if (o.EnableFading)
                ISWebAnimationEngine.ChangeOpacity(100, o);

            if (o.OnCompleted != null)
                o.OnCompleted();

            return;
        }
        else
        {
            var clipTop = (o.Element.OriginalTop - step);
            var clipBottom = (o.Element.OriginalHeight + step);
            var opacity = 0;

            style.top = destTop + "px";
            style.clip = "rect(" + clipTop + "px auto " + clipBottom + "px auto)";

            if (o.EnableFading)
            {
                opacity = (destTop / o.Element.OriginalTop) * 100;
                ISWebAnimationEngine.ChangeOpacity(opacity, o);
            }
        }

        var deltaHeight = o.Element.OriginalTop - step;

        if (initial)
            deltaHeight = deltaHeight + (o.Element.OriginalHeight / 2);

        deltaHeight /= 2;

        if (deltaHeight < 0)
            deltaHeight = 0 - deltaHeight;

        deltaHeight = step + Math.round(deltaHeight);

        setTimeout(function () { ISWebAnimationEngine._PlayMenuSlideDown(o, deltaHeight); }, ISAnimationSpeed[o.Speed]);
    },

    _PlayMenuSlideRight: function (o, step)
    {
        var style = o.Element.style;
        var initial = false;

        if (step == null)
        {
            if (!o.Element.OriginalLeft)
            {
                o.Element.OriginalLeft = ISPosLib.getLeft(o.Element);
                o.Element.OriginalWidth = o.Element.offsetWidth;
            }

            step = o.Element.OriginalLeft - o.Element.OriginalWidth;
            initial = true;

            style.position = "absolute";
            style.visibility = "visible";
        }

        var destLeft = step;

        if (destLeft >= o.Element.OriginalLeft)
        {
            style.left = o.Element.OriginalLeft;
            style.clip = "rect(auto auto auto auto)";

            if (o.EnableFading)
                ISWebAnimationEngine.ChangeOpacity(100, o);

            if (o.OnCompleted != null)
                o.OnCompleted();

            return;
        }
        else
        {
            var clipLeft = (o.Element.OriginalLeft - step) + "px";
            var clipRight = (o.Element.OriginalWidth + step) + "px";
            var opacity = 0;

            style.left = destLeft;
            style.clip = "rect(auto " + clipRight + " auto " + clipLeft + ")";

            if (o.EnableFading)
            {
                opacity = (destLeft / o.Element.OriginalLeft) * 100;
                ISWebAnimationEngine.ChangeOpacity(opacity, o);
            }
        }

        var deltaWidth = step + (o.Element.OriginalWidth / 1.5);

        setTimeout(function () { ISWebAnimationEngine._PlayMenuSlideRight(o, deltaWidth); }, ISAnimationSpeed[o.Speed]);
    },

    _PlayShrinkExpand: function (o, step)
    {
        var duration = o.Duration / o.MaxStep;

        if (step == 0)
        {
            if (ISWebAnimationEngine._ShadowElement == null)
            {
                var shadow = document.createElement("DIV");

                shadow.style.cssText = "border: red 1px solid; position:absolute; z-index: 106";

                if (o.BorderColor == "")
                    shadow.style.borderColor = o.Element.currentStyle.borderColor;
                else
                    shadow.style.borderColor = o.BorderColor;

                shadow.style.left = o.CurrentLocation.X + "px";
                shadow.style.top = o.CurrentLocation.Y + "px";
                shadow.style.width = o.CurrentSize.Width + "px";
                shadow.style.height = o.CurrentSize.Height + "px";

                o.Element.parentElement.appendChild(shadow);
                ISWebAnimationEngine._ShadowElement = shadow;
            }
            else
                ISWebAnimationEngine._ShadowElement.style.display = "none";

            setTimeout(function () { ISWebAnimationEngine._PlayShrinkExpand(o, step + 1); }, duration);
        }
        else
        {
            shadow = ISWebAnimationEngine._ShadowElement;
            shadow.style.display = "";

            if (o.AnimateLocation)
            {
                var x = (step / o.MaxStep) * (o.TargetLocation.X - o.CurrentLocation.X);
                var y = (step / o.MaxStep) * (o.TargetLocation.Y - o.CurrentLocation.Y);

                shadow.style.left = x + o.CurrentLocation.X + "px";
                shadow.style.top = y + o.CurrentLocation.Y + "px";
            }

            if (o.AnimateSize)
            {
                var w = (step / o.MaxStep) * (o.TargetSize.Width - o.CurrentSize.Width);
                var h = (step / o.MaxStep) * (o.TargetSize.Height - o.CurrentSize.Height);

                shadow.style.width = o.CurrentSize.Width + w + "px";
                shadow.style.height = o.CurrentSize.Height + h + "px";
            }

            if (step == o.MaxStep)
            {
                shadow.style.display = "none";

                if (o.OnCompleted != null)
                    o.OnCompleted();

                return;
            }

            setTimeout(function () { ISWebAnimationEngine._PlayShrinkExpand(o, step + 1); }, duration);
        }
    },

    //change the opacity for different browsers
    ChangeOpacity: function (opacity, o, fromEnd)
    {
        var object = o.Element.style;
        object.opacity = (opacity / 100);
        object.MozOpacity = (opacity / 100);
        object.KhtmlOpacity = (opacity / 100);

        if (IS.ie)
        {
            if (o.Element.currentStyle.filter == "")
                object.filter = "Alpha(Opacity=" + opacity + ")";

            if ((opacity == 0 || (fromEnd && opacity == 100)) && o.Element.currentStyle.filter.indexOf("Alpha") == -1)
            {
                object.filter = ((o.Element.currentStyle.filter != "") ? o.Element.currentStyle.filter + " " : "") + "Alpha(Opacity=" + opacity + ")";
            }
            else
            {
                var s = object.filter;
                var p0 = s.indexOf("Opacity");

                object.filter = s.substring(0, p0 + 8) + opacity + ")";
            }
        }

        if (opacity == 100 && !fromEnd)
            ISWebAnimationEngine.RemoveOpacity(o.Element);
    },

    RemoveOpacity: function (el)
    {
        var s = el.style.cssText;
        var i = s.indexOf("FILTER");

        if (IS.ie)
        {
            if (i > -1)
            {
                var i2 = s.indexOf(";", i + 1);

                s = s.substring(0, i) + s.substring(i2 + 1);
                el.style.cssText = s;
            }
        }
        else
        {
            el.style.opacity = 1;
            el.style.MozOpacity = 1;
            el.style.KhtmlOpacity = 1;
        }
    },

    CssColor2rgb: function (color)
    {
        if (color.indexOf('rgb') <= -1)
            return ISWebAnimationEngine.Hexa2rgb(color.substring(1, 3), color.substring(3, 5), color.substring(5, 7));

        return color.substring(4, color.length - 1).split(',');
    },

    Hexa2rgb: function (h, e, x)
    {
        return [parseInt(h, 16), parseInt(e, 16), parseInt(x, 16)];
    },

    //changing the step of movement (for type: slidedown, slideup) every n pixels of the parameter
    _delta: function (el, obj, n)
    {
        for (var i = 1; i <= obj.MaxStep; i++)
        {
            if (el.offsetHeight < (n * i))
                return i;
        }

        for (var i = 1; i <= obj.MaxStep; i++)
        {
            if (obj.Height - (n * i) < el.offsetHeight)
                return i;
        }

        return obj.MaxStep;
    },

    _PlaySlideDown: function (o, step)
    {
        var el = o.Element;
        var parent = (o.ParentElement == null) ? el.parentNode : o.ParentElement;
        var opacity = parent.offsetHeight / o.Height * 100;

        if (Math.round(opacity) > 98)
            opacity = 100;

        if (o.EnableFading)
            ISWebAnimationEngine.ChangeOpacity(opacity, o);

        if (opacity == 100)
            el.style.filter = "";

        if (o.Style == "WinXPStyle")
        {
            step = ISWebAnimationEngine._delta(parent, o, IS.safari ? 1 : 3);
        }
        else if (o.Style == "Accelerated" || o.Style == "Decelerated")
        {
            step += o.Step;
        }
        else if (o.Style == "Easing")
        {
            step += ISWebAnimationEngine._Ease(o.Step, step, 10, o.MaxStep);
        }
        else if (o.Style == "Quadratic")
        {
            step += QuadraticAnimation(step, o.Height, 10.5);
        }

        if (el.offsetTop + o.Height >= o.Height)
        {
            el.style.top = o.Height + "px";

            if (o.OnCompleted != null)
                ISEvent.Raise(o.OnCompleted, o.EventArgs);
            return;
        }
        else
        {
            var height = parent.offsetHeight + step;
            if (height >= o.Height)
            {
                if (o.EnableFading)
                    ISWebAnimationEngine.ChangeOpacity(100, o);

                el.style.top = "0px";
                parent.style.height = "";

                if (o.OnCompleted != null)
                    ISEvent.Raise(o.OnCompleted, o.EventArgs);
                return;
            }
            else
                parent.style.height = height + "px";

            if (el.offsetTop + step < 0)
                el.style.top = el.offsetTop + step + "px";
            else
                el.style.top = "0px";
        }

        o.IntervalId = setTimeout(function () { ISWebAnimationEngine._PlaySlideDown(o, step); }, 15);
    },

    _PlaySlideUp: function (o, step)
    {
        var el = o.Element;
        var parent = (o.ParentElement == null) ? el.parentNode : o.ParentElement;

        if (o.EnableFading)
        {
            var opacity = parent.offsetHeight / o.Height * 100;
            ISWebAnimationEngine.ChangeOpacity(opacity, o);
        }

        if (o.Style == "WinXPStyle")
        {
            step = ISWebAnimationEngine._delta(parent, o, IS.safari ? 1 : 3);
        }
        else if (o.Style == "Accelerated" || o.Style == "Decelerated")
        {
            step += o.Step;
        }
        else if (o.Style == "Easing")
        {
            step += ISWebAnimationEngine._Ease(o.Step, step, 10, o.MaxStep);
        }
        else if (o.Style == "Quadratic")
        {
            step += QuadraticAnimation(step, o.Height, 10.5);
        }

        if (el.offsetTop + o.Height <= 0)
        {
            parent.style.height = "1px";

            if (o.OnCompleted != null)
                ISEvent.Raise(o.OnCompleted, o.EventArgs);
            return;
        }
        else
        {
            el.style.top = (el.offsetTop - step) + "px";
            var height = (parent.offsetHeight - step);

            if (height <= 0)
            {
                parent.style.height = "1px";

                if (o.OnCompleted != null)
                    ISEvent.Raise(o.OnCompleted, o.EventArgs);
                return;
            }
            else
                parent.style.height = height + "px";
        }

        o.IntervalId = setTimeout(function () { ISWebAnimationEngine._PlaySlideUp(o, step); }, 15);
    },

    _VResize: function (o, step)
    {
        var el = o.Element;

        if (step < 0)
        {
            if (el.offsetHeight + step <= parseInt(o.TargetSize.Height))
            {
                el.style.height = parseInt(o.TargetSize.Height);
                return;
            }
            else
                el.style.height = el.offsetHeight + step;
        }
        else
        {
            if (el.offsetHeight + step >= parseInt(o.TargetSize.Height))
            {
                el.style.height = parseInt(o.TargetSize.Height);
                return;
            }
            else
                el.style.height = el.offsetHeight + step;
        }

        setTimeout(function () { ISWebAnimationEngine._VResize(o, step); }, 10);
    },

    _PlayZoomOut: function (o, step)
    {
        if (step == null)
        {
            var el = o.Element;

            step = 1;
            o.OriginalLeft = parseFloat(el.style.left);
            o.OriginalTop = parseFloat(el.style.top);
            o.CurrentOpacity = 100;
            o.CurrentInterval = 100;

            el.lastCalculatedWidth = ISPosLib.getWidth(el);
            el.lastCalculatedHeight = ISPosLib.getHeight(el);
        }

        if (step == o.MaxStep || o.CurrentOpacity == 0)
        {
            var el = o.Element;

            with (el.style)
            {
                display = "none";
                filter = "";
                zoom = "100%";
                left = o.OriginalLeft;
                top = o.OriginalTop;
            }

            if (o.OnCompleted != null)
                ISEvent.Raise(o.OnCompleted, o.EventArgs);

            return;
        }

        var el = o.Element;
        var op = o.CurrentOpacity;
        var duration = o.CurrentInterval;

        if (!o.AnimateLocation && !o.AnimateSize)
        {
            with (el.style)
            {
                top = parseFloat(top) + step;
                left = parseFloat(left) + step;
                zoom = (100 - (step * 2)) + "%";
            }
        }
        else
        {
            if (o.AnimateLocation)
            {
                var x = (step / o.MaxStep) * (o.TargetLocation.X - o.CurrentLocation.X);
                var y = (step / o.MaxStep) * (o.TargetLocation.Y - o.CurrentLocation.Y);

                el.style.left = x + o.CurrentLocation.X;
                el.style.top = y + o.CurrentLocation.Y;
            }

            if (o.AnimateSize)
            {
                var w = (step / o.MaxStep) * (o.TargetSize.Width - o.CurrentSize.Width);
                var h = (step / o.MaxStep) * (o.TargetSize.Height - o.CurrentSize.Height);

                el.style.width = o.CurrentSize.Width + w;
                el.style.height = o.CurrentSize.Height + h;
            }
        }

        op = op / 1.75;

        if (op < 0)
            op = 0;

        ISWebAnimationEngine.ChangeOpacity(op, o);

        step++;
        duration = duration / step;

        if (duration < 1)
            duration = 1;

        o.CurrentOpacity = op;
        o.CurrentInterval = duration;

        setTimeout(function () { ISWebAnimationEngine._PlayZoomOut(o, step); }, duration);
    },

    _PlayZoomIn: function (o, step)
    {
        if (step == null)
        {
            step = 1;

            if (typeof (o.CurrentOpacity) == "undefined")
                o.CurrentOpacity = 5;

            if (typeof (o.CurrentInterval) == "undefined")
                o.CurrentInterval = 50;

            var el = o.Element;
            var distance = 0;
            var _top = 0;
            var _left = 0;
            var _width = 0;
            var _height = 0;

            if (!o.AnimateLocation && !o.AnimateSize)
            {
                _top = parseFloat(el.style.top);
                _left = parseFloat(el.style.left);

                if (el.offsetWidth == 0)
                {
                    if (el.lastCalculatedWidth)
                        _width = parseFloat(el.lastCalculatedWidth);
                    else
                        _width = parseFloat(el.style.width);
                }
                else
                    _width = el.offsetWidth;

                if (el.offsetHeight == 0)
                {
                    if (el.lastCalculatedHeight)
                        _height = parseFloat(el.lastCalculatedHeight);
                    else
                        _height = parseFloat(el.style.height);
                }
                else
                    _height = el.offsetHeight;
            }
            else
            {
                _top = o.CurrentLocation.Y;
                _left = o.CurrentLocation.X;
                _width = o.CurrentSize.Width;
                _height = o.CurrentSize.Height;
            }

            for (var i = 1; i < o.MaxStep; i++)
                distance += (i * 1.5);

            with (el.style)
            {
                top = _top + distance;
                left = _left + distance;
                width = _width - (distance * 2);
                height = _height - (distance * 2);
                display = "";
            }
        }

        if (step == o.MaxStep /*|| o.CurrentOpacity == 100*/)
        {
            if (o.CurrentOpacity < 100)
            {
                ISWebAnimationEngine.ChangeOpacity(100, o);
                o.Element.style.filter = "";
            }

            if (o.AnimateLocation && o.AnimateSize)
            {
                // ensure it reach the correct size
                with (o.Element.style)
                {
                    left = o.TargetLocation.X;
                    top = o.TargetLocation.Y;
                    width = o.TargetSize.Width;
                    height = o.TargetSize.Height;
                }
            }

            if (o.OnCompleted != null)
                ISEvent.Raise(o.OnCompleted, o.EventArgs);

            return;
        }

        var el = o.Element;
        var op = o.CurrentOpacity;
        var duration = o.CurrentInterval;

        if (!o.AnimateLocation && !o.AnimateSize)
        {
            with (el.style)
            {
                top = parseFloat(top) - (step * 1.5);
                left = parseFloat(left) - (step * 1.5);
                width = parseFloat(width) + ((step * 1.5) * 2);
                height = parseFloat(height) + ((step * 1.5) * 2);
            }
        }
        else
        {
            if (o.AnimateLocation)
            {
                var x = (step / o.MaxStep) * (o.TargetLocation.X - o.CurrentLocation.X);
                var y = (step / o.MaxStep) * (o.TargetLocation.Y - o.CurrentLocation.Y);

                el.style.left = x + o.CurrentLocation.X;
                el.style.top = y + o.CurrentLocation.Y;
            }

            if (o.AnimateSize)
            {
                var w = (step / o.MaxStep) * (o.TargetSize.Width - o.CurrentSize.Width);
                var h = (step / o.MaxStep) * (o.TargetSize.Height - o.CurrentSize.Height);

                el.style.width = o.CurrentSize.Width + w;
                el.style.height = o.CurrentSize.Height + h;
            }
        }

        ISWebAnimationEngine.ChangeOpacity(op, o);

        op = op * 2;

        if (op > 100)
            op = 100;

        step++;
        duration = duration / (step / 1.25);

        if (duration < 1)
            duration = 1;

        if (duration > 300)
            duration = 300;

        o.CurrentOpacity = op;
        o.CurrentInterval = duration;

        setTimeout(function () { ISWebAnimationEngine._PlayZoomIn(o, step); }, duration);
    }
};

function ISAnimation_RemoveOpacity(el)
{
    ISWebAnimationEngine.RemoveOpacity(el);
}

var quantifier = 1;

function QuadraticAnimation(start, end, baseRate)
{
    if (end > start)
        var diff = end - start;
    if (end < start)
        var diff = start - end;

    var value = (diff / (baseRate * quantifier));
    if (parseInt(value) == 0)
        value = 1;

    //if (baseRate < 2)
    //    quantifier = 2;

    if (end > start)
        return start + parseInt(value);
    if (end < start)
        return start - parseInt(value);
}

function GetWindowScrollTop()
{
    if (IS.ie || IS.moz || IS.opera)
        return document.documentElement.scrollTop;
    else if (IS.safari || IS.chrome)
        return document.body.scrollTop;
}

function SetWindowScrollTop(value)
{
    if (IS.ie || IS.moz || IS.opera)
        document.documentElement.scrollTop = value;
    else if (IS.safari || IS.chrome)
        document.body.scrollTop = value;
}

function GetElementTop(el)
{
    //return el.offsetTop;
    //Modified by Dicky 05/23/2009
    if (IS.ie)
        return ISPosLib.getTop(el);
    else
        return ISPosLib.getTopNonIE(el);
}

function GetXHTMLTop(el)
{
    var top = ISPosLib.getTop(el);

    if (IS.moz || IS.opera)
        top = ISPosLib.getClientTop(el);
    else if (IS.safari || IS.chrome)
        top = ISPosLib.getClientTop(el) + GetWindowScrollTop();

    return top;
}

var SmoothScrollCompleted = null;
function SmoothScrollToAnchor(id, adjustTop, onCompleted)
{
    if (typeof (onCompleted) != "undefined")
        SmoothScrollCompleted = onCompleted;

    if (!id)
        el = event.srcElement;
    else if (typeof (id) == "string")
        el = document.getElementById(id);
    else if (typeof (id) == "object")
        el = id;

    var targetPos = GetElementTop(el);

    var htmlEl = document.documentElement;
    var scrollHeight = htmlEl.scrollHeight;

    var clientHeight = htmlEl.clientHeight;
    var maxScroll = scrollHeight - clientHeight;

    var end;

    if (targetPos > GetWindowScrollTop())      //Go Down
    {
        if (maxScroll >= targetPos)
            end = targetPos;
        else
            end = maxScroll;
    }
    else    //Go Up
    {
        end = targetPos;
    }

    if (adjustTop)
        end += adjustTop;

    quantifier = 1;

    var lastPos;
    var timer = window.setInterval(function ()
    {
        var pos = QuadraticAnimation(GetWindowScrollTop(), end, 7.5);

        if (GetWindowScrollTop() < end)
        {
            if (pos < end && lastPos != pos)
            {
                lastPos = pos;
                SetWindowScrollTop(pos);
            }
            else
            {
                clearInterval(timer);

                if (SmoothScrollCompleted != null)
                {
                    SmoothScrollCompleted();
                    SmoothScrollCompleted = null;
                }
            }
        }
        else
        {
            if (pos > end && lastPos != pos)
            {
                lastPos = pos;
                SetWindowScrollTop(pos);
            }
            else
            {
                clearInterval(timer);

                if (SmoothScrollCompleted != null)
                {
                    SmoothScrollCompleted();
                    SmoothScrollCompleted = null;
                }
            }
        }
    }, (IS.ie ? 5 : 15));

    if (typeof (event) != "undefined")  //for Firefox
    {
        if (event)   //for others browser
        {
            event.cancelBubble = true;
            event.returnValue = false;
        }
    }
}

if (typeof (Sys) != "undefined")
    Sys.Application.notifyScriptLoaded();


// Added by Jemmy.
// Script for Media Gallery
function setOpacity(obj, value)
{
    obj.style.opacity = value / 10;
    obj.style.filter = 'alpha(opacity=' + value * 10 + ')';
}
