//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

MooTools.More = { version: "1.2.4.4", build: "6f6057dc645fdb7547689183b2311063bd653ddf" }; Class.Mutators.Binds = function (a) { return a; }; Class.Mutators.initialize = function (a) {
    return function () {
        $splat(this.Binds).each(function (b) {
            var c = this[b];
            if (c) { this[b] = c.bind(this); } 
        }, this); return a.apply(this, arguments);
    };
}; Fx.Scroll = new Class({ Extends: Fx, options: { offset: { x: 0, y: 0 }, wheelStops: true }, initialize: function (b, a) {
    this.element = this.subject = document.id(b);
    this.parent(a); var d = this.cancel.bind(this, false); if ($type(this.element) != "element") { this.element = document.id(this.element.getDocument().body); } var c = this.element;
    if (this.options.wheelStops) {
        this.addEvent("start", function () { c.addEvent("mousewheel", d); }, true); this.addEvent("complete", function () {
            c.removeEvent("mousewheel", d);
        }, true);
    } 
}, set: function () {
    var a = Array.flatten(arguments); if (Browser.Engine.gecko) { a = [Math.round(a[0]), Math.round(a[1])]; } this.element.scrollTo(a[0], a[1]);
}, compute: function (c, b, a) { return [0, 1].map(function (d) { return Fx.compute(c[d], b[d], a); }); }, start: function (c, g) {
    if (!this.check(c, g)) { return this; } var e = this.element.getScrollSize(), b = this.element.getScroll(), d = { x: c, y: g };
    for (var f in d) { var a = e[f]; if ($chk(d[f])) { d[f] = ($type(d[f]) == "number") ? d[f] : a; } else { d[f] = b[f]; } d[f] += this.options.offset[f]; } return this.parent([b.x, b.y], [d.x, d.y]);
}, toTop: function () { return this.start(false, 0); }, toLeft: function () { return this.start(0, false); }, toRight: function () { return this.start("right", false); }, toBottom: function () {
    return this.start(false, "bottom");
}, toElement: function (b) { var a = document.id(b).getPosition(this.element); return this.start(a.x, a.y); }, scrollIntoView: function (c, e, d) {
    e = e ? $splat(e) : ["x", "y"];
    var h = {}; c = document.id(c); var f = c.getPosition(this.element); var i = c.getSize(); var g = this.element.getScroll(); var a = this.element.getSize(); var b = { x: f.x + i.x, y: f.y + i.y };
    ["x", "y"].each(function (j) {
        if (e.contains(j)) { if (b[j] > g[j] + a[j]) { h[j] = b[j] - a[j]; } if (f[j] < g[j]) { h[j] = f[j]; } } if (h[j] == null) { h[j] = g[j]; } if (d && d[j]) {
            h[j] = h[j] + d[j];
        } 
    }, this); if (h.x != g.x || h.y != g.y) { this.start(h.x, h.y); } return this;
}, scrollToCenter: function (c, e, d) {
    e = e ? $splat(e) : ["x", "y"]; c = $(c); var h = {}, f = c.getPosition(this.element), i = c.getSize(), g = this.element.getScroll(), a = this.element.getSize(), b = { x: f.x + i.x, y: f.y + i.y };
    ["x", "y"].each(function (j) { if (e.contains(j)) { h[j] = f[j] - (a[j] - i[j]) / 2; } if (h[j] == null) { h[j] = g[j]; } if (d && d[j]) { h[j] = h[j] + d[j]; } }, this); if (h.x != g.x || h.y != g.y) {
        this.start(h.x, h.y);
    } return this;
} 
}); var Scroller = new Class({ Implements: [Events, Options], options: { area: 20, velocity: 1, onChange: function (a, b) { this.element.scrollTo(a, b); }, fps: 50 }, initialize: function (b, a) {
    this.setOptions(a);
    this.element = document.id(b); this.docBody = document.id(this.element.getDocument().body); this.listener = ($type(this.element) != "element") ? this.docBody : this.element;
    this.timer = null; this.bound = { attach: this.attach.bind(this), detach: this.detach.bind(this), getCoords: this.getCoords.bind(this) };
}, start: function () {
    this.listener.addEvents({ mouseover: this.bound.attach, mouseout: this.bound.detach });
}, stop: function () { this.listener.removeEvents({ mouseover: this.bound.attach, mouseout: this.bound.detach }); this.detach(); this.timer = $clear(this.timer); }, attach: function () {
    this.listener.addEvent("mousemove", this.bound.getCoords);
}, detach: function () { this.listener.removeEvent("mousemove", this.bound.getCoords); this.timer = $clear(this.timer); }, getCoords: function (a) {
    this.page = (this.listener.get("tag") == "body") ? a.client : a.page;
    if (!this.timer) { this.timer = this.scroll.periodical(Math.round(1000 / this.options.fps), this); } 
}, scroll: function () {
    var b = this.element.getSize(), a = this.element.getScroll(), f = this.element != this.docBody ? this.element.getOffsets() : { x: 0, y: 0 }, c = this.element.getScrollSize(), e = { x: 0, y: 0 };
    for (var d in this.page) {
        if (this.page[d] < (this.options.area + f[d]) && a[d] != 0) { e[d] = (this.page[d] - this.options.area - f[d]) * this.options.velocity; } else {
            if (this.page[d] + this.options.area > (b[d] + f[d]) && a[d] + b[d] != c[d]) {
                e[d] = (this.page[d] - b[d] + this.options.area - f[d]) * this.options.velocity;
            } 
        } 
    } if (e.y || e.x) { this.fireEvent("change", [a.x + e.x, a.y + e.y]); } 
} 
}); (function () {
    var a = function (c, b) { return (c) ? ($type(c) == "function" ? c(b) : b.get(c)) : ""; }; this.Tips = new Class({ Implements: [Events, Options], options: { onShow: function () {
        this.tip.setStyle("display", "block");
    }, onHide: function () { this.tip.setStyle("display", "none"); }, title: "title", text: function (b) { return b.get("rel") || b.get("href"); }, showDelay: 100, hideDelay: 100, className: "tip-wrap", offset: { x: 16, y: 16 }, windowPadding: { x: 0, y: 0 }, fixed: false
    }, initialize: function () {
        var b = Array.link(arguments, { options: Object.type, elements: $defined });
        this.setOptions(b.options); if (b.elements) { this.attach(b.elements); } this.container = new Element("div", { "class": "tip" });
    }, toElement: function () {
        if (this.tip) {
            return this.tip;
        } return this.tip = new Element("div", { "class": this.options.className, styles: { position: "absolute", top: 0, left: 0} }).adopt(new Element("div", { "class": "tip-top" }), this.container, new Element("div", { "class": "tip-bottom" })).inject(document.body);
    }, attach: function (b) {
        $$(b).each(function (d) {
            var f = a(this.options.title, d), e = a(this.options.text, d); d.erase("title").store("tip:native", f).retrieve("tip:title", f);
            d.retrieve("tip:text", e); this.fireEvent("attach", [d]); var c = ["enter", "leave"]; if (!this.options.fixed) { c.push("move"); } c.each(function (h) {
                var g = d.retrieve("tip:" + h);
                if (!g) { g = this["element" + h.capitalize()].bindWithEvent(this, d); } d.store("tip:" + h, g).addEvent("mouse" + h, g);
            }, this);
        }, this); return this;
    }, detach: function (b) {
        $$(b).each(function (d) {
            ["enter", "leave", "move"].each(function (e) {
                d.removeEvent("mouse" + e, d.retrieve("tip:" + e)).eliminate("tip:" + e);
            }); this.fireEvent("detach", [d]); if (this.options.title == "title") { var c = d.retrieve("tip:native"); if (c) { d.set("title", c); } } 
        }, this); return this;
    }, elementEnter: function (c, b) {
        this.container.empty();
        ["title", "text"].each(function (e) { var d = b.retrieve("tip:" + e); if (d) { this.fill(new Element("div", { "class": "tip-" + e }).inject(this.container), d); } }, this); $clear(this.timer);
        this.timer = (function () { this.show(this, b); this.position((this.options.fixed) ? { page: b.getPosition()} : c); }).delay(this.options.showDelay, this);
    }, elementLeave: function (c, b) {
        $clear(this.timer);
        this.timer = this.hide.delay(this.options.hideDelay, this, b); this.fireForParent(c, b);
    }, fireForParent: function (c, b) {
        b = b.getParent(); if (!b || b == document.body) {
            return;
        } if (b.retrieve("tip:enter")) { b.fireEvent("mouseenter", c); } else { this.fireForParent(c, b); } 
    }, elementMove: function (c, b) { this.position(c); }, position: function (e) {
        if (!this.tip) {
            document.id(this);
        } var c = window.getSize(), b = window.getScroll(), f = { x: this.tip.offsetWidth, y: this.tip.offsetHeight }, d = { x: "left", y: "top" }, g = {}; for (var h in d) {
            g[d[h]] = e.page[h] + this.options.offset[h];
            if ((g[d[h]] + f[h] - b[h]) > c[h] - this.options.windowPadding[h]) { g[d[h]] = e.page[h] - this.options.offset[h] - f[h]; } 
        } this.tip.setStyles(g);
    }, fill: function (b, c) {
        if (typeof c == "string") {
            b.set("html", c);
        } else { b.adopt(c); } 
    }, show: function (b) { if (!this.tip) { document.id(this); } this.fireEvent("show", [this.tip, b]); }, hide: function (b) {
        if (!this.tip) {
            document.id(this);
        } this.fireEvent("hide", [this.tip, b]);
    } 
    });
})();
