/**
Script: Slideshow.Fold.js
	Slideshow.Fold - Flash extension for Slideshow.

License:
	MIT-style license.

Copyright:
	Copyright (c) 2008 [Aeron Glemann](http://www.electricprism.com/aeron/).
*/

Slideshow.Fold = new Class({
    Extends: Slideshow,
    initialize: function(B, C, A) {
        this.parent(B, C, A)
    },
    _show: function(B) {
        if (!this.image.retrieve("tween")) {
            var C = (this.options.overlap) ? {
                duration: this.options.duration
            }: {
                duration: this.options.duration / 2
            };
            $$(this.a, this.b).set("tween", $merge(C, {
                link: "chain",
                onStart: this._start.bind(this),
                onComplete: this._complete.bind(this),
                property: "clip",
                transition: this.options.transition
            }))
        }
        var F = this._rect(this.image);
        var A = (this.counter % 2) ? this.a: this.b;
        if (B) {
            A.get("tween").cancel().set("rect(0, 0, 0, 0)");
            this.image.setStyle("visibility", "visible").get("tween").cancel().set("auto")
        } else {
            if (this.options.overlap) {
                A.setStyle("visibility", "visible").get("tween").set("auto");
                var D = this.image.setStyle("visibility", "visible").get("tween").set(F.top + " " + F.left + " " + Math.ceil(F.bottom / 2) + " " + F.left).start(F.top + " " + F.right + " " + Math.ceil(F.bottom / 2) + " " + F.left).start(F.top + " " + F.right + " " + F.bottom + " " + F.left)
            } else {
                var E = function(G) {
                    this.image.setStyle("visibility", "visible").get("tween").set(G.top + " " + G.left + " " + Math.ceil(G.bottom / 2) + " " + G.left).start(G.top + " " + G.right + " " + Math.ceil(G.bottom / 2) + " " + G.left).start(G.top + " " + G.right + " " + G.bottom + " " + G.left)
                }.pass(F, this);
                var F = this._rect(A);
                A.setStyle("visibility", "visible").get("tween").set(F.top + " " + F.right + " " + F.bottom + " " + F.left).start(F.top + " " + F.right + " " + Math.ceil(F.bottom / 2) + " " + F.left).start(F.top + " " + F.left + " " + Math.ceil(F.bottom / 2) + " " + F.left).chain(E)
            }
        }
    },
    _rect: function(A) {
        var B = A.getCoordinates(this.slideshow.retrieve("images"));
        B.right = (B.right > this.width) ? this.width - B.left: B.width;
        B.bottom = (B.bottom > this.height) ? this.height - B.top: B.height;
        B.top = (B.top < 0) ? Math.abs(B.top) : 0;
        B.left = (B.left < 0) ? Math.abs(B.left) : 0;
        return B
    }
});
