var debug = true;
if (!debug) {
    var console = {
        log: function() {}
    }
}
var iFrame = new Class({
    Implements: [Options, Events],
    getOptions: function() {
        return {
            src: "javascript:void(0);",
            id: "iFrame_" + new Date().getTime(),
            container: document.body,
            zIndex: 1,
            browsers: (Browser.Engine.trident4)
        }
    },
    initialize: function(A) {
        this.setOptions(this.getOptions(), A);
        this.container = $(this.options.container);
        if ($(this.options.id)) {
            this.frame = $(this.options.id)
        } else {
            this.frame = new Element("iframe", {
                id: this.options.id,
                name: this.options.id,
                src: this.options.src,
                frameborder: 0,
                scrolling: "no",
                styles: {
                    position: "absolute",
                    zIndex: this.options.zIndex,
                    border: "0",
                    filter: "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)",
                    top: 0,
                    left: 0,
                    width: "100%",
                    height: "100%",
                    display: "none"
                }
            });
            this.frame.injectInside(this.container)
        }
    },
    set: function(A) {
        if ($type(A) == "object") {
            var C = A
        } else {
            var B = $(A);
            var C = B.getCoordinates()
        }
        this.frame.setStyles({
            top: C.top,
            left: C.left,
            width: C.width,
            height: C.height
        })
    },
    fillPage: function() {
        this.frame.setStyles({
            top: 0,
            left: 0,
            width: window.getScrollSize().x,
            height: window.getScrollSize().y
        })
    },
    show: function() {
        this.frame.setStyle("display", "block")
    },
    hide: function() {
        this.frame.setStyle("display", "none")
    }
});
Fx.Slide = new Class({
    Extends: Fx,
    options: {
        mode: "vertical"
    },
    initialize: function(B, A) {
        this.addEvent("complete",
        function() {
            this.open = (this.wrapper["offset" + this.layout.capitalize()] != 0);
            if (this.open && Browser.Engine.webkit419) {
                this.element.dispose().inject(this.wrapper)
            }
        },
        true);
        this.element = this.subject = $(B);
        this.parent(A);
        var C = this.element.retrieve("wrapper");
        this.wrapper = C || new Element("div", {
            styles: $extend(this.element.getStyles("margin", "position"), {
                overflow: "hidden"
            })
        }).wraps(this.element);
        this.element.store("wrapper", this.wrapper).setStyle("margin", 0);
        this.now = [];
        this.open = true
    },
    vertical: function() {
        this.margin = "margin-top";
        this.layout = "height";
        this.offset = this.element.offsetHeight
    },
    horizontal: function() {
        this.margin = "margin-left";
        this.layout = "width";
        this.offset = this.element.offsetWidth
    },
    set: function(A) {
        this.element.setStyle(this.margin, A[0]);
        this.wrapper.setStyle(this.layout, A[1]);
        return this
    },
    compute: function(E, D, C) {
        var B = [];
        var A = 2;
        A.times(function(F) {
            B[F] = Fx.compute(E[F], D[F], C)
        });
        return B
    },
    start: function(B, E) {
        if (!this.check(arguments.callee, B, E)) {
            return this
        }
        this[E || this.options.mode]();
        var D = this.element.getStyle(this.margin).toInt();
        var C = this.wrapper.getStyle(this.layout).toInt();
        var A = [[D, C], [0, this.offset]];
        var G = [[D, C], [ - this.offset, 0]];
        var F;
        switch (B) {
        case "in":
            F = A;
            break;
        case "out":
            F = G;
            break;
        case "toggle":
            F = (this.wrapper["offset" + this.layout.capitalize()] == 0) ? A: G
        }
        return this.parent(F[0], F[1])
    },
    slideIn: function(A) {
        return this.start("in", A)
    },
    slideOut: function(A) {
        return this.start("out", A)
    },
    hide: function(A) {
        this[A || this.options.mode]();
        this.open = false;
        return this.set([ - this.offset, 0])
    },
    show: function(A) {
        this[A || this.options.mode]();
        this.open = true;
        return this.set([0, this.offset])
    },
    toggle: function(A) {
        return this.start("toggle", A)
    }
});
Element.Properties.slide = {
    set: function(B) {
        var A = this.retrieve("slide");
        if (A) {
            A.cancel()
        }
        return this.eliminate("slide").store("slide:options", $extend({
            link: "cancel"
        },
        B))
    },
    get: function(A) {
        if (A || !this.retrieve("slide")) {
            if (A || !this.retrieve("slide:options")) {
                this.set("slide", A)
            }
            this.store("slide", new Fx.Slide(this, this.retrieve("slide:options")))
        }
        return this.retrieve("slide")
    }
};
Element.implement({
    slide: function(D, E) {
        D = D || "toggle";
        var B = this.get("slide"),
        A;
        switch (D) {
        case "hide":
            B.hide(E);
            break;
        case "show":
            B.show(E);
            break;
        case "toggle":
            var C = this.retrieve("slide:flag", B.open);
            B[(C) ? "slideOut": "slideIn"](E);
            this.store("slide:flag", !C);
            A = true;
            break;
        default:
            B.start(D, E)
        }
        if (!A) {
            this.eliminate("slide:flag")
        }
        return this
    }
});
var Asset = new Hash({
    javascript: function(F, D) {
        D = $extend({
            onload: $empty,
            document: document,
            check: $lambda(true)
        },
        D);
        var B = new Element("script", {
            src: F,
            type: "text/javascript"
        });
        var E = D.onload.bind(B),
        A = D.check,
        G = D.document;
        delete D.onload;
        delete D.check;
        delete D.document;
        B.addEvents({
            load: E,
            readystatechange: function() {
                if (["loaded", "complete"].contains(this.readyState)) {
                    E()
                }
            }
        }).setProperties(D);
        if (Browser.Engine.webkit419) {
            var C = (function() {
                if (!$try(A)) {
                    return
                }
                $clear(C);
                E()
            }).periodical(50)
        }
        return B.inject(G.head)
    },
    css: function(B, A) {
        return new Element("link", $merge({
            rel: "stylesheet",
            media: "screen",
            type: "text/css",
            href: B
        },
        A)).inject(document.head)
    },
    image: function(C, B) {
        B = $merge({
            onload: $empty,
            onabort: $empty,
            onerror: $empty
        },
        B);
        var D = new Image();
        var A = $(D) || new Element("img"); ["load", "abort", "error"].each(function(E) {
            var F = "on" + E;
            var G = B[F];
            delete B[F];
            D[F] = function() {
                if (!D) {
                    return
                }
                if (!A.parentNode) {
                    A.width = D.width;
                    A.height = D.height
                }
                D = D.onload = D.onabort = D.onerror = null;
                G.delay(1, A, A);
                A.fireEvent(E, A, 1)
            }
        });
        D.src = A.src = C;
        if (D && D.complete) {
            D.onload.delay(1)
        }
        return A.setProperties(B)
    },
    images: function(D, C) {
        C = $merge({
            onComplete: $empty,
            onProgress: $empty
        },
        C);
        if (!D.push) {
            D = [D]
        }
        var A = [];
        var B = 0;
        D.each(function(F) {
            var E = new Asset.image(F, {
                onload: function() {
                    C.onProgress.call(this, B, D.indexOf(F));
                    B++;
                    if (B == D.length) {
                        C.onComplete()
                    }
                }
            });
            A.push(E)
        });
        return new Elements(A)
    }
});
var Layers = new Class({
    Implements: Options,
    getOptions: function() {
        return {}
    },
    initialize: function(A) {
        this.setOptions(this.getOptions(), A);
        this.layers = [];
        this.elements = []
    },
    toggle: function(B, A) {
        if ($(B)) {
            B = this.GetElement(B)
        }
        if (this.elements.contains(B)) {
            var C = this.elements.indexOf(B);
            if (this.layers[C].options.control == A.control) {
                this.hide(B, A)
            } else {
                this.show(B, A)
            }
        } else {
            this.show(B, A)
        }
        return false
    },
    show: function(C, B) {
        if ($(C)) {
            C = this.GetElement(C)
        }
        if (this.elements.contains(C)) {
            var D = this.elements.indexOf(C);
            if (this.layers[D].inProgress == false) {
                if (this.layers[D].visible) {
                    C.store("show", true);
                    C.store("options", B);
                    this.hide(C, B)
                } else {
                    this.layers[D].show()
                }
            }
        } else {
            this.elements.push(C);
            var A = new Layer(C, B);
            this.layers.push(A);
            A.show()
        }
        return false
    },
    hide: function(C, B, A) {
        if ($(C)) {
            C = this.GetElement(C)
        }
        if (this.elements.contains(C)) {
            var D = this.elements.indexOf(C);
            if (this.layers[D].inProgress == false) {
                this.layers[D].hide()
            } else { (function() {
                    layers.hide(C)
                }).delay(250, C)
            }
        }
        return false
    },
    UpdateDimensions: function(A) {
        if ($(A)) {
            A = this.GetElement(A)
        }
        if (this.elements.contains(A)) {
            var B = this.elements.indexOf(A);
            this.layers[B].updateFrameDimensions()
        }
        return false
    },
    GetElement: function(B) {
        var A = $(B);
        $(document.body).getElements("div[id=" + B + "]").each(function(D, C) {
            if (layers.elements.contains(D)) {
                A = D
            }
        });
        return A
    }
});
var layers = new Layers();
var Layer = new Class({
    Implements: Options,
    getOptions: function() {
        return {
            fade: false,
            slide: false,
            vertical: null,
            horizontal: null,
            duration: 500,
            transition: "sine:out",
            control: null,
            position: null,
            align: null,
            center: "both",
            container: window,
            modal: false,
            modalTarget: null,
            bgColor: "#000",
            opacity: 0.7,
            dropshadow: false,
            shadow: null,
            shadowSize: 8,
            closeOnMouseout: false,
            mouseoutDelay: 2000,
            closeOnBlur: false,
            MoveToBody: false,
            OnHide: $empty,
            OnShow: $empty
        }
    },
    initialize: function(E, D) {
        this.setOptions(this.getOptions(), D);
        this.layer = $(E);
        this.unique = new Date().getTime();
        this.ref = E;
        this.visible = false;
        this.doBlur = false;
        this.inProgress = false;
        if (this.layer && this.options.MoveToBody) {
            if (this.layer.getParent() != document.body) {
                this.layer.inject($(document.body))
            }
        }
        if (this.layer) {
            this.ref = this.layer;
            this.layer.setStyles({
                display: "block",
                visibility: "hidden",
                position: "absolute"
            });
            this.coords = this.layer.getCoordinates();
            this.layer.setStyles({
                position: "relative",
                "z-index": 2
            });
            var B = false;
            if (this.layer.getParent().id) {
                if (this.layer.getParent().id.contains("EzLayerWrapperElement")) {
                    B = true
                }
            }
            if (B) {
                this.container = this.layer.getParent();
                this.container.setStyles({
                    overflow: "hidden",
                    width: 0,
                    height: 0,
                    display: "none"
                })
            } else {
                this.container = new Element("div", {
                    id: "EzLayerWrapperElement" + this.unique,
                    styles: {
                        overflow: "hidden",
                        width: 0,
                        height: 0,
                        display: "none"
                    }
                }).wraps(this.layer)
            }
            this.layer.setStyle("visibility", "visible")
        }
        if (this.options.modalTarget) {
            this.options.modal = false;
            var G = $(this.options.modalTarget);
            if (!this.layer) {
                this.layer = new Element("div").inject(document.body)
            }
            var A = G.get("tag");
            if (A == "img" || A == "input" || A == "textarea" || A == "select") {
                G = new Element("span").wraps(G)
            }
            if (G.getStyle("position") == "static") {
                G.setStyle("position", "relative")
            }
            this.loaderContainer = new Element("div", {
                "class": "ezLoader",
                styles: {
                    position: "absolute",
                    top: 0,
                    left: 0,
                    width: "100%",
                    height: "100%",
                    zIndex: 1
                }
            }).wraps(this.layer).inject(G);
            this.content = new Element("div", {
                styles: {
                    position: "absolute",
                    height: "auto",
                    width: "100%",
                    zIndex: 2
                }
            }).wraps(this.layer);
            this.bg = new Element("div", {
                styles: {
                    position: "absolute",
                    width: "100%",
                    height: "100%",
                    top: 0,
                    left: 0,
                    zIndex: 1,
                    "background-color": this.options.bgColor,
                    opacity: this.options.opacity
                }
            }).inject(this.loaderContainer);
            this.content = this.layer;
            this.layer = this.loaderContainer;
            this.container = new Element("div").wraps(this.layer);
            if (Browser.Engine.trident4) {
                var F = G.getCoordinates();
                this.container.setStyles({
                    position: "absolute",
                    top: 0,
                    left: 0,
                    width: F.width,
                    height: F.height
                })
            }
            this.coords = G.getCoordinates();
            this.coords.width++
        }
        this.layerRef = this.layer;
        if (this.options.shadow) {
            var C = 0;
            if (this.options.shadow == "glow") {
                C = this.options.shadowSize * 2
            }
            if (this.options.shadow == "drop") {
                C = this.options.shadowSize
            }
            this.coords.width += C;
            this.coords.height += C;
            this.layerRef = this.createShadow()
        }
        this.fx = {};
        if (Browser.Engine.trident4) {
            var F = this.container;
            if (this.options.modal) {
                F = document.body
            }
            this.frame = new iFrame({
                container: F
            });
            this.frame.frame.setStyle("height", "100%");
            this.frameTimer = 0
        }
        if (this.options.modal) {
            if ($("ezLayerOverlay" + this.unique)) {
                this.overlay = $("ezLayerOverlay" + this.unique).setStyles({
                    backgroundColor: this.options.bgColor
                })
            } else {
                this.overlay = new Element("div", {
                    id: "ezLayerOverlay" + this.unique,
                    styles: {
                        position: "absolute",
                        display: "none",
                        opacity: 0,
                        top: 0,
                        left: 0,
                        width: window.getScrollSize().x,
                        height: window.getScrollSize().y,
                        zIndex: 2,
                        backgroundColor: this.options.bgColor
                    }
                }).inject(document.body)
            }
            this.fx.overlay = new Fx.Tween(this.overlay, {
                duration: this.options.duration,
                transition: Fx.Transitions.linear,
                onComplete: function() {
                    if (this.overlay.getStyle("opacity") == 0) {
                        this.overlay.setStyle("display", "none")
                    }
                }.bind(this)
            });
            if (this.frame) {
                this.frame.fillPage()
            }
        }
        this.fx.container = new Fx.Morph(this.container, {
            duration: this.options.duration,
            transition: this.options.transition,
            onStart: function() {
                if (this.doHide && this.frame) {
                    $clear(this.frameTimer)
                }
                if (!this.options.fade) {
                    this.container.setStyle("opacity", 1)
                }
            }.bind(this),
            onComplete: function() {
                if (this.doHide) {
                    this.container.setStyle("display", "none");
                    this.layer.setStyle("display", "none");
                    this.layer.inject(this.container, "before");
                    if (this.frame) {
                        this.frame.frame.destroy()
                    }
                    this.container.destroy();
                    if (this.options.modalTarget) {
                        this.content.setStyle("display", "none");
                        this.content.inject(this.layer, "before");
                        this.layer.destroy()
                    }
                    if (this.overlay) {
                        this.overlay.destroy()
                    }
                    this.visible = false;
                    var H = layers.elements.indexOf(this.ref);
                    layers.elements.erase(this.ref);
                    layers.layers.splice(H, 1);
                    if ($type(this.ref) == "element") {
                        if (this.ref.retrieve("show")) {
                            this.ref.store("show", false);
                            layers.show(this.ref, this.ref.retrieve("options"))
                        } else {
                            this.inProgress = false
                        }
                        this.inProgress = false
                    }
                } else {
                    if (!Browser.Engine.trident4) {
                        this.container.setStyles({
                            overflow: "visible",
                            height: "auto"
                        });
                        this.updateFrameDimensions()
                    }
                    if (this.options.closeOnMouseout) {
                        this.layer.addEvents({
                            mouseout: function() {
                                this.delay = layers.hide.delay(this.options.mouseoutDelay, layers, this.ref)
                            }.bind(this),
                            mouseover: function() {
                                $clear(this.delay)
                            }.bind(this)
                        });
                        if (this.options.control) {
                            $(this.options.control).cloneEvents(this.layer, "mouseout");
                            $(this.options.control).cloneEvents(this.layer, "mouseover")
                        }
                    }
                    this.doBlur = true;
                    this.visible = true;
                    this.inProgress = false
                }
            }.bind(this)
        });
        this.fx.layer = new Fx.Tween(this.layerRef, {
            duration: this.options.duration,
            onComplete: function() {
                if (this.doHide) { (function() {
                        this.layerRef.setStyle("opacity", 1)
                    }).delay(50, this)
                }
            }.bind(this)
        });
        this.position();
        window.addEvent("resize", this.resize.bind(this));
        if (this.options.closeOnBlur) {
            document.addEvent("click",
            function(J) {
                if (this.doBlur) {
                    J = new Event(J);
                    var H = this.layer.getCoordinates();
                    var I = true;
                    if (J.page.x > H.left && J.page.x < H.right && J.page.y > H.top && J.page.y < H.bottom) {
                        I = false
                    }
                    if (I) {
                        if (this.options.OnHide) {
                            layers.hide(this.ref, {
                                onHide: this.options.OnHide
                            })
                        } else {
                            layers.hide(this.ref)
                        }
                    }
                }
            }.bind(this))
        }
    },
    updateFrameDimensions: function() {
        if (this.frame) {
            var A = this.container.getCoordinates();
            if (this.options.modalTarget) {
                A = $(this.options.modalTarget).getCoordinates();
                this.layer.setStyles({
                    width: A.width,
                    height: A.height
                });
                this.bg.setStyles({
                    width: A.width,
                    height: A.height
                })
            }
            this.frame.frame.setStyles({
                width: A.width,
                height: A.height
            })
        }
    },
    resize: function() {
        if (this.overlay) {
            this.overlay.setStyle("display", "none");
            this.overlay.setStyles({
                width: window.getScrollSize().x,
                height: window.getScrollSize().y,
                display: "block"
            })
        }
        if (this.frame && this.options.modal) {
            this.frame.fillPage()
        }
        if (this.options.position == "center") {
            this.center()
        } else {
            this.position()
        }
        this.updateFrameDimensions()
    },
    position: function() {
        var E = $(this.options.control);
        var G = this.options.position;
        var F = this.options.align;
        var A = this.options.center;
        var B = this.container;
        if (E) {
            var D = E.getCoordinates();
            var C = {};
            C.position = "absolute";
            C.zIndex = 3;
            C.top = D.top;
            C.left = D.left;
            if (G == "top") {
                this.options.vertical = "up";
                C.top = D.top - this.coords.height;
                C.left = D.left;
                C.width = this.coords.width
            }
            if (G == "left") {
                this.options.horizontal = "left";
                C.top = D.top;
                C.left = D.left - this.coords.width;
                C.height = this.coords.height
            }
            if (G == "bottom") {
                this.options.vertical = "down";
                C.top = D.bottom;
                C.left = D.left;
                C.width = this.coords.width
            }
            if (G == "right") {
                this.options.horizontal = "right";
                C.top = D.top;
                C.left = D.right;
                C.height = this.coords.height
            }
            if (G == "center") {
                C.top = D.bottom;
                C.width = this.coords.width;
                C.height = this.coords.height
            }
            if (F == "top") {
                C.top = D.top
            }
            if (F == "bottom") {
                C.top = D.top + D.height - this.coords.height
            }
            if (F == "left") {
                C.left = D.left
            }
            if (F == "right") {
                C.left = D.left + D.width - this.coords.width
            }
            if (Browser.Engine.trident) {
                C.top += $(document.body).getStyle("margin-top").toInt();
                C.left += $(document.body).getStyle("margin-left").toInt()
            }
            if ($type(G) == "array") {
                C.top += G[1];
                C.left += G[0];
                if (this.options.vertical) {
                    C.width = this.coords.width
                }
                if (this.options.horizontal) {
                    C.height = this.coords.height
                }
            }
            this.container.setStyles(C);
            this.coords.top = C.top;
            this.coords.left = C.left;
            this.coords.bottom = C.top + this.coords.height;
            this.coords.right = C.left + this.coords.width;
            if (G == "center") {
                this.center(true)
            }
        } else {
            if ($type(G) == "array") {
                this.container.setStyles({
                    top: G[1],
                    left: G[0],
                    position: "absolute",
                    zIndex: 3,
                    width: this.coords.width,
                    height: this.coords.height
                })
            } else {
                if (G == "center") {
                    if (this.options.modalTarget == null) {
                        this.container.setStyles({
                            position: "absolute",
                            zIndex: 3,
                            width: this.coords.width,
                            height: this.coords.height
                        })
                    }
                    this.center()
                } else {
                    if (this.options.modalTarget == null) {
                        this.container.setStyles({
                            width: this.coords.width,
                            height: this.coords.height
                        })
                    }
                }
            }
        }
    },
    center: function(F) {
        var A = $(this.options.container);
        var C = A.getCoordinates();
        var E = C.top + (C.height / 2) - (this.coords.height / 2);
        var D = C.left + (C.width / 2) - (this.coords.width / 2);
        if (this.options.modalTarget && this.content) {
            var B = this.content.getCoordinates();
            C = this.container.getCoordinates();
            E = (C.height / 2) - (B.height / 2);
            D = (C.width / 2) - (B.width / 2)
        }
        if (Browser.Engine.trident) {
            E += $(document.body).getStyle("margin-top").toInt();
            D += $(document.body).getStyle("margin-left").toInt()
        }
        if (this.options.modalTarget) {
            if (this.content) {
                if (this.options.center == "horizontal") {
                    this.content.setStyles({
                        left: D
                    })
                }
                if (this.options.center == "vertical") {
                    this.content.setStyles({
                        top: E
                    })
                }
                if (this.options.center == "both") {
                    this.content.setStyles({
                        top: E,
                        left: D
                    })
                }
            }
        } else {
            if (this.options.center == "horizontal") {
                this.container.setStyles({
                    left: D
                })
            }
            if (this.options.center == "vertical") {
                this.container.setStyles({
                    top: E
                })
            }
            if (this.options.center == "both") {
                this.container.setStyles({
                    top: E,
                    left: D
                })
            }
        }
    },
    show: function() {
        this.doHide = false;
        if (this.frame) {
            this.frame.show()
        }
        if (this.shadow) {
            this.shadow.resize()
        }
        this.inProgress = true;
        var A = {};
        var B = {};
        if (this.options.vertical) {
            A.height = [0, this.coords.height];
            if (this.options.slide) {
                B.height = 0
            } else {
                B.height = this.coords.height
            }
            if (this.options.vertical == "up") {
                A.top = [this.coords.top + this.coords.height, this.coords.top]
            }
        } else {
            B.height = this.coords.height
        }
        if (this.options.horizontal) {
            A.width = [0, this.coords.width];
            if (this.options.slide) {
                B.width = 0
            } else {
                B.width = this.coords.width
            }
            if (this.options.horizontal == "left") {
                A.left = [this.coords.right, this.coords.left]
            }
        } else {
            B.width = this.coords.width
        }
        if (!this.options.slide && this.options.fade) {
            var A = {}
        }
        if (this.options.fade) {
            B.opacity = 0;
            A.opacity = [0, 1]
        }
        B.display = "block";
        this.options.OnShow();
        this.container.setStyles(B);
        if (!this.options.slide && !this.options.fade) {
            this.fx.container.fireEvent("complete")
        } else {
            this.fx.container.start(A)
        }
        if (this.overlay) {
            this.overlay.setStyle("display", "block");
            this.fx.overlay.start("opacity", 0, this.options.opacity)
        }
        if ((this.frame && !this.options.modal) || this.shadow) {
            this.contentHeight = this.container.getCoordinates().height;
            this.frameTimer = (function() {
                this.checkDimensions()
            }).delay(this.options.duration, this)
        }
    },
    hide: function() {
        this.doHide = true;
        this.doBlur = false;
        this.inProgress = true;
        var A = {};
        var B = this.layerRef.getCoordinates();
        window.removeEvent("resize", this.resize.bind(this));
        if (this.frameTimer) {
            $clear(this.frameTimer)
        }
        this.container.setStyles({
            overflow: "hidden",
            width: B.width,
            height: B.height
        });
        if (this.options.vertical) {
            A.height = 0;
            if (this.options.vertical == "up") {
                A.top = this.coords.bottom
            }
        }
        if (this.options.horizontal) {
            A.width = 0;
            if (this.options.horizontal == "left") {
                A.left = this.coords.right
            }
        }
        if (this.options.slide) {
            this.fx.container.start(A)
        } else {
            if (this.options.fade) {
                this.fx.container.fireEvent("complete", this, this.options.duration)
            } else {
                this.fx.container.fireEvent("complete")
            }
        }
        this.options.OnHide();
        if (this.options.fade) {
            this.fx.layer.start("opacity", 0)
        } else {
            this.fx.layer.fireEvent("complete")
        }
        if (this.overlay) {
            this.fx.overlay.cancel();
            this.fx.overlay.start("opacity", 0)
        }
    },
    createDropshadow: function() {
        return new Element("div", {
            "class": "ezLayer-upperRight"
        }).wraps(new Element("div", {
            "class": "ezLayer-lowerLeft"
        }).wraps(new Element("div", {
            "class": "ezLayer-shadow"
        }).wraps(new Element("div", {
            "class": "ezLayer-wrapper"
        }).wraps(this.layer))))
    },
    createShadow: function() {
        var A = this.options.shadowSize;
        var B = "";
        if (this.options.shadow == "glow") {
            B = A + "px"
        }
        if (this.options.shadow == "drop") {
            B = "0px " + A + "px " + A + "px 0px"
        }
        var C = new Element("div", {
            "class": "ezLayerShadow"
        }).wraps(new Element("div", {
            "class": "ezLayerWrapper",
            styles: {
                padding: B
            }
        }).wraps(this.layer));
        this.shadow = new canvasBox({
            shadowType: this.options.shadow,
            shadowBlur: A,
            container: C,
            size: this.coords
        });
        return C
    },
    checkDimensions: function() {
        if (this.contentHeight != this.container.getCoordinates().height) {
            this.contentHeight = this.container.getCoordinates().height;
            if (this.frame) {
                this.updateFrameDimensions()
            }
            if (this.shadow) {
                this.shadow.options.size = this.container.getCoordinates();
                this.shadow.resize()
            }
        }
        this.frameTimer = this.checkDimensions.delay(150, this)
    }
});
var datePicker = new Class({
    Implements: [Options, Events],
    getOptions: function() {
        return {
            classname: "calendar",
            format: "yyyy/mm/dd",
            range: null,
            blockedDates: null,
            blockedDays: null,
            toggleClear: true,
            input: null,
            container: null,
            width: 170,
            height: 162,
            headerHeight: 22,
            OnSelect: $empty,
            position: "right"
        }
    },
    initialize: function(A) {
        this.setOptions(this.getOptions(), A);
        this.ref = "calIcon_" + $time();
        this.container = new Element("div", {
            "class": this.options.classname + "Container"
        });
        if (this.options.container) {
            this.container.inject($(this.options.container))
        }
        this.header = new Element("div", {
            "class": this.options.classname + "Header"
        }).inject(this.container);
        this.prevArrow = new Element("span", {
            "class": "left"
        }).inject(this.header);
        this.prevArrow.addEvent("click", this.previous.bind(this));
        this.titleHolder = new Element("span", {
            "class": "title"
        }).inject(this.header);
        this.titleHolder.addEvent("click", this.showPanel.bind(this));
        this.nextArrow = new Element("span", {
            "class": "right"
        }).inject(this.header);
        this.nextArrow.addEvent("click", this.next.bind(this));
        this.headerHeight = this.options.headerHeight;
        this.input = $(this.options.input);
        if (this.input) {
            this.icon = new Element("span", {
                "class": this.options.classname + "Icon",
                id: this.ref,
                html: "&nbsp;"
            }).inject(this.input, "after");
            this.icon.addEvent("click", this.toggle.bind(this, false));
            this.input.set("readOnly", true);
            this.input.addEvent("focus", this.toggle.bind(this, false));
            this.container.setStyle("display", "none").inject(document.body)
        }
        this.today = new Date();
        this.currentDate = this.today.getFirstDay();
        if (this.options.blockedDates) {
            this.options.blockedDates.each(function(C, B) {
                this.options.blockedDates[B] = this.today.parse(C).format("yyyy/mm/dd")
            },
            this)
        }
        if (this.options.range) {
            this.options.range.each(function(C, B) {
                this.options.range[B] = this.today.parse(C)
            },
            this)
        }
        if (this.options.container) {
            this.show()
        }
    },
    createCalendarDates: function(E) {
        E = E.clearTime();
        var B = E.getFirstDay();
        var M = B.getFullMonthName();
        var N = B.getFullYear();
        var D = B.getPreviousDay("mon");
        this.title = M + " " + N;
        this.shownDate = E;
        this.panel = "month";
        var A = new Element("div", {
            "class": this.options.classname
        });
        var O = new Element("table", {
            cellspacing: 1,
            "class": "date"
        }).inject(A);
        var I = new Element("tbody").inject(O);
        var L = new Element("tr").inject(I);
        new Element("th", {
            text: "Mon",
            scope: "col"
        }).inject(L);
        new Element("th", {
            text: "Tue",
            scope: "col"
        }).inject(L);
        new Element("th", {
            text: "Wed",
            scope: "col"
        }).inject(L);
        new Element("th", {
            text: "Thu",
            scope: "col"
        }).inject(L);
        new Element("th", {
            text: "Fri",
            scope: "col"
        }).inject(L);
        new Element("th", {
            text: "Sat",
            scope: "col"
        }).inject(L);
        new Element("th", {
            text: "Sun",
            scope: "col"
        }).inject(L);
        var J = 0;
        var P = 1;
        for (var H = 0; H < 6; H++) {
            var K = new Element("tr", {
                "class": "row" + P
            }).inject(I);
            for (var G = 0; G < 7; G++) {
                var F = "";
                if (D.isBeforeMonth(E)) {
                    F += " past"
                }
                if (D.isAfterMonth(E)) {
                    F += " future"
                }
                if (D.isSame(D.today())) {
                    F += " today"
                }
                if (this.selected) {
                    if (D.isSame(this.selected)) {
                        F += " selected"
                    }
                }
                if (this.options.blockedDates) {
                    if (this.options.blockedDates.contains(D.format("yyyy/mm/dd"))) {
                        F += " blocked"
                    }
                }
                if (this.options.range) {
                    if (D.isBefore(this.options.range[0]) || D.isAfter(this.options.range[1])) {
                        F += " blocked"
                    }
                }
                if (this.options.blockedDays) {
                    if (this.options.blockedDays.contains(D.getShortDayName().toLowerCase())) {
                        F += " blocked"
                    }
                }
                var C = new Element("td", {
                    text: D.getDate(),
                    "class": F
                }).inject(K);
                
                if (F.match(" blocked") == null) {
                    C.addEvent("click", this.selectDate.bind(this, D));
                }
                D = D.addDay()
            }
            P++
        }
        return A
    },
    createCalendarMonths: function(C) {
        C = C.clearTime();
        var J = C.getFullYear();
        this.title = J;
        this.shownDate = C;
        this.panel = "year";
        var A = new Element("div", {
            "class": this.options.classname
        });
        var K = new Element("table", {
            cellspacing: 1,
            "class": "month"
        }).inject(A);
        var G = new Element("tbody").inject(K);
        var H = 0;
        var L = 1;
        for (var F = 0; F < 3; F++) {
            var I = new Element("tr", {
                "class": "row" + L
            }).inject(G);
            for (var E = 0; E < 4; E++) {
                var D = "";
                if (this.selectedMonth) {
                    if (this.selectedYear == C.getFullYear()) {
                        if (this.selectedMonth == H) {
                            D = "selected"
                        }
                    }
                }
                var B = new Element("td", {
                    text: C.shortMonthNames[H].capitalize(),
                    "class": D
                }).inject(I);
                B.addEvent("click", this.selectMonth.bind(this, H));
                H++
            }
            L++
        }
        return A
    },
    createCalendarYears: function(C) {
        C = C.clearTime();
        var K = C.getFullYear() - new Date().getFullYear();
        var G = Math.floor(K / 12);
        startDate = new Date().addYears((G * 12)).addYears( - 2);
        this.title = "Years:";
        this.shownDate = C;
        this.panel = "years";
        var A = new Element("div", {
            "class": this.options.classname
        });
        var L = new Element("table", {
            cellspacing: 1,
            "class": "month"
        }).inject(A);
        var H = new Element("tbody").inject(L);
        var I = 0;
        var M = 1;
        for (var F = 0; F < 3; F++) {
            var J = new Element("tr", {
                "class": "row" + M
            }).inject(H);
            for (var E = 0; E < 4; E++) {
                var D = "";
                if (this.selectedYear) {
                    if (startDate.getFullYear() == this.selectedYear) {
                        D = "selected"
                    }
                }
                var B = new Element("td", {
                    text: startDate.getFullYear(),
                    "class": D
                }).inject(J);
                B.addEvent("click", this.selectYear.bind(this, startDate.getFullYear()));
                startDate = startDate.addYear()
            }
            M++
        }
        return A
    },
    showMonth: function(A) {
        this.month = this.createCalendarDates(A).setStyles({
            position: "absolute",
            top: this.headerHeight,
            left: 0,
            zIndex: 0
        }).inject(this.container);
        this.titleHolder.set("html", this.title)
    },
    showMonths: function(B, A) {
        this.months = this.createCalendarMonths(B).setStyles({
            position: "absolute",
            top: -(this.options.height),
            left: 0,
            zIndex: 2
        }).inject(this.container);
        this.titleHolder.set("html", this.title);
        if (A) {
            new Fx.Tween(this.months, {
                onComplete: function() {
                    this.month.setStyle("display", "none")
                }.bind(this)
            }).start("top", -(this.options.height), this.headerHeight)
        } else {
            this.months.setStyle("top", this.headerHeight)
        }
    },
    showYears: function(A) {
        this.years = this.createCalendarYears(A).setStyles({
            position: "absolute",
            top: -(this.options.height),
            left: 0,
            zIndex: 3
        }).inject(this.container);
        this.titleHolder.set("html", this.title);
        new Fx.Tween(this.years, {
            onComplete: function() {
                this.months.setStyle("display", "none")
            }.bind(this)
        }).start("top", -(this.options.height), this.headerHeight)
    },
    hideMonths: function() {
        this.month.setStyle("display", "block");
        new Fx.Tween(this.months, {
            onComplete: function() {
                this.months.destroy()
            }.bind(this)
        }).start("top", this.headerHeight, -(this.options.height))
    },
    hideYears: function() {
        this.months.setStyle("display", "block");
        new Fx.Tween(this.years, {
            onComplete: function() {
                this.years.destroy()
            }.bind(this)
        }).start("top", this.headerHeight, -(this.options.height))
    },
    toggle: function(A) {
        if (this.showing) {
            this.hide()
        } else {
            this.show(A)
        }
    },
    show: function(A) {
        this.showing = true;
        if (this.months) {
            this.months.destroy()
        }
        if (this.years) {
            this.years.destroy()
        }
        if (!A && this.input) {
            A = this.input.get("value")
        }
        if (A) {
            if ($type(A) == "string") {
                A = new Date().parse(A)
            }
            this.selected = A.clearTime();
            this.selectedMonth = this.selected.getMonth();
            this.selectedYear = this.selected.getFullYear()
        } else {
            A = new Date().today()
        }
        this.currentDate = A.getFirstDay();
        this.showMonth(A);
        if (this.input) {
            layers.show(this.container, {
                control: this.ref,
                fade: true,
                position: this.options.position,
                dropshadow: true,
                closeOnBlur: true,
                OnHide: function() {
                    this.showing = false
                }.bind(this)
            })
        }
    },
    hide: function() {
        this.showing = false;
        if (this.input) {
            layers.hide(this.container)
        }
    },
    next: function() {
        if (this.panel == "month") {
            this.nextMonth()
        }
        if (this.panel == "year") {
            this.nextYear()
        }
        if (this.panel == "years") {
            this.nextYears()
        }
    },
    previous: function() {
        if (this.panel == "month") {
            this.previousMonth()
        }
        if (this.panel == "year") {
            this.previousYear()
        }
        if (this.panel == "years") {
            this.previousYears()
        }
    },
    showPanel: function() {
        if (this.panel == "month") {
            this.showMonths(this.shownDate, true)
        } else {
            if (this.panel == "year") {
                this.showYears(this.shownDate)
            }
        }
    },
    nextMonth: function() {
        this.currentDate = this.currentDate.addMonths(1);
        var A = this.createCalendarDates(this.currentDate).setStyles({
            position: "absolute",
            top: this.headerHeight,
            left: this.options.width,
            zIndex: 0
        }).inject(this.container);
        this.titleHolder.set("html", this.title);
        new Fx.Tween(this.month, {
            onComplete: function() {
                this.month.destroy()
            }.bind(this)
        }).start("left", 0, -(this.options.width));
        new Fx.Tween(A, {
            onComplete: function() {
                this.month = A
            }.delay(600, this)
        }).start("left", this.options.width, 0)
    },
    previousMonth: function() {
        this.currentDate = this.currentDate.addMonths( - 1);
        var A = this.createCalendarDates(this.currentDate).setStyles({
            position: "absolute",
            top: this.headerHeight,
            left: -(this.options.width),
            zIndex: 0
        }).inject(this.container);
        this.titleHolder.set("html", this.title);
        new Fx.Tween(this.month, {
            onComplete: function() {
                this.month.destroy()
            }.bind(this)
        }).start("left", 0, this.options.width);
        new Fx.Tween(A, {
            onComplete: function() {
                this.month = A
            }.delay(600, this)
        }).start("left", -(this.options.width), 0)
    },
    nextYear: function() {
        this.currentDate = this.currentDate.addYears(1);
        var A = this.createCalendarMonths(this.currentDate).setStyles({
            position: "absolute",
            top: this.headerHeight,
            left: this.options.width,
            zIndex: 2
        }).inject(this.container);
        this.titleHolder.set("html", this.title);
        new Fx.Tween(this.months, {
            onComplete: function() {
                this.months.destroy()
            }.bind(this)
        }).start("left", 0, -(this.options.width));
        new Fx.Tween(A, {
            onComplete: function() {
                this.months = A
            }.delay(600, this)
        }).start("left", this.options.width, 0)
    },
    previousYear: function() {
        this.currentDate = this.currentDate.addYears( - 1);
        var A = this.createCalendarMonths(this.currentDate).setStyles({
            position: "absolute",
            top: this.headerHeight,
            left: -(this.options.width),
            zIndex: 2
        }).inject(this.container);
        this.titleHolder.set("html", this.title);
        new Fx.Tween(this.months, {
            onComplete: function() {
                this.months.destroy()
            }.bind(this)
        }).start("left", 0, this.options.width);
        new Fx.Tween(A, {
            onComplete: function() {
                this.months = A
            }.delay(600, this)
        }).start("left", -(this.options.width), 0)
    },
    nextYears: function() {
        this.currentDate = this.currentDate.addYears(12);
        var A = this.createCalendarYears(this.currentDate).setStyles({
            position: "absolute",
            top: this.headerHeight,
            left: this.options.width,
            zIndex: 3
        }).inject(this.container);
        new Fx.Tween(this.years, {
            onComplete: function() {
                this.years.destroy()
            }.bind(this)
        }).start("left", 0, -(this.options.width));
        new Fx.Tween(A, {
            onComplete: function() {
                this.years = A
            }.delay(600, this)
        }).start("left", this.options.width, 0)
    },
    previousYears: function() {
        this.currentDate = this.currentDate.addYears( - 12);
        var A = this.createCalendarYears(this.currentDate).setStyles({
            position: "absolute",
            top: this.headerHeight,
            left: -(this.options.width),
            zIndex: 3
        }).inject(this.container);
        new Fx.Tween(this.years, {
            onComplete: function() {
                this.years.destroy()
            }.bind(this)
        }).start("left", 0, this.options.width);
        new Fx.Tween(A, {
            onComplete: function() {
                this.years = A
            }.delay(600, this)
        }).start("left", -(this.options.width), 0)
    },
    selectDate: function(A) {
        if (this.input) {
            if (this.options.toggleClear) {
                if (this.input.get("value") == A.format(this.options.format)) {
                    this.input.set("value", "");
                    this.selected = null
                } else {
                    this.input.set("value", A.format(this.options.format))
                }
            } else {
                this.input.set("value", A.format(this.options.format))
            }
        }
        this.hide();
        if (this.options.OnSelect) {
            this.options.OnSelect()
        }
    },
    selectMonth: function(A) {
        this.month.destroy();
        this.currentDate.setMonth(A);
        this.selectedMonth = A;
        this.showMonth(this.currentDate);
        this.hideMonths()
    },
    selectYear: function(A) {
        this.months.destroy();
        this.currentDate.setFullYear(A);
        this.selectedMonth = null;
        this.selectedYear = A;
        this.showMonths(this.currentDate);
        this.hideYears()
    }
});
Date.implement({
    parse: function(E) {
        var C = new Date(E);
        var D = false;
        this.dateFormats.each(function(F) {
            if (E == C.format(F)) {
                D = true
            }
        });
        if (!D) {
            var B = "";
            if (E.contains("/")) {
                B = "/"
            }
            if (E.contains("-")) {
                B = "-"
            }
            var A = E.split(B);
            if (A[0].length == 4) {
                return new Date(A[0] + "/" + A[1] + "/" + A[2])
            } else {
                if (A[2].length == 2) {
                    A[2] = "20" + A[2]
                }
                return new Date(A[2] + "/" + A[1] + "/" + A[0])
            }
        } else {
            return C
        }
    },
    format: function(B) {
        var A = this.getDate().toString();
        var C = (this.getMonth() + 1).toString();
        var E = this.getFullYear().toString();
        var D = E.substr(2);
        if (A.length == 1) {
            A = "0" + A
        }
        if (C.length == 1) {
            C = "0" + C
        }
        B = B.replace("dd", A);
        B = B.replace("mm", C);
        B = B.replace("yyyy", E);
        B = B.replace("yy", D);
        return B
    },
    today: function() {
        return new Date().clearTime()
    },
    getFirstDay: function() {
        return new Date(this.getFullYear() + "/" + (this.getMonth() + 1) + "/1")
    },
    clone: function() {
        return new Date(this)
    },
    addDay: function() {
        return this.addDays(1)
    },
    addDays: function(A) {
        if (!A) {
            A = 0
        }
        return new Date(this.getFullYear() + "/" + (this.getMonth() + 1) + "/" + (this.getDate() + A))
    },
    addMonth: function() {
        return this.addMonths(1)
    },
    addMonths: function(A) {
        if (!A) {
            A = 0
        }
        return new Date(this.getFullYear() + "/" + (this.getMonth() + 1 + A) + "/" + this.getDate())
    },
    addYear: function() {
        return this.addYears(1)
    },
    addYears: function(A) {
        if (!A) {
            A = 0
        }
        return new Date((this.getFullYear() + A) + "/" + (this.getMonth() + 1) + "/" + this.getDate())
    },
    isBeforeMonth: function(A) {
        if (this.getFirstDay() < A.getFirstDay()) {
            return true
        } else {
            return false
        }
    },
    isAfterMonth: function(A) {
        if (this.getFirstDay() > A.getFirstDay()) {
            return true
        } else {
            return false
        }
    },
    isBefore: function(A) {
        if (this.getTime() < A.getTime()) {
            return true
        } else {
            return false
        }
    },
    isAfter: function(A) {
        if (this.getTime() > A.getTime()) {
            return true
        } else {
            return false
        }
    },
    isSame: function(A) {
        if (this.getTime() == A.getTime()) {
            return true
        } else {
            return false
        }
    },
    getPreviousDay: function(A) {
        if (A) {
            A = this.getDayFromName(A);
            var B = this;
            if (B.getDay() != A) {
                do {
                    B = B.addDays( - 1)
                }
                while (B.getDay() != A)
            }
            return B
        } else {
            return this.addDays( - 1)
        }
    },
    getDayFromName: function(A) {
        A = A.toLowerCase();
        if (this.fullDayNames.contains(A)) {
            return this.fullDayNames.indexOf(A)
        }
        if (this.shortDayNames.contains(A)) {
            return this.shortDayNames.indexOf(A)
        }
    },
    getFullDayName: function() {
        return this.fullDayNames[this.getDay()].capitalize()
    },
    getShortDayName: function() {
        return this.shortDayNames[this.getDay()].capitalize()
    },
    getFullMonthName: function() {
        return this.fullMonthNames[this.getMonth()].capitalize()
    },
    getShortMonthName: function() {
        return this.shortMonthNames[this.getMonth()].capitalize()
    },
    clearTime: function() {
        return new Date(this.getFullYear() + "/" + (this.getMonth() + 1) + "/" + this.getDate())
    },
    fullDayNames: ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"],
    shortDayNames: ["sun", "mon", "tue", "wed", "thu", "fri", "sat"],
    fullMonthNames: ["january", "febuary", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"],
    shortMonthNames: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"],
    dateFormats: ["dd/mm/yyyy", "dd/mm/yy", "yyyy/mm/dd", "dd-mm-yyyy", "dd-mm-yy", "yyyy-mm-dd"]
});
