(function (a)
{
    a.fn.animaDrag = function (b, c)
    {
        var d = {
            speed: 400,
            interval: 300,
            easing: null,
            cursor: "point",
            boundary: document.body,
            boundary_offset: 0,
            grip: null,
            offset_x: 0,
            offset_y: 0,
            overlay: true,
            direction: "vertical",
            afterDiv: null,
            after: function (a)
            {},
            during: function (a)
            {},
            before: function (a)
            {},
            afterEachAnimation: function (a)
            {}
        };
        if (typeof c == "function")
        {
            d.after = c
        }
        b = a.extend(d, b || {});
        return this.each(function ()
        {
            var c, d, e, f, g, h = false,
                i, j = this,
                k = a(this).find(b.grip).length > 0 ? a(this).find(b.grip) : a(this);
            if (b.boundary)
            {
                var l = 0 - b.boundary_offset;
                var m = 0 - b.boundary_offset;
                var n = l + a(b.boundary).innerHeight() + 2 * b.boundary_offset;
                var p = m + a(b.boundary).innerWidth() + 2 * b.boundary_offset
            }
            k.mousedown(function (k)
            {
                b.before.call(j, k);
                var l, n;
                h = true;
                i = k;
                d = l = k.pageX;
                e = n = k.pageY;
                var q = parseInt(b.boundary.parent().css("padding-left"));
                f = a(j).offset().left - b.boundary.parent().offset().left - q;
                g = a(j).offset().top - b.boundary.parent().position().top;
                a(j).css(
                {
                    position: "absolute",
                    cursor: b.cursor,
                    zIndex: "1010"
                });
                c = setInterval(function ()
                {
                    if (l != i.pageX || n != i.pageY)
                    {
                        var c = f - (d - i.pageX);
                        var h = g - (e - i.pageY);
                        if (c < m && b.boundary)
                        {
                            c = m
                        }
                        else if (c + a(j).innerWidth() > p && b.boundary)
                        {
                            c = p - a(j).outerWidth()
                        }
                        if (b.direction == "vertical")
                        {
                            a(j).stop().animate(
                            {
                                left: c + b.offset_x + "px"
                            }, b.speed, b.easing)
                        }
                    }
                    b.boundary.find("#divider").css(
                    {
                        left: a(j).position().left + a(j).width() / 2 + "px"
                    });
                    if (b.afterDiv != null)
                    {
                        b.afterDiv.parent().parent().parent().find("#before").each(function (c)
                        {
                            var d = parseInt(b.boundary.parent().css("padding-left"));
                            var e = b.boundary.find("#divider").offset().left - b.boundary.find("#divider").parent().parent().offset().left - d;
                            if (e < 0) e = 0;
                            a(this).parent().parent().css(
                            {
                                width: e + "px"
                            })
                        })
                    }
                    l = i.pageX;
                    n = i.pageY
                }, b.interval);
                a.browser.safari || k.preventDefault()
            });
            a(document).mousemove(function (a)
            {
                if (h)
                {
                    i = a;
                    b.during.call(j, a)
                }
            });
            a(document).mouseup(function (d)
            {
                if (h)
                {
                    a(j).css(
                    {
                        cursor: "",
                        zIndex: "990"
                    }).removeClass("anima-drag");
                    a("#anima-drag-overlay").hide().appendTo(document.body);
                    clearInterval(c);
                    b.after.call(j, d);
                    h = false
                }
            })
        })
    }
})(jQuery)
