(function (f) {
    function g(a, b) {
        this.sett = f.extend({
            textAreaPadding: 20,
            textBgBlur: 20,
            autoRotate: !0,
            rotationInterval: 4,
            borderSize: 2
        }, b);
        this.$container = a;
        this.imgsLoaded = 0;
        this.totalImgs = this.$container.children(".vuAll_item").length;
        this.taPadding = this.sett.textAreaPadding;
        this.blurAmount = this.sett.textBgBlur;
        this.autoSlideDelay = this.sett.rotationInterval;
        this.autoSlide = this.sett.autoRotate;
        this.borderSize = this.sett.borderSize;
        this.lastSlide = null;
        this.curAutoSlide = 0;
        this.rotationStarted = !1;
        this.masterArr = [];
        this.hasCanvas = document.createElement("canvas").getContext ? !0 : !1;
        this.init()
    }
    g.prototype = {
        init: function () {
            var a = this;
            a.$container.find(".vuAll_item").each(function () {
                var b = f(this);
                b.css({
                    opacity: 0
                });
                a.masterArr.push(b);
                var c = new Image;
                f(c).load(function () {
                    a.imgsLoaded++;
                    a.imgsLoaded == a.totalImgs && a.launch()
                }).attr("src", b.find("img").attr("src"))
            })
        },
        launch: function () {
            var a = this;
            a.$container.find(".vuAll_item").each(function (b) {
                var c = f(this),
                    d = c.find("img").width(),
                    h = c.find("img").height(),
                    e = c.find(".vuAll_textArea"),
                    g = c.find(".vuAll_copy"),
                    i = c.find(".headSize"),
                    j = c.find(".headSize").width(),
                    k = c.find(".headSize").height();
                e.destLeft = d - j - 2 * a.taPadding;
                e.destTop = h - k - 2 * a.taPadding;
                c.css({
                    borderWidth: a.borderSize + "px"
                });
                c.find("img").attr("id", "image" + a.$container.attr("class") + b);
                a.hasCanvas && c.find("canvas").attr("id", "canvas" + a.$container.attr("class") + b).css({
                    "float": "left",
                    display: "block",
                    position: "absolute",
                    left: -e.destLeft,
                    top: -e.destTop
                });
                c.find(".blurMask").css({
                    clear: "both",
                    "float": "left",
                    position: "absolute",
                    overflow: "hidden",
                    width: d + "px",
                    height: h + "px",
                    left: e.destLeft,
                    top: e.destTop
                });
                a.hasCanvas ? stackBlurImage("image" + a.$container.attr("class") + b, "canvas" + a.$container.attr("class") + b, a.blurAmount, !1, 100) : f(document.createElement("img")).attr({
                    src: c.find("img").attr("src")
                }).css({
                    "float": "left",
                    display: "block",
                    position: "absolute",
                    width: c.find("img").width() + 2 * a.blurAmount + "px",
                    height: c.find("img").height() + 2 * a.blurAmount + "px",
                    left: -e.destLeft - 2 * a.blurAmount,
                    top: -e.destTop - 2 * a.blurAmount,
                    filter: "progid:DXImageTransform.Microsoft.Blur(pixelRadius=" + a.blurAmount + ")",
                    "-ms-filter": "progid:DXImageTransform.Microsoft.Blur(pixelRadius=" + a.blurAmount + ")"
                }).appendTo(c.find(".blurMask"));
                e.css({
                    left: e.destLeft,
                    top: e.destTop,
                    padding: a.taPadding + "px",
                    width: d - 2 * a.taPadding + "px",
                    height: h
                });
                g.css({
                    width: d - 2 * a.taPadding + "px"
                });
                b = c.find(".vuAll_button");
                b.css({
                    marginRight: -(b.width() + a.taPadding) + "px",
                    opacity: 0
                });
                i.bind("mouseover", function () {
                    a.itemOver(a, a.lastSlide, e, i)
                });
                c.animate({
                    opacity: 1,
                    easing: "easeInOutExpo"
                }, 500)
            });
            a.autoSlide && (a.masterArr[a.curAutoSlide].find(".headSize").mouseover(), a.curAutoSlide++, a.rotate(), a.$container.mouseenter(function () {
                a.stopRotation()
            }), a.$container.mouseleave(function () {
                a.rotate()
            }))
        },
        itemOver: function (a, b, c, d) {
            d.unbind("mouseover");
            null != b && (b.animate({
                left: b.destLeft,
                top: b.destTop,
                easing: "easeInOutExpo"
            }, 500), d = b.find(".vuAll_button"), d.animate({
                marginRight: -(d.width() + this.taPadding) + "px",
                opacity: 0
            }, 500), b.parent().find(".blurMask").animate({
                left: b.destLeft,
                top: b.destTop,
                easing: "easeInOutExpo"
            }, 500), this.hasCanvas ? (d = b.parent().find("canvas"), d.animate({
                left: -b.destLeft,
                top: -b.destTop,
                easing: "easeInOutExpo"
            }, 500)) : (d = b.parent().find(".blurMask img"), d.animate({
                left: -b.destLeft - 2 * this.blurAmount,
                top: -b.destTop - 2 * this.blurAmount,
                easing: "easeInOutExpo"
            }, 500)));
            a.lastSlide = c;
            this.hasCanvas ? c.parent().find("canvas").animate({
                left: 0,
                top: 0,
                easing: "easeInOutExpo"
            }, 500) : c.parent().find(".blurMask img").animate({
                left: 2 * -this.blurAmount,
                top: 2 * -this.blurAmount,
                easing: "easeInOutExpo"
            }, 500);
            c.parent().find(".blurMask").animate({
                left: 0,
                top: 0,
                easing: "easeInOutExpo"
            }, 500);
            c.animate({
                left: 0,
                top: 0,
                easing: "easeInOutExpo"
            }, 500);
            c.find(".vuAll_button").delay(200).animate({
                marginRight: 0,
                opacity: 1
            }, 500);
            if (null != b) {
                var f = b.find(".headSize");
                f.bind("mouseover", function () {
                    a.itemOver(a, a.lastSlide, b, f)
                })
            }
        },
        rotate: function () {
            var a = this;
            a.interval = setInterval(function () {
                var b = a.masterArr[a.curAutoSlide].find(".headSize");
                a.$container.unbind("mouseenter");
                b.mouseover();
                a.curAutoSlide < a.totalImgs - 1 ? a.curAutoSlide++ : a.curAutoSlide = 0;
                a.$container.mouseenter(function () {
                    a.stopRotation()
                })
            }, 1E3 * a.autoSlideDelay)
        },
        stopRotation: function () {
            clearInterval(this.interval)
        }
    };
    f.fn.vuAll = function (a) {
        return this.each(function () {
            var b = f(this);
            b.data("vuAll") || b.data("vuAll", new g(b, a))
        })
    }
})(jQuery);
