(function (a)
{
    a.fn.extend(
    {
        beforeAfter_slider: function (b)
        {
            var c = {
                width: 876,
                height: 300,
                start_from: "left",
                start_pos: 30,
                follow: true
            };
            var b = a.extend(
            {}, a.fn.beforeAfter_slider.defaults, b);
            return this.each(function ()
            {
                var c = new Array;
                var d = 0;
                var e = a(this);
                var f = b;
                var g = 0;
                a(document).mousemove(function (a)
                {
                    g = a.pageY
                });
                var h = function (b)
                    {
                        a(b).css(
                        {
                            width: f.width + "px",
                            height: f.height + "px",
                            position: "relative"
                        })
                    };
                var i = function (b, c)
                    {
                        a(b).css(
                        {
                            width: f.width + "px",
                            height: f.height + "px",
                            "z-index": "200",
                            position: "relative",
                            overflow: "hidden",
                            left: 0,
                            top: 0
                        });
                        if (c > 0) a(b).css(
                        {
                            opacity: 0
                        })
                    };
                var j = function ()
                    {
                        jQuery(e.find("#drag")).animaDrag(
                        {
                            speed: 0,
                            interval: 0,
                            easing: null,
                            direction: "vertical",
                            boundary: e.find("#mask"),
                            boundary_offset: 30,
                            grip: null,
                            overlay: false,
                            afterDiv: x
                        })
                    };
                var k = function (b, c)
                    {
                        var d = 0;
                        b.find("div").each(function (c)
                        {
                            if (a(this).hasClass("before")) a(this).appendTo(b.find("#before").parent());
                            if (a(this).hasClass("after")) a(this).appendTo(b.find("#after").parent())
                        });
                        b.find("div").each(function (b)
                        {
                            if (a(this).attr("id") != "ext_ext_before") a(this).stop(true, true);
                            if (a(this).data("_top") == undefined) a(this).data("_top", a(this).position().top);
                            if (a(this).data("_left") == undefined) a(this).data("_left", a(this).position().left);
                            if (a(this).data("_op") == undefined) a(this).data("_op", a(this).css("opacity"));
                            if (a(this).hasClass("slideup"))
                            {
                                a(this).animate(
                                {
                                    top: a(this).data("_top") + 20 + "px"
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    top: a(this).data("_top") - 20 + "px"
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("slideright"))
                            {
                                a(this).animate(
                                {
                                    left: a(this).data("_left") - 20 + "px"
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    left: a(this).data("_left") + 20 + "px"
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("slidedown"))
                            {
                                a(this).animate(
                                {
                                    top: a(this).data("_top") - 20 + "px"
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    top: a(this).data("_top") + 20 + "px"
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("slideleft"))
                            {
                                a(this).animate(
                                {
                                    left: a(this).data("_left") + 20 + "px"
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    left: a(this).data("_left") - 20 + "px"
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("fadeup"))
                            {
                                a(this).animate(
                                {
                                    top: a(this).data("_top") + 20 + "px",
                                    opacity: 0
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    top: a(this).data("_top") - 20 + "px",
                                    opacity: a(this).data("_op")
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("faderight"))
                            {
                                a(this).animate(
                                {
                                    left: a(this).data("_left") - 20 + "px",
                                    opacity: 0
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    left: a(this).data("_left") + 20 + "px",
                                    opacity: a(this).data("_op")
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("fadedown"))
                            {
                                a(this).animate(
                                {
                                    top: a(this).data("_top") - 20 + "px",
                                    opacity: 0
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    top: a(this).data("_top") + 20 + "px",
                                    opacity: a(this).data("_op")
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("fadeleft"))
                            {
                                a(this).animate(
                                {
                                    left: a(this).data("_left") + 20 + "px",
                                    opacity: 0
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    left: a(this).data("_left") - 20 + "px",
                                    opacity: a(this).data("_op")
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                            if (a(this).hasClass("fade"))
                            {
                                a(this).animate(
                                {
                                    opacity: 0
                                }, {
                                    duration: 0,
                                    queue: false
                                }).delay(c + (d + 1) * 200).animate(
                                {
                                    opacity: a(this).data("_op")
                                }, {
                                    duration: 300,
                                    queue: true
                                });
                                d++
                            }
                        })
                    };
                var l = function (b, c)
                    {
                        var d = true;
                        if (b.index() > c.index()) d = false;
                        if (b.index() == 0 && c.index() != 1) d = false;
                        if (b.index() == b.parent().find("li").size() - 1 && c.index() == 0) d = true;
                        if (d)
                        {
                            b.animate(
                            {
                                left: 0 - f.width
                            }, {
                                duration: 500,
                                queue: false
                            });
                            c.css(
                            {
                                opacity: "1.0",
                                position: "absolute",
                                top: "0px",
                                left: f.width,
                                width: f.width,
                                height: f.height
                            })
                        }
                        else
                        {
                            b.animate(
                            {
                                left: f.width
                            }, {
                                duration: 500,
                                queue: false
                            });
                            c.css(
                            {
                                opacity: "1.0",
                                position: "absolute",
                                top: "0px",
                                left: 0 - f.width,
                                width: f.width,
                                height: f.height
                            })
                        }
                        b.parent().parent().parent().find(".mini_thumbnail_buttons").each(function (b)
                        {
                            a(this).css(
                            {
                                "background-position": "top left"
                            });
                            a(this).data("on", false);
                            if (b == c.parent().find("li").size() - c.index() - 1)
                            {
                                a(this).data("on", true);
                                a(this).css(
                                {
                                    "background-position": "bottom right"
                                })
                            }
                        });
                        var g = c.find("#before").parent().parent();
                        g.css(
                        {
                            width: e.find("#divider").position().left + "px",
                            overflow: "hidden"
                        });
                        c.animate(
                        {
                            left: "0px",
                            top: "0px",
                            opacity: "1.0"
                        }, {
                            duration: 500,
                            queue: false
                        });
                        x = c;
                        k(c, 500)
                    };
                var m = function (a)
                    {
                        a.find("ul").wrap("<div id='mask'></div>");
                        a.find("#mask").css(
                        {
                            overflow: "hidden",
                            width: f.width + "px",
                            height: f.height + "px",
                            position: "absolute"
                        })
                    };
                var n = function (b)
                    {
                        divider = a("<div id='divider'></div>");
                        b.find("#mask").append(divider);
                        drag = a("<div id='drag'></div>");
                        b.find("#mask").append(drag);
                        drag.hover(function ()
                        {
                            a(this).css(
                            {
                                "background-position": "left bottom"
                            })
                        }, function ()
                        {
                            a(this).css(
                            {
                                "background-position": "left top"
                            })
                        });
                        b.hover(function ()
                        {
                            a(this).find("#drag").animate(
                            {
                                opacity: 1
                            }, {
                                duration: 200,
                                queue: false
                            });
                            a(this).find("#divider").animate(
                            {
                                opacity: 1
                            }, 200)
                        }, function ()
                        {
                            a(this).find("#drag").animate(
                            {
                                opacity: .3
                            }, 200);
                            a(this).find("#divider").animate(
                            {
                                opacity: .3
                            }, 200)
                        })
                    };
                var o = function (b)
                    {
                        b.find("li >img").each(function ()
                        {
                            a(this).attr(
                            {
                                id: "before"
                            });
                            if (a(this).attr("alt").length != 0 && a(this).attr("alt") != null)
                            {
                                a(this).parent().append("<img id='after' src='" + a(this).attr("alt") + "'>")
                            }
                            else
                            {
                                a(this).parent().append("<img id='before' src='" + a(this).attr("src") + "'>")
                            }
                            a(this).parent().find("#before, #after").wrapAll("<div id='ba_images'></div>");
                            a(this).parent().find("#after").wrap("<div id='ext_ext_after'><div id='ext_after'></div></div>");
                            a(this).parent().find("#before").wrap("<div id='ext_ext_before'><div id='ext_before'></div></div>");
                            var b = a(this).parent().parent().parent().find("#after").parent().parent();
                            var c = b.find("#after").parent();
                            var d = c.find("#after");
                            var e = a(this).parent().parent().parent().find("#before").parent().parent();
                            var f = e.find("#before").parent();
                            var g = f.find("#before");
                            b.css(
                            {
                                position: "absolute",
                                "z-index": "0",
                                top: "0px"
                            });
                            e.css(
                            {
                                position: "absolute",
                                "z-index": "1",
                                top: "0px",
                                left: "0px"
                            });
                            b.parent().css(
                            {
                                "z-index": 1
                            });
                            var h = a("<div id='loader' class='loader'></div>");
                            a(b).parent().parent().append(h);
                            c.find("img").load(function ()
                            {
                                a(this).parent().parent().parent().parent().find("#loader").each(function ()
                                {
                                    a(this).remove()
                                })
                            })
                        })
                    };
                var p = function (b)
                    {
                        var c = a('<div id="toolbox" style="opacity:0"></div>');
                        b.append(c);
                        c.css(
                        {
                            "z-index": "4051"
                        });
                        var d = a("<div id='previous'></div>");
                        var g = a("<div id='next'></div>");
                        var h = function (b)
                            {
                                b.hover(function ()
                                {
                                    if (a(this).attr("id") == "previous") a(this).css(
                                    {
                                        "background-position": "bottom right"
                                    });
                                    else a(this).css(
                                    {
                                        "background-position": "bottom left"
                                    })
                                }, function ()
                                {
                                    if (a(this).attr("id") == "previous") a(this).css(
                                    {
                                        "background-position": "top right"
                                    });
                                    else a(this).css(
                                    {
                                        "background-position": "top left"
                                    })
                                })
                            };
                        var i = function (b)
                            {
                                b.click(function ()
                                {
                                    var b = x.index();
                                    if (a(this).attr("id") == "previous") b++;
                                    else b--;
                                    if (b == x.parent().find("li").size()) b = 0;
                                    if (b == -1) b = x.parent().find("li").size() - 1;
                                    var c = e.find("li").each(function (c)
                                    {
                                        if (c == b)
                                        {
                                            l(x, a(this))
                                        }
                                    })
                                })
                            };
                        h(d);
                        i(d);
                        h(g);
                        i(g);
                        c.append(d);
                        c.append(g);
                        var j = a("<div id='mini_divider'></div>");
                        c.append(j);
                        b.find("li").each(function (b)
                        {
                            var d = a(this).parent().find("li").size() - 1;
                            var g = a("<div id='" + (d - b) + "' class='mini_thumbnail_buttons'></div>");
                            c.append(g);
                            if (x.index() == d - b)
                            {
                                g.data("on", true);
                                g.css(
                                {
                                    "background-position": "bottom right"
                                })
                            }
                            g.hover(function ()
                            {
                                a(this).css(
                                {
                                    "background-position": "top right"
                                });
                                if (a(this).data().on == true) a(this).css(
                                {
                                    "background-position": "bottom right"
                                });
                                a(this).parent().append('<div id="image_thumbnail" style="opacity:0.0;left:' + a(this).position().left + "px;top:" + (a(this).position().top + 10) + 'px"></div>');
                                var b = a(this).parent().find("#image_thumbnail");
                                var c = a(this).attr("id");
                                var d = "";
                                var g = "";
                                e.find("li").each(function ()
                                {
                                    if (a(this).index() == c)
                                    {
                                        d = a(this).find("#before").attr("src");
                                        g = a(this).find("#after").attr("src")
                                    }
                                });
                                var h = b.width() - 6;
                                var i = b.height() - 6;
                                var j = e.find("#divider").position().left / f.width * h;
                                b.append('<div><div><img style="position:absolute;top:3px;left:3px;width:' + h + "px;height:" + i + 'px" src="' + g + '"></div></div>');
                                b.append('<div style="position:absolute;overflow:hidden;width:' + j + "px;height:" + b.height() + 'px"><div><img style="position:absolute;top:3px;left:3px;width:' + h + "px;height:" + i + 'px" src="' + d + '"></div></div>');
                                b.append('<div id="loader" style="loader"></div>');
                                b.append('<div id="image_thumbnail_arrow" style="position:absolute;left:' + (b.width() / 2 - 4) + "px;top:" + (b.height() - 1) + 'px"></div>');
                                b.animate(
                                {
                                    opacity: 1,
                                    top: +1
                                }, 200)
                            }, function ()
                            {
                                a(this).css(
                                {
                                    "background-position": "top left"
                                });
                                if (a(this).data().on == true) a(this).css(
                                {
                                    "background-position": "bottom left"
                                });
                                a(this).parent().find("#image_thumbnail").remove()
                            });
                            g.click(function ()
                            {
                                if (a(this).data().on != true)
                                {
                                    var b = a(this).attr("id");
                                    var c = e.find("li").each(function (c)
                                    {
                                        if (c == b)
                                        {
                                            l(x, a(this))
                                        }
                                    })
                                }
                            })
                        })
                    };
                var q = function (b)
                    {
                        var d = 0;
                        b.find("ul li:first img").each(function (b)
                        {
                            c[d] = a(this).attr("src");
                            d++
                        });
                        c[d] = "images/navigation/buttons.png";
                        d++;
                        c[d] = "images/navigation/toolbar_separator.png";
                        d++
                    };
                var r = function (b)
                    {
                        var e = new Image;
                        a(e).css("display", "none");
                        a(e).attr("src", c[d]);
                        if (e.complete || e.readyState === 4)
                        {
                            d++;
                            if (d == c.length)
                            {
                                t(b)
                            }
                            else
                            {
                                r(b)
                            }
                        }
                        else
                        {
                            a(e).load(function ()
                            {
                                d++;
                                if (d == c.length)
                                {
                                    t(b)
                                }
                                else
                                {
                                    r(b)
                                }
                            })
                        }
                    };
                var s = function (a)
                    {
                        w = a.find("#drag").height() / 2;
                        a.each(function ()
                        {
                            h(this)
                        });
                        a.find("li").each(function (a)
                        {
                            i(this, a)
                        });
                        a.css(
                        {
                            opacity: "0.0",
                            display: "block"
                        });
                        a.animate(
                        {
                            opacity: "1.0"
                        }, 1500);
                        p(a)
                    };
                var t = function (b)
                    {
                        w = b.find("#drag").height() / 2;
                        b.each(function ()
                        {
                            h(this)
                        });
                        b.find("li").each(function (a)
                        {
                            i(this, a)
                        });
                        b.css(
                        {
                            opacity: "0.0",
                            display: "block"
                        });
                        b.animate(
                        {
                            opacity: "1.0"
                        }, 1500);
                        var c = x.find("#after").parent().parent();
                        var d = c.find("#after").parent();
                        var g = d.find("#after");
                        var l = x.find("#before").parent().parent();
                        var m = l.find("#before").parent();
                        var n = m.find("#before");
                        if (f.start_from == "right")
                        {
                            l.css(
                            {
                                width: f.width,
                                overflow: "hidden"
                            });
                            l.animate(
                            {
                                width: f.width + "px"
                            }, 0).delay(500);
                            b.find("#drag").animate(
                            {
                                left: f.width + "px"
                            }, 0).delay(500);
                            b.find("#divider").animate(
                            {
                                left: f.width + "px"
                            }, 0).delay(500)
                        }
                        if (f.start_from == "left")
                        {
                            l.css(
                            {
                                width: "0px",
                                overflow: "hidden"
                            });
                            l.animate(
                            {
                                width: "0px",
                                overflow: "hidden"
                            }, 0).delay(500);
                            b.find("#drag").animate(
                            {
                                left: "0px"
                            }, 0).delay(500);
                            b.find("#divider").animate(
                            {
                                left: "0px"
                            }, 0).delay(500)
                        }
                        l.animate(
                        {
                            width: f.start_pos + "px"
                        }, 800);
                        b.find("#drag").animate(
                        {
                            opacity: .3,
                            left: f.start_pos - 20 + "px"
                        }, {
                            duration: 800,
                            complete: function ()
                            {
                                if (f.follow)
                                {
                                    var b = function (b)
                                        {
                                            a(this).find("#drag").css(
                                            {
                                                opacity: "1.0"
                                            });
                                            a(this).find("#drag").css(
                                            {
                                                top: b.pageY - a(this).offset().top - w - v + "px"
                                            })
                                        };
                                    e.bind("mousemove", b)
                                }
                            }
                        });
                        b.find("#divider").animate(
                        {
                            opacity: .3,
                            left: f.start_pos + "px"
                        }, 800);
                        j();
                        b.find("#toolbox").animate(
                        {
                            opacity: "1.0"
                        }, 1e3);
                        b.find("ul li").animate(
                        {
                            opacity: "1.0"
                        }, 300);
                        b.find("#mainloader").animate(
                        {
                            opacity: "0.4"
                        }, {
                            duration: 500,
                            complete: function ()
                            {
                                e.find("#mainloader").remove()
                            }
                        });
                        k(x, 500)
                    };
                var u = false;
                var v = parseInt(a(this).css("padding-top"));
                var w = 0;
                a(this).find("#drag").height() * 2;
                var x = e.find("li").first();
                m(e);
                n(e);
                o(e);
                var y = a("<div id='mainloader' class='loader'></div>");
                e.append(y);
                e.find("ul li").css(
                {
                    opacity: "0.0"
                });
                e.find("#divider").css(
                {
                    opacity: "0.0"
                });
                e.find("#drag").css(
                {
                    opacity: "0.0"
                });
                s(e);
                q(e);
                r(e)
            })
        }
    })
})(jQuery)
