if (typeof(console) == "undefined") {
    console = {
        log: function () {},
        profile: function () {},
        profileEnd: function () {}
    }
}
function strip_comments(a) {
    return a.replace(/\/\/.*/g, "").replace(/\/\*[\s\S]*?\*\//g, "")
}
function fn_body(b) {
    var a = strip_comments(b.toString());
    a = a.replace(/[\s]+/g, " ");
    if (a.startsWith("(")) {
        a = a.substr(1)
    }
    if (a.endsWith(")")) {
        a = a.substr(0, a.length - 1)
    }
    a = a.replace("function (", "function(");
    return a
}
function get_stack_rep() {
    var d = [];
    var a = {};
    var c = arguments.callee.caller;
    while (c) {
        if (c.__tb_ajax_info__) {
            d.unshift("Ajax.DBRequest: " + c.__tb_ajax_info__);
            break
        }
        if (c.__tb__) {
            d = c.__tb__.concat(d);
            break
        }
        var b = fn_body(c);
        if (b in a) {
            break
        }
        a[b] = true;
        d.unshift(b);
        c = c.caller
    }
    return d
}
function assert(c, d, b) {
    if (!c) {
        d = "Assertion Error: " + d;
        if (!Constants.IS_PROD) {
            alert(d)
        }
        var a = get_stack_rep();
        a.pop();
        global_report_exception(d, window.location.href, "", a.join("\n"), true);
        throw d
    }
}
Function.prototype.defer = Function.prototype.defer.wrap(function (b) {
    var a = $A(arguments).slice(1);
    this.__tb__ = get_stack_rep();
    b.apply(this, a)
});
String.prototype.evalScripts = String.prototype.evalScripts.wrap(function (b) {
    var a = $A(arguments).slice(1);
    try {
        b.apply(this, a)
    } catch (c) {
        assert(0, c.toString())
    }
});

function add_i18n_message(d, c, a, b) {
    Constants.messages = Constants.messages || {};
    Constants.emessages = Constants.emessages || {};
    c = c.stripTags().friendly_format();
    a = a.stripTags();
    Constants.messages[c] = d;
    Constants.emessages[c] = a;
    if (b) {
        delete Constants.messages[b];
        delete Constants.emessages[b]
    }
    if (TranslationSuggest) {
        TranslationSuggest.index_message(c)
    }
}
function singular_1(a) {
    return a == 1 ? 0 : 1
}
function singular_01(a) {
    return a <= 1 ? 0 : 1
}
function singular_all(a) {
    return 0
}
var PLURAL_RULES = {
    es_US: singular_1,
    de: singular_1,
    es: singular_1,
    fr: singular_01,
    ja: singular_all,
    pl: singular_1
};
Date.prototype.localize = function () {
    assert(Constants.date_format, "Date format missing.");
    return this.format(Constants.date_format)
};
Date.prototype.format = function (b) {
    assert(b, "Missing format string");
    assert(typeof(b) == "string", "Date format requires a format string");
    var c = {
        yy: function (d) {
            return d.getFullYear().toString().substring(2)
        },
        yyyy: function (d) {
            return d.getFullYear().toString()
        },
        d: function (d) {
            return d.getDate().toString()
        },
        dd: function (d) {
            return d.getDate().toString().lpad(2)
        },
        M: function (d) {
            return (d.getMonth() + 1).toString()
        },
        MM: function (d) {
            return (d.getMonth() + 1).toString().lpad(2)
        }
    };
    var a = b.replace(/([a-zA-Z]+)/g, (function (d) {
        return (c[d] && c[d](this)) || d
    }).bind(this));
    return a
};
String.prototype.format_sub = function (a) {
    return this.replace(/%(\([a-z_\-]+\))?(.\d+)?(.)/g, a.bind(this))
};
String.prototype.format = function string_format() {
    if (arguments.length === 0) {
        return this.toString()
    }
    var g;
    var f = 0;
    if (arguments.length == 1 && arguments[0] instanceof Object) {
        g = arguments[0]
    } else {
        g = $A(arguments)
    }
    function b(l, j, i, k) {
        var h;
        if (!j) {
            if (!Object.isArray(g)) {
                g = [g]
            }
            assert(f > -1, "Cannot mix named and positional indices in string formatting for string '" + this + "'.");
            assert(f < g.length, "Insufficient number of items in format for string '" + this + "', list " + $A(g).toJSON() + ".");
            h = g[f];
            f++
        } else {
            j = j.slice(1, -1);
            assert(f <= 0, "Cannot mix named and positional indices in string formatting for string '" + this + "'.");
            f = -1;
            assert(j in g, "Key '" + j + "' not present during string substitution for string '" + this + "', dict " + $H(g).toJSON() + ".");
            h = g[j]
        }
        assert(typeof(h) != "undefined", 'value for key "' + (j || "").toString() + '" is undefined');
        var d;
        if (k == "s") {
            d = h.toString()
        } else {
            if (k == "d") {
                d = parseInt(h, 10).toString()
            } else {
                if (k == "f") {
                    d = Number(h).toString()
                } else {
                    if (k == "%") {
                        return "%"
                    } else {
                        assert(false, "Unexpected format character '" + k + "' for string '" + this + "'.")
                    }
                }
            }
        }
        if (i) {
            i = parseInt(i.slice(1), 10);
            if (k == "f") {
                if (d.indexOf(".") == "-1") {
                    d = d + ".0"
                }
                var m = d.split(".");
                return m[0] + "." + m[1].slice(0, i)
            } else {
                return d.slice(0, i)
            }
        }
        return d
    }
    var a = this.format_sub(b);
    if (this in Constants.messages) {
        f = 0;
        var e = Constants.emessages[this];
        var c = String.prototype.format_sub.call(e, b);
        add_i18n_message(e, a, c, this)
    }
    return a
};
String.prototype.friendly_format = function () {
    var a = 1;
    var b = 1;

    function c(g, e, d, f) {
        if (!e) {
            if (f == "s") {
                return "[word" + (b++) + "]"
            } else {
                return "[number" + (a++) + "]"
            }
        } else {
            return "[" + e.slice(1, -1).replace("-", "_") + "]"
        }
    }
    return this.format_sub(c)
};
String.prototype.blank_format = function () {
    function a() {
        return ""
    }
    return this.format_sub(a)
};
if (!window.LANGPACK) {
    var LANGPACK = {}
}
function _(a) {
    var b = LANGPACK[a] || a;
    add_i18n_message(a, b, a);
    return b
}
function N_(a) {
    return a
}
function ungettext(c, b, g) {
    assert(typeof(g) != "undefined", "missing number parameter for ungettext");
    var a;
    if (c in LANGPACK) {
        if (Constants.USER_LOCALE) {
            var d = LANGPACK[c];
            var f = PLURAL_RULES[Constants.USER_LOCALE](g);
            assert(f in d, "bad plural lookup");
            a = d[f]
        }
    }
    var e = g == 1 ? c : b;
    a = a || e;
    add_i18n_message(c, a, e);
    return a
}
function localized_path(d, b) {
    if (!b) {
        b = [];
        for (var a = 0; a < Constants.LOCALES.length; a++) {
            var c = Constants.LOCALES[a];
            b.push(c[0])
        }
    }
    if (b.indexOf(Constants.USER_LOCALE) != -1) {
        return d.replace(/(\.[a-zA-Z0-9]{2,4})$/, "__%s$1".format(Constants.USER_LOCALE))
    } else {
        return d
    }
}
document.observe("dom:loaded", function () {
    var c = document.body.style;
    if (c.WebkitBoxShadow !== undefined || c.MozBoxShadow !== undefined || c.BoxShadow !== undefined || c.boxShadow !== undefined) {
        $(document.body).addClassName("has_box_shadow")
    }
    if (c.WebkitBorderRadius !== undefined || c.MozBorderRadius !== undefined || c.BorderRadius !== undefined || c.borderRadius !== undefined) {
        $(document.body).addClassName("has_border_radius")
    }
    var g = new Element("a");
    var d = "#ffffff";
    g.style.color = d;
    try {
        g.style.color = "rgba(1,1,1,0.5)"
    } catch (f) {}
    if (g.style.color != d) {
        $(document.body).addClassName("has_rgba")
    }
    var b = Prototype.Browser.WebKit || Prototype.Browser.Opera;
    if (b) {
        $(document.body).addClassName("has_font_face")
    }
    for (var a in Prototype.Browser) {
        if (Prototype.Browser[a]) {
            $(document.body).addClassName(a.toLowerCase())
        }
    }
});
Function.prototype.stop_calls_at = function (a) {
    var b = this;
    return function () {
        if (a-- > 0) {
            return b.apply(this, arguments)
        }
    }
};
Array.prototype.sort_by_key = function (a, b) {
    if (!b) {
        b = -1
    }
    return this.sort(function (c, d) {
        c = a(c);
        d = a(d);
        if (c < d) {
            return b * -1
        } else {
            if (c > d) {
                return b * 1
            } else {
                return 0
            }
        }
    })
};
Array.prototype.contains = function (a) {
    return this.indexOf(a) != -1
};
var WIT = {
    enabled: Constants.WIT_ENABLED,
    reporting: false,
    start_time: 0,
    register: function () {
        if (WIT.enabled) {
            WIT.reportInterval = setInterval(WIT.report, 10000);
            $(document.body).observe("click", WIT.click)
        }
    },
    add_group: function (b, a) {
        b = $(b);
        assert(b, "WIT.add_group missing elm");
        b.addClassName("wit_group");
        b.setAttribute("name", a)
    },
    clear_group: function (a) {
        if (a.hasClassName("wit_group")) {
            a.removeClassName("wit_group")
        }
    },
    get_group: function (b) {
        var a = b.up(".wit_group");
        if (a) {
            return a.getAttribute("name")
        }
        return "ALL"
    },
    time_elapsed: function () {
        var a = Util.time() - WIT.start_time;
        if (a < 0) {
            a = 0
        }
        return a
    },
    click: function (f) {
        if (!WIT.enabled || !f || !f.target) {
            return
        }
        var d = $(f.target);
        var c;
        if (["input", "textarea", "checkbox"].indexOf(d.tagName.toLowerCase()) > -1) {
            c = d
        }
        if (!c) {
            Util.resolve_target(d, "a, .wit")
        }
        if (!c || $(c).hasClassName("ignore")) {
            return
        }
        var a = c.getAttribute("name") || c.id || (c.getValue && c.getValue()) || c.innerHTML.stripTags().strip() || "unknown " + c.tagName;
        if (Constants.emessages[a]) {
            a = Constants.emessages[a]
        }
        var b = WIT.get_group(c);
        assert(b, "Group missing");
        WIT.record_action(a, "click", b, WIT.time_elapsed())
    },
    record_action: function (c, d, e, b, a) {
        a = a || {};
        a.group = e;
        a.type = d;
        a.tti = b;
        WIT.record("ACTION", c, a)
    },
    record: function (c, b, a) {
        a = a || {};
        WIT._record(c, b, window.location.pathname.split("#")[0], a)
    },
    _record: function (f, c, b, a) {
        var d = "WIT_" + f + "_" + c;
        if (!WIT.enabled || Jcached.get(d) || WIT.IGNORE_URLS[b.split(Constants.WEBSERVER).last().split(/[\?\#]/)[0]]) {
            return
        }
        assert(c, "Missing WIT label");
        assert(f, "Missing WIT event_type");
        assert(b, "Missing WIT url");
        var e = [f, c, b, a || {}];
        WIT.add_to_cookie(e);
        Jcached.set(d, 1, 5000)
    },
    add_to_cookie: function (d) {
        if (Ajax.activeRequestCount) {
            setTimeout(function () {
                WIT.add_to_cookie(d)
            }, 500);
            return
        }
        assert(WIT.enabled, "WIT Disabled.");
        var c = WIT.get_cookie_val();
        c.push(d);
        var a = Object.toJSON(c);
        var b = encodeURIComponent(a);
        Util.create_cookie("wit", b, 365);
        if (b.length > 1024) {
            WIT.report()
        }
    },
    get_cookie_val: function () {
        var c = Util.read_cookie("wit");
        var b;
        if (c) {
            try {
                b = decodeURIComponent(c).evalJSON()
            } catch (a) {
                b = []
            }
        } else {
            b = []
        }
        return b
    },
    IGNORE_URLS: {
        "/wit": true
    },
    report: function () {
        if (!WIT.enabled || WIT.reporting) {
            return
        }
        var b = Util.read_cookie("wit");
        if (b) {
            WIT.reporting = true;
            var a = new Ajax.Request("/wit", {
                onComplete: function () {
                    WIT.reporting = false
                }
            });
            Util.create_cookie("wit", "", -1)
        }
    }
};
WIT.start_time = window.ST || new Date().getTime();
document.observe("dom:loaded", function () {
    WIT.record("LOAD", "ready", {
        time: Util.time() - WIT.start_time
    });
    WIT.register()
});
Event.observe(window, "load", function () {
    WIT.record("LOAD", "complete", {
        time: Util.time() - WIT.start_time
    })
});
Event.stop = Event.stop.wrap(function (a, b) {
    if (b) {
        if (b.type == "click") {
            WIT.click(b)
        }
        a.apply(this, $A(arguments).slice(1))
    }
});
var Jcached = {
    cache: {},
    set: function (b, d, a) {
        var e = Jcached.cache[b];
        if (!e) {
            Jcached.cache[b] = {};
            e = Jcached.cache[b]
        }
        e.value = d;
        e.expires = a ? (new Date()).getTime() + a : 0
    },
    get: function (a) {
        var b = Jcached.cache[a];
        if (!b || (b.expires && (new Date()).getTime() > b.expires)) {
            delete Jcached.cache[a];
            return false
        }
        return b.value
    }
};
Function.prototype.cached = function (a) {
    var b = Math.random();
    var c = this;
    return function () {
        var d = Jcached.get(b);
        if (d !== false) {
            return d
        }
        d = c();
        Jcached.set(b, d, a);
        return d
    }
};

function zip() {
    var c = [];
    var f = arguments.length;
    var h;
    for (var a = 0; a < f; a += 1) {
        var e = arguments[a].length;
        assert(arguments[a] instanceof Array, "zip only takes arrays as args");
        if (!h || e < h) {
            h = e
        }
    }
    for (var d = 0; d < h; d += 1) {
        var g = [];
        for (var b = 0; b < f; b += 1) {
            g.push(arguments[b][d])
        }
        c.push(g)
    }
    return c
}
var Util = {
    one_line_fit: function (a) {
        var c = $$(a);
        if (c.length < 2) {
            return
        }
        var b = function () {
            var d = false;
            var j = c[0];
            var h = c[c.length - 1];
            var f = j.cumulativeOffset().top,
                e = h.cumulativeOffset().top;
            if (f != e) {
                var g = parseInt(j.getStyle("font-size"), 10);
                var i = g - 1;
                if (i < 8) {
                    return
                }
                c.each(function (k) {
                    k.style.fontSize = i + "px"
                });
                b()
            }
        };
        b()
    },
    timedelta: function (b, g) {
        var d = b.getTime() - g.getTime();
        var a = 86400000,
            c = 1000;
        var f = parseInt(d / a, 10);
        d = d % a;
        var e = parseInt(d / c, 10);
        d = d % c;
        return {
            microseconds: parseInt(d, 10),
            seconds: e,
            days: f
        }
    },
    ago: function (b, c) {
        var f = new Date();
        var e = Util.timedelta(f, b);
        var a;
        if (e.days < 2) {
            var d = e.seconds + e.days * 86400;
            if (d < 60) {
                a = d;
                if (c) {
                    return ungettext("%d second", "%d seconds", a).format(a)
                } else {
                    return ungettext("%d sec", "%d secs", a).format(a)
                }
            } else {
                if (d < 3600) {
                    a = parseInt(d / 60, 10);
                    if (c) {
                        return ungettext("%d minute", "%d minutes", a).format(a)
                    } else {
                        return ungettext("%d min", "%d mins", a).format(a)
                    }
                } else {
                    a = parseInt(d / 3600, 10);
                    if (c) {
                        return ungettext("%d hour", "%d hours", a).format(a)
                    } else {
                        return ungettext("%d hr", "%d hrs", a).format(a)
                    }
                }
            }
        } else {
            var g = parseInt(e.days + Math.round(e.seconds / 86400), 10);
            if (g < 30) {
                return ungettext("%d day", "%d days", g).format(g)
            } else {
                if (g < 56) {
                    a = parseInt(g / 7, 10);
                    return ungettext("%d week", "%d weeks", a).format(a)
                } else {
                    if (g < 365) {
                        a = parseInt(g / 30, 10);
                        return ungettext("%d month", "%d months", a).format(a)
                    } else {
                        a = parseInt(g / 365, 10);
                        return ungettext("%d year", "%d years", a).format(a)
                    }
                }
            }
        }
    },
    nice_list: function (b) {
        if (!b) {
            return ""
        } else {
            if (b.length == 1) {
                return b[0]
            } else {
                if (b.length == 2) {
                    return _(Constants.TWO_ITEM_LIST).format({
                        x: b[0],
                        y: b[1]
                    })
                }
            }
        }
        var c = _(Constants.THREE_ITEM_LIST).split(/%\(x\)s|%\(y\)s|%\(z\)s/);
        assert(c.length == 4, "bad item list format " + Constants.THREE_ITEM_LIST);
        var e = c[0],
            d = c[1],
            a = c[2],
            f = c[3];
        return [e, b.slice(0, -1).join(d), a, b[b.length - 1], f].join("")
    },
    months: [_("January"), _("February"), _("March"), _("April"), _("May"), _("June"), _("July"), _("August"), _("September"), _("October"), _("November"), _("December")],
    center: function (b) {
        b = $(b);
        var a = (document.viewport.getWidth() - b.getWidth()) / 2;
        b.setStyle({
            left: Math.floor(a) + "px"
        })
    },
    pinTop: function (c, a) {
        c = $(c);
        if (a) {
            c.setStyle({
                top: window.pageYOffset + "px"
            })
        } else {
            var b = new Effect.Move(c, {
                y: window.pageYOffset,
                mode: "absolute",
                duration: 0.25
            })
        }
    },
    getTickWaiter: function (c, b) {
        var a = 0;
        return function () {
            if (a == c) {
                b()
            }
            a++
        }
    },
    calcBox: function (e, b, c, a, d) {
        d.top = Math.min(e, c);
        d.left = Math.min(b, a);
        d.width = Math.abs(b - a);
        d.height = Math.abs(e - c)
    },
    initBox: function (c, b, a) {
        a.top = c;
        a.left = b;
        a.width = 0;
        a.height = 0
    },
    pointOnBox: function (c, b, a) {
        return (b >= a.top && b <= a.top + a.height && c >= a.left && c <= a.left + a.width)
    },
    cmpBox: function (c, b, a) {
        if (b < a.top || c < a.left) {
            return -1
        }
        if (b > a.top + a.height || c > a.left + a.width) {
            return 1
        }
        return 0
    },
    boxOnBox: function (c, b) {
        var e = Math.max(c.top, b.top);
        var a = Math.max(c.left, b.left);
        var d = Math.min(c.top + c.height, b.top + b.height);
        var f = Math.min(c.left + c.width, b.left + b.width);
        return (e < d && a < f)
    },
    reduceBox: function (b, c) {
        var a = {};
        a.width = b.width * c;
        a.height = b.height * c;
        a.top = b.top + (b.height - a.height) / 2;
        a.left = b.left + (b.width - a.width) / 2;
        return a
    },
    getBox: function (c) {
        c = $(c);
        var b = c.getDimensions();
        var a = c.viewportOffset();
        return {
            top: a.top,
            left: a.left,
            width: b.width,
            height: b.height
        }
    },
    ts: function () {
        var a = new Date();
        return a.getUTCFullYear().toString() + "-" + (a.getUTCMonth() + 1).toString().lpad(2) + "-" + a.getUTCDate().toString().lpad(2) + " " + a.getUTCHours().toString().lpad(2) + ":" + a.getUTCMinutes().toString().lpad(2) + ":" + a.getUTCSeconds().toString().lpad(2)
    },
    start_of_day: function (a) {
        var b = new Date();
        b.setTime(a.getTime());
        b.setHours(0);
        b.setMinutes(0);
        b.setSeconds(0);
        b.setMilliseconds(0);
        return b
    },
    to_mysql_date: function (e, a) {
        var b = e.getFullYear().toString() + "-" + (e.getMonth() + 1).toString().lpad(2) + "-" + e.getDate().toString().lpad(2);
        var c = e.getHours().toString().lpad(2) + ":" + e.getMinutes().toString().lpad(2) + ":" + e.getSeconds().toString().lpad(2) + "." + e.getMilliseconds().toString().lpad(3);
        if (!a) {
            return b
        } else {
            return b + " " + c
        }
    },
    from_mysql_date: function (b) {
        var h = b.split(" ");
        var d = h[0];
        var g = h.length > 1 ? h[1] : false;
        var f = d.split("-");
        assert(f.length == 3, "weird date format on {d}, expected yyyy-mm-dd".interpolate({
            d: d
        }));
        var c = new Date(f[0], parseInt(f[1], 10) - 1, f[2]);
        if (g) {
            var e = g.split(":");
            assert(e.length == 3, "weird time format on {t}, expected hh:mm:ss.ms".interpolate({
                t: g
            }));
            c.setHours(e[0]);
            c.setMinutes(e[1]);
            var a = e[2].split(".");
            c.setSeconds(a[0]);
            if (a.length > 1) {
                c.setMilliseconds(a[1])
            }
        }
        return c
    },
    make_table: function (h, b) {
        var d = new Element("table", b);
        var a = new Element("tbody");
        d.insert(a);
        for (var c in h) {
            var e = new Element("tr");
            var g = new Element("td").insert(c);
            var f = new Element("td").insert(h[c]);
            e.insert(g);
            e.insert(f);
            a.insert(e)
        }
        return d
    },
    time: function () {
        return (new Date()).getTime()
    },
    last_time: false,
    delta: function (b) {
        var a = Util.time();
        if (Util.last_time && (!b || typeof(b) != "boolean")) {
            Util.log(a - Util.last_time)
        }
        Util.last_time = a;
        if (typeof(b) == "string") {
            Util.log("^ " + b)
        }
    },
    toggle_names: {},
    toggle: function (a) {
        if (Util.toggle_names[a]) {
            Util.toggle_names[a] = false
        } else {
            Util.toggle_names[a] = true
        }
        return Util.toggle_names[a]
    },
    reset_toggle: function (a) {
        Util.set_toggle(a, false)
    },
    set_toggle: function (a, b) {
        Util.toggle_names[a] = b
    },
    set_next_toggle: function (a, b) {
        Util.toggle_names[a] = !b
    },
    url_hash: function () {
        var a = window.location.href;
        if (a.indexOf("#") >= 0) {
            return a.split("#").last()
        } else {
            return ""
        }
    },
    copy_to_clipboard: function (h, d, g) {
        var a = $("hold_clipboard");
        a.value = h;
        if (a.createTextRange) {
            var b = a.createTextRange();
            if (b && (typeof(BodyLoaded) == "undefined" || BodyLoaded == 1)) {
                try {
                    b.execCommand("Copy")
                } catch (f) {
                    g = g || _("Please copy the text below:");
                    d = d || _("Copy text");
                    DomUtil.fillVal(h, "text-to-copy");
                    DomUtil.fillVal(g, "copy-modal-body");
                    Modal.show(d, DomUtil.fromElm("copy-modal"), {
                        wit_group: "copy_to_clipboard"
                    });
                    $("text-to-copy").select()
                }
            }
        } else {
            if (!$("flashcb")) {
                var i = document.createElement("div");
                i.id = "flashcb";
                document.body.appendChild(i)
            }
            $("flashcb").innerHTML = "";
            var c = '<embed src="/static/swf/_clipboard.swf" FlashVars="clipboard=' + encodeURIComponent(a.value) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
            $("flashcb").innerHTML = c
        }
    },
    report_exception: global_report_exception,
    scrollTop: function () {
        return window.scrollY || document.documentElement.scrollTop || 0
    },
    scrollLeft: function () {
        return window.scrollX || document.documentElement.scrollLeft || 0
    },
    setCursor: function (a) {
        if (!document.styleSheets[0].cssRules) {
            return
        }(document.styleSheets[0].rules || document.styleSheets[0].cssRules)[0].style.cursor = a;
        (document.styleSheets[0].rules || document.styleSheets[0].cssRules)[1].style.cursor = a
    },
    clearCursor: function () {
        if (!document.styleSheets[0].cssRules) {
            return
        }(document.styleSheets[0].rules || document.styleSheets[0].cssRules)[0].style.cursor = "auto";
        (document.styleSheets[0].rules || document.styleSheets[0].cssRules)[1].style.cursor = "pointer"
    },
    noHorizScroll: function () {
        if (!(/Mac.*(Firefox\/3|Camino)/.match(navigator.userAgent))) {
            document.body.style.overflowX = "hidden"
        }
    },
    allowHorizScroll: function () {
        document.body.style.overflowX = ""
    },
    scried: {},
    scry: function (c) {
        var a = Util.scried;
        var b = a[c];
        if (!b) {
            b = $(c);
            a[c] = b
        }
        return b
    },
    pathDepth: function (c) {
        var b = c.split("/");
        var d = 0;
        for (var a = 0; a < b.length; a++) {
            if (b[a].length) {
                d++
            }
        }
        return d
    },
    normalize: function (b) {
        if (!b) {
            return "/"
        }
        b = b.strip();
        var a = "";
        if (!b) {
            a = ""
        } else {
            a = b
        }
        if (!a.startsWith("/")) {
            a = "/" + a
        }
        if (a.endsWith("/")) {
            a = a.substr(0, a.length - 1)
        }
        return a
    },
    normPath: function (a) {
        if (!a || a.charAt(a.length - 1) != "/") {
            return a
        }
        return a.substr(0, a.length - 1)
    },
    normDir: function (a) {
        return Util.normPath(a) + "/"
    },
    parentDir: function (a) {
        return a.split("/").slice(0, -1).join("/") + "/"
    },
    urlquote: function (a) {
        return a.split("/").map(encodeURIComponent).join("/")
    },
    unevent: function (f) {
        if (f.attributes) {
            f.onclick = null;
            f.onmouseover = null;
            f.onmouseout = null;
            f.onmousedown = null;
            f.onmouseup = null;
            f.onmousemove = null
        }
        var c = f.childNodes,
            e, b;
        if (c) {
            b = c.length;
            for (e = 0; e < b; e += 1) {
                Util.unevent(c[e])
            }
        }
    },
    yank: function (a) {
        Util.unevent(a);
        if (!Util.dom_trash_can) {
            Util.dom_trash_can = Util.scry("trash-can")
        }
        Util.dom_trash_can.insert(a);
        Util.dom_trash_can.update();
        a = null;
        return a
    },
    ie8: Prototype.Browser.IE && document.documentMode && true,
    ie6: window.external && typeof window.XMLHttpRequest == "undefined",
    ie: Prototype.Browser.IE,
    linux_ff3: navigator.userAgent.toLowerCase().indexOf("linux") > -1,
    log: function () {
        Util.scry("ieconsole").innerHTML += $A(arguments).join(" ") + "<br>"
    },
    childElement: function (d, c) {
        var b = Util.childElementWithIndex(d, c);
        return b[0]
    },
    childElementWithIndex: function (h, c) {
        var f = 0;
        var b = h.childNodes;
        var a, d;
        a = b.length;
        for (d = 0; d < a; ++d) {
            var g = b[d];
            if (g.nodeType == 1 && f++ == c) {
                return [g, d]
            }
        }
        return [false, false]
    },
    childElementCache: {},
    childElementCached: function (c, f, b, a) {
        var d = Util.childElementCache[c];
        if (d !== undefined && a !== true) {
            return f.childNodes[d]
        }
        var e = Util.childElementWithIndex(f, b, true);
        Util.childElementCache[c] = e[1];
        return e[0]
    },
    childElementByIndexPath: function (d, c) {
        var a = c.length;
        for (var b = 0; b < a; b += 1) {
            d = Util.childElement(d, c[b])
        }
        return d
    },
    disableSelection: function (a) {
        a.onselectstart = function () {
            return false
        };
        a.unselectable = "on";
        a.style.MozUserSelect = "none";
        a.style.cursor = "default"
    },
    enableSelection: function (a) {
        a.onselectstart = function () {
            return true
        };
        a.unselectable = "off";
        a.style.MozUserSelect = "";
        a.style.cursor = ""
    },
    bsearch: function (a, g, d) {
        if (!d) {
            d = function (h) {
                return h
            }
        }
        var c = a.length;
        var e = 0;
        while (c > e) {
            var b = Math.floor(c / 2 + e / 2);
            var f = d(a[b]);
            if (f > g) {
                c = b
            } else {
                if (f < g) {
                    e = b + 1
                } else {
                    return b
                }
            }
        }
        return -1
    },
    nonce: function () {
        var c = new Date();
        var b = c.getTime().toString();
        var a = Math.floor(Math.random() * 1000000).toString().lpad(6);
        return b + a
    },
    _joff: function (c) {
        assert(c.length == 3, "incomplete jag");
        var d = $(c[0]);
        assert(d, "no element found with id " + c[0]);
        var a = c[1];
        var b = c[2];
        if (a.startsWith("on")) {
            d[a] = new Function(b)
        } else {
            d.setAttribute(a, b)
        }
        if (d.tagName.toLowerCase() == "a" && !d.hasAttribute("href")) {
            d.setAttribute("href", "#")
        }
    },
    live_joff: function (c, b) {
        var a = c.identify();
        if (a in Util._live_jags) {
            (function () {
                Util._live_jags[a].each(function (d) {
                    var e = $(d[0]);
                    assert(e, "jag elm %s missing".format(d[0]));
                    d[0] = b.down("#" + e.identify());
                    Util._joff(d)
                })
            }).defer()
        }
    },
    jag: function (c, a, b) {
        var d = $A(arguments);
        if (document.loaded) {
            Util._joff(d)
        } else {
            Util._jags.push(d)
        }
    },
    live_jag: function (e, c, a, b) {
        var d = $A(arguments).slice(1);
        if (e in Util._live_jags) {
            Util._live_jags[e].push(d)
        } else {
            Util._live_jags[e] = [d]
        }
    },
    _jags: [],
    _live_jags: {},
    focus: function (b) {
        b = $(b);
        try {
            b.focus()
        } catch (a) {}
    },
    sumStyles: function (b, c) {
        var a = 0;
        if (b) {
            c.each(function (d) {
                a += parseInt(b.getStyle(d), 10) || 0
            })
        }
        return a
    },
    syncHeight: function () {
        $$(".sync-height").invoke("setStyle", {
            height: "auto"
        });
        var a = $$(".sync-height").invoke("getHeight").max() - Util.sumStyles($$(".sync-height")[0], ["border-left-width", "padding-left", "padding-right", "border-right-width"]);
        $$(".sync-height").invoke("setStyle", {
            height: a > 0 ? a + "px" : "auto"
        })
    },
    formatGB: function (b, c) {
        var d, a;
        assert(b >= 1073741824, "must use value at least 1 GB");
        d = Math.round(b / 1073741824);
        if (c) {
            a = " "
        } else {
            a = ""
        }
        return d + a + "GB"
    },
    formatBytes: function (e, d, g, c) {
        e = parseFloat(e);
        var b = Math.abs(e);
        var h, f;
        if (b < 1024) {
            d = 0;
            g = true;
            h = e;
            f = ungettext("byte", "bytes", e)
        } else {
            if (b < 900 * 1024) {
                h = e / 1024;
                f = _("KB")
            } else {
                if (b < 900 * 1048576) {
                    h = e / 1048576;
                    f = _("MB")
                } else {
                    if (b < 900 * 1073741824 || (d === 0 && e < 1048576 * 1048576)) {
                        h = e / 1073741824;
                        f = _("GB")
                    } else {
                        h = e / (1048576 * 1048576);
                        f = _("TB")
                    }
                }
            }
        }
        h = Math.round(h * Math.pow(10, d)) / parseFloat(Math.pow(10, d));
        h = h.toFixed(d);
        var a;
        if (c && d > 0) {
            if (h != Math.floor(h)) {
                a = h
            } else {
                a = parseInt(Math.floor(h), 10)
            }
        } else {
            a = h
        }
        if (g) {
            a = a + " " + f
        }
        return a
    },
    formatTime: function (e) {
        var c = [86400, 3600, 60, 1];
        var d;
        e = isNaN(e) ? 0 : e;
        for (var b = 0; b < c.length; b += 1) {
            if (e >= c[b]) {
                d = parseInt(e / c[b], 10) || 0;
                break
            }
        }
        if (e < 1) {
            d = 0
        }
        var a;
        if (b >= 3) {
            a = ungettext("%d sec", "%d secs", d).format(d)
        } else {
            if (b == 2) {
                a = ungettext("%d min", "%d mins", d).format(d)
            } else {
                if (b == 1) {
                    a = ungettext("%d hour", "%d hours", d).format(d)
                } else {
                    if (b === 0) {
                        a = ungettext("%d day", "%d days", d).format(d)
                    } else {
                        assert(false, "Invalid time")
                    }
                }
            }
        }
        return a
    },
    is_right_click: function (b) {
        var a = false;
        if (b.which) {
            a = (b.which == 3)
        } else {
            if (b.button) {
                a = (b.button == 2)
            }
        }
        return a
    },
    removeClassNameRegex: {},
    removeClassName: function (c, a) {
        if (!c) {
            return
        }
        var b = Util.removeClassNameRegex[a];
        if (!b) {
            Util.removeClassNameRegex[a] = b = new RegExp("(^|\\s+)" + a + "(\\s+|$)")
        }
        c.className = c.className.replace(b, " ").strip();
        return c
    },
    observe: function (b, a, c) {
        b = Element.extend(b);
        if (b.addEventListener) {
            b.addEventListener(a, c, false)
        } else {
            b.attachEvent("on" + a, c)
        }
    },
    smartLoad: function (a) {
        if (document.loaded) {
            a()
        } else {
            document.observe("dom:loaded", a)
        }
    },
    nop: function () {
        return false
    },
    niceDate: function (a) {
        a = a || new Date();
        return 1 + a.getMonth() + "/" + a.getDate() + "/" + a.getFullYear()
    },
    reverseNiceDate: function (a) {
        if (!a) {
            return false
        }
        var b = a.split("/");
        if (b.length != 3) {
            return false
        }
        return new Date(parseInt(b[2], 10), parseInt(b[0], 10) - 1, parseInt(b[1], 10))
    },
    replaceHtml: function (c, b) {
        if (Prototype.Browser.IE) {
            c.innerHTML = b;
            return c
        }
        var a = c.cloneNode(false);
        a.innerHTML = b;
        c.parentNode.replaceChild(a, c);
        return a
    },
    isNumber: function (a) {
        return !isNaN(Number(a, 10))
    },
    resolve_target: function (b, a) {
        b = $(b);
        while (b && b != document.body) {
            if (b.match(a)) {
                return b
            } else {
                b = b.parentNode && Element.extend(b.parentNode)
            }
        }
        return false
    },
    shorten_url: function (a, c) {
        var b = new Ajax.DBRequest("/shorten_url", {
            parameters: {
                url: a
            },
            onSuccess: function (d) {
                c(d.responseText)
            }
        })
    },
    flash_version: function () {
        return FlashDetect.major + "." + FlashDetect.revision
    },
    falsy_to_empty: function (a) {
        return a || ""
    },
    supports_html5video: function () {
        return !!document.createElement("video").canPlayType
    },
    embed_h264_video: function (b, d, c, e, a) {
        if (FlashDetect.installed) {
            Util.embed_flash_video(b, d, c, e, a)
        } else {
            if (Util.supports_html5video()) {
                Util.embed_video(b, d, c, e, a)
            } else {
                $(d).update(_("Please enable flash to watch this video."))
            }
        }
    },
    embed_video: function (c, e, d, f, b) {
        b = b || d * 0.58;
        b = parseInt(b, 10);
        var a = new Element("video", {
            src: c,
            width: d,
            height: b,
            controls: 1
        });
        if (f) {
            a.autoplay = true
        }
        $(e).update(a)
    },
    embed_flash_video: function (a, i, b, c, j) {
        var g = new Element("div");
        var f = g.identify();
        $(i).insert(g);
        b = b || 532;
        j = j || b * 0.58;
        j = parseInt(j, 10);
        var e = {
            allowfullscreen: "true",
            allowScriptAccess: "always"
        };
        a = encodeURI(encodeURI(encodeURI(a)));
        var d = {
            file: a,
            skin: "/static/swf/bekle.swf",
            controlbar: "over",
            autostart: c,
            type: "video"
        };
        var h = {
            name: f
        };
        swfobject.embedSWF("/static/swf/player-licensed.swf", g.identify(), b.toString(), j.toString(), "9", false, d, e, h, function (k) {
            $(document).fire("db:flash_video_loaded", {
                player: $(k.ref)
            })
        })
    },
    embed_help_video: function (e, f, i) {
        var g = function (k, j, l, a) {
            if (FlashDetect.installed) {
                $(document).observe("db:flash_video_loaded", function (m) {
                    window.playerReady = function () {
                        m.memo.player.addModelListener("STATE", "AMC.help_article_play")
                    }
                })
            }
            Util.embed_h264_video(e, k, j, l, a)
        };
        if (i) {
            var c = new Element("img", {
                src: i
            });
            var b = new Element("a", {
                href: "#",
                style: "position: relative; display: block;"
            });
            var d = new Element("img", {
                src: "images/help_play.png"
            });
            d.addClassName("overlay_play");
            b.appendChild(c);
            b.appendChild(d);
            var h = new Element("div");
            b.observe("click", function (l) {
                h.update();
                Event.stop(l);
                Modal.show("", h, false, false, 860);
                var j = 800;
                var k = true;
                var a = 600;
                g(h, j, k, a);
                $("modal-title").hide()
            });
            $(f).update(b)
        } else {
            g(f)
        }
    },
    seconds_to_time: function (b) {
        b = parseInt(b, 10);
        var a;
        if (b > 60) {
            a = parseInt(b / 60, 10);
            b = b % 60
        } else {
            a = 0
        }
        a = a.toString().lpad(2, "0");
        b = b.toString().lpad(2, "0");
        return a + ":" + b
    },
    add_script: function (b) {
        var a = document.createElement("script");
        a.setAttribute("type", "text/javascript");
        a.setAttribute("src", b);
        document.getElementsByTagName("head")[0].appendChild(a)
    },
    supports_video: function () {
        var a = document.createElement("video");
        if (!a.canPlayType) {
            return false
        }
        return a.canPlayType("video/mp4")
    },
    create_cookie: function (c, d, e) {
        var a = "";
        if (e) {
            var b = new Date();
            b.setTime(b.getTime() + (e * 24 * 60 * 60 * 1000));
            a = "; expires=" + b.toGMTString()
        }
        document.cookie = c + "=" + d + a + "; path=/"
    },
    read_cookie: function (b) {
        var e = b + "=";
        var a = document.cookie.split(";");
        for (var d = 0; d < a.length; d++) {
            var f = a[d];
            while (f.charAt(0) == " ") {
                f = f.substring(1, f.length)
            }
            if (f.indexOf(e) === 0) {
                return f.substring(e.length, f.length)
            }
        }
        return null
    },
    delete_cookie: function (a) {
        Util.create_cookie(a, "", -1)
    },
    preloaded_images: {},
    preload_image: function (b) {
        if (Util.preloaded_images[b]) {
            return
        }
        var a = new Image();
        a.src = b;
        Util.preloaded_images[b] = a
    },
    get_preloaded_image: function (a) {
        if (Util.preloaded_images[a]) {
            return $(Util.preloaded_images[a])
        } else {
            return new Element("img", {
                src: a
            })
        }
    },
    copy_to_clipboard_swf: function (b, c, d, f) {
        var e = {
            wmode: "transparent",
            flashVars: "copy_text=" + Util.urlquote(b) + (d ? "&callback=" + d + "()" : "")
        };
        var a = new Element("div", {
            id: "flash_copy_container"
        });
        var g = new Element("div");
        a.update(g);
        if ($(f)) {
            f = $(f)
        } else {
            f = document.body
        }
        f.appendChild(a);
        swfobject.embedSWF("/static/swf/copy_to_clipboard.swf", g.identify(), "100%", "100%", "6.0.65", false, false, e);
        a.absolutize();
        a.style.zIndex = 1;
        a.clonePosition(c, {
            offsetTop: -3,
            offsetLeft: -3,
            offsetHeight: 6,
            offsetWidth: 6
        })
    },
    inner_height: function (a) {

        a = $(a);
        assert(a, "inner_height missing elm");
        return a.getHeight() - parseInt(a.getStyle("padding-top"), 10) - parseInt(a.getStyle("padding-bottom"), 10) - parseInt(a.getStyle("border-top-width"), 10) - parseInt(a.getStyle("border-bottom-width"), 10)
    },
    decode_b64: function (h) {
        if (typeof window.atob == "function") {
            return Util.utf8_decode(window.atob(h))
        }
        var d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        var c, b, a, m, l, k, j, n, g = 0,
            o = 0,
            e = "",
            f = [];
        if (!h) {
            return h
        }
        h += "";
        do {
            m = d.indexOf(h.charAt(g++));
            l = d.indexOf(h.charAt(g++));
            k = d.indexOf(h.charAt(g++));
            j = d.indexOf(h.charAt(g++));
            n = m << 18 | l << 12 | k << 6 | j;
            c = n >> 16 & 255;
            b = n >> 8 & 255;
            a = n & 255;
            if (k == 64) {
                f[o++] = String.fromCharCode(c)
            } else {
                if (j == 64) {
                    f[o++] = String.fromCharCode(c, b)
                } else {
                    f[o++] = String.fromCharCode(c, b, a)
                }
            }
        } while (g < h.length);
        e = f.join("");
        e = Util.utf8_decode(e);
        return e
    },
    utf8_decode: function (a) {
        var c = [],
            e = 0,
            g = 0,
            f = 0,
            d = 0,
            b = 0;
        a += "";
        while (e < a.length) {
            f = a.charCodeAt(e);
            if (f < 128) {
                c[g++] = String.fromCharCode(f);
                e++
            } else {
                if ((f > 191) && (f < 224)) {
                    d = a.charCodeAt(e + 1);
                    c[g++] = String.fromCharCode(((f & 31) << 6) | (d & 63));
                    e += 2
                } else {
                    d = a.charCodeAt(e + 1);
                    b = a.charCodeAt(e + 2);
                    c[g++] = String.fromCharCode(((f & 15) << 12) | ((d & 63) << 6) | (b & 63));
                    e += 3
                }
            }
        }
        return c.join("")
    },
    list_cmp: function (a, h) {
        var g = a.length;
        var c = h.length;
        var b = Math.min(g, c);
        for (var e = 0; e < b; e++) {
            var d = a[e];
            var f = h[e];
            if (d < f) {
                return -1
            }
            if (d > f) {
                return 1
            }
        }
        return g - c
    }
};
Util.scrollLeft = Util.scrollLeft.cached(50);
Util.scrollTop = Util.scrollTop.cached(50);
document.observe("dom:loaded", function () {
    Util.syncHeight();
    Util._jags.each(function (a) {
        Util._joff(a)
    })
});
var SimpleSet = Class.create({
    initialize: function (a) {
        this.d = {};
        this.update(a)
    },
    update: function (b) {
        b = b || [];
        for (var c = 0, a = b.length; c < a; c++) {
            var d = b[c];
            this.add(d)
        }
    },
    add: function (b) {
        var a = typeof(b);
        assert(["string", "number"].contains(a), "expected a string or a number, got %s".format(a));
        this.d["-" + a + ":" + b] = true
    },
    contains: function (b) {
        var a = typeof(b);
        return this.d["-" + a + ":" + b] || false
    }
});
var AMC = {
    log: function (b, a) {
        assert(b, "AMCLog missing label");
        var d = {
            label: b
        };
        if (a) {
            Object.extend(d, a)
        }
        var c = new Ajax.Request("/ajax_amc_log", {
            parameters: d
        })
    },
    help_article_play: function (a) {
        if (!AMC.help_article_play_logged) {
            AMC.help_article_play_logged = 1;
            if (Help.article_id) {
                var b = new Ajax.Request("/ajax_amc_help_video", {
                    parameters: {
                        article_id: Help.article_id
                    }
                })
            }
        }
    }
};
var MCLog = {
    log: function (a) {
        var b = new Ajax.Request("/ajax_mc_log/" + a)
    }
};
var ReferralRegisterAB = {
    log: function (b) {
        var a = new Ajax.Request("/referral_register_log", {
            method: "GET",
            parameters: {
                event: b
            }
        })
    }
};
var SM = {
    r: function (f, d, e, b) {
        var g = {
            tkey: f,
            action: d,
            visitor_user_id: e,
            subpath: b
        };
        var a = Object.toJSON(g);
        if (Jcached.get(a)) {
            return
        }
        Jcached.set(a, 1, 2000);
        var c = new Ajax.Request("/ajax_sm_visit", {
            parameters: g
        })
    }
};
String.prototype.widthSplit = function (d) {
    d = d || 15;
    var a = [];
    var c = this;
    var e = 0;
    var b = c.substring(e, e + d);
    while (b !== "") {
        a.push(b);
        e += d;
        b = c.substring(e, e + d)
    }
    return a
};
String.prototype.lpad = function (b, a) {
    var c = this;
    a = a || "0";
    while (c.length < b) {
        c = a + c
    }
    return c.toString()
};
String.prototype.pad_nums = function () {
    return this.replace(/(\d+)/, function (a) {
        return a.lpad(10)
    })
};
String.prototype.reverse = function () {
    var a = this.split("");
    var c = a.reverse();
    var b = c.join("");
    return b
};
String.prototype.replace_last = function (e, a) {
    var d = this.reverse();
    var c = e.reverse();
    var b = a.reverse();
    return d.replace(c, b).reverse()
};
String.prototype.create = function (a) {
    return a
};
String.prototype.count = function (a) {
    return (this.length - this.gsub(a, "").length) / a.length
};
String.prototype.snippet = function (f, e) {
    f = f || 26;
    e = e || 0.75;
    if (this.length <= f) {
        return this
    }
    var a = this.lastIndexOf(".");
    var b = "";
    if (a > 0) {
        b = this.substr(a);
        f = f - b.length
    } else {
        a = this.length;
        b = ""
    }
    f = f - this.create("...").length;
    var c = Math.floor(f * e);
    var g = f - c;
    var i = a - g;
    var d = this.substr(0, c);
    var h = this.substr(i, a - i);
    return d + "..." + h + b
};
String.prototype.title = function () {
    return this.charAt(0).toUpperCase() + this.substr(1)
};
var Emstring = Class.create({
    initialize: function (a) {
        this.s = a;
        this.info = this.widthInfo();
        this.length = a.length ? this.info[this.s.length - 1] : 0
    },
    create: function (a) {
        return new Emstring(a)
    },
    widthInfo: function () {
        var b = {};
        b[-1] = 0;
        for (var a = 0; a < this.s.length; a++) {
            b[a] = b[a - 1] + this.ems(this.s.charAt(a))
        }
        return b
    },
    findSpot: function (b) {
        if (!b) {
            return 0
        }
        var c = 0;
        var f = this.s.length;
        while (c <= f) {
            var a = Math.floor(c / 2 + f / 2);
            var d = this.info[a - 1];
            if (d > b) {
                f = a - 1
            } else {
                if (d < b) {
                    c = a + 1
                } else {
                    return a
                }
            }
        }
        if (c > a) {
            return c
        } else {
            return a
        }
    },
    ems: function (d) {
        var a = 0.65;
        if (Emstring.THIN_CHARS.contains(d)) {
            return 0.3
        }
        if (Emstring.WIDE_CHARS.contains(d)) {
            return 1
        }
        var b = d.charCodeAt(0);
        if (b < 128) {
            return a
        }
        if (12288 < b && b < 12543 || 65280 < b && b < 65375 || 19968 < b && b < 40879 || 13312 < b && b < 19888) {
            return 1.1
        }
        return a
    },
    substr: function (b, a) {
        b = this.findSpot(b);
        a = a !== null ? this.findSpot(b + a) : this.s.length;
        return new Emstring(this.s.substr(b, a))
    },
    indexOf: function (b) {
        var a = this.s.indexOf(b);
        return a > -1 ? this.info[a - 1] : -1
    },
    lastIndexOf: function (b) {
        var a = this.s.reverse().indexOf(b.reverse());
        if (a < 0) {
            return -1
        }
        return this.info[(this.s.length - a) - b.length - 1]
    },
    toString: function () {
        return this.s
    },
    snippet: String.prototype.snippet
});
Emstring.THIN_CHARS = new SimpleSet(["!", "'", "(", ")", ",", "-", ".", "/", ":", ";", "I", "J", "[", "\\", "]", "f", "i", "j", "l", "r", "t", "|"]);
Emstring.WIDE_CHARS = new SimpleSet(["#", "%", "+", "<", "=", ">", "M", "W", "^", "m", "w", "~"]);
var Job = {
    complete: {},
    handled: function (a) {
        if (!a) {
            return false
        }
        var b = !! Job.complete[a];
        Job.complete[a] = true;
        return b
    },
    peek: function (a) {
        if (!a) {
            return false
        }
        return !!Job.complete[a]
    }
};
var RequestWatcher = {
    reqs: [],
    working_msg: _("Still working..."),
    TIMEOUT: 5,
    watch: function (b, c) {
        var a = RequestWatcher.reqs;
        if (!a.length) {
            RequestWatcher.int_id = setInterval(RequestWatcher.check_up, 500)
        }
        if (c) {
            b.skip_message = true
        }
        a.push([b, Util.time()])
    },
    check_up: function () {
        RequestWatcher.scan(false)
    },
    remove: function (a) {
        RequestWatcher.scan(a)
    },
    scan: function (f) {
        var b = Util.time();
        var c = RequestWatcher.reqs.length;
        var a = RequestWatcher.reqs;
        var d = [];
        for (var e = 0; e < c; e++) {
            var h = a[e][0];
            var g = a[e][1];
            var j = b - g;
            if (h.transport.readyState == 4) {
                Notify.clearIf(RequestWatcher.working_msg);
                continue
            }
            if (j > 4000 && !h.skip_message) {
                h.skip_message = true;
                Notify.ServerSuccess(RequestWatcher.working_msg)
            }
            if (j > RequestWatcher.TIMEOUT * 1000 && h.job) {
                h.transport.abort()
            }
            if (h != f) {
                d.push([h, g])
            } else {
                h.transport.abort()
            }
        }
        RequestWatcher.reqs = d;
        if (!d.length) {
            clearInterval(RequestWatcher.int_id)
        }
    }
};
var ProgressWatcher = {
    job_info: {},
    INIT_POLL_INT: 1000,
    FAILS_MEAN_FAIL: 3,
    MODAL_WAIT_MS: 1000,
    watch: function (a) {
        ProgressWatcher.job_info[a.job_id] = {};
        var b = ProgressWatcher.job_info[a.job_id];
        b.req = a;
        b.poll_int = ProgressWatcher.INIT_POLL_INT;
        b.poll_count = 0;
        b.int_id = setInterval(ProgressWatcher.update_for(a.job_id), b.poll_int);
        b.failures = 0;
        b.start_time = Util.time()
    },
    update_for: function (a) {
        return function () {
            return ProgressWatcher.update(a)
        }
    },
    backoff: function (b) {
        var a = ProgressWatcher.job_info[b];
        clearInterval(a.int_id);
        a.poll_int = Math.min(Math.floor(a.poll_int * 1.5), 30000);
        a.int_id = setInterval(ProgressWatcher.update_for(b), a.poll_int)
    },
    update: function (d) {
        var c = ProgressWatcher.job_info[d];
        if (Job.peek(d)) {
            return ProgressWatcher.done(d)
        }
        c.poll_count++;
        if (c.poll_count % 10 === 0) {
            ProgressWatcher.backoff(d)
        }
        if (!c.modaled && Util.time() - c.start_time > ProgressWatcher.MODAL_WAIT_MS) {
            var b = c.req.options;
            ModalProgress.show(b.progress_text, b.cover_this);
            b.onProgress = ModalProgress.update;
            c.modaled = true
        }
        var a = new Ajax.Request("/job_status/" + d, {
            method: "post",
            t: Constants.TOKEN,
            onSuccess: function (i) {
                var l = ProgressWatcher.job_info[d];
                var h = i.responseText;
                var g = false;
                if (h.indexOf("err") === 0) {
                    ProgressWatcher.done(d);
                    ModalProgress.hide();
                    if (l.req.options.onFailure && !Job.handled(d)) {
                        l.req.options.onFailure(i)
                    }
                    return
                }
                if (h.indexOf("done") === 0) {
                    l.req.options.job = false;
                    if (!Job.handled(d)) {
                        var f = new Ajax.Request("/job_results/" + d, {
                            onSuccess: function (e) {
                                if (Job.handled(d)) {
                                    return
                                }
                                Notify.clearIf(RequestWatcher.working_msg);
                                if (l.req.options.onSuccess) {
                                    l.req.options.onSuccess(e)
                                }
                            },
                            onFailure: function (e) {
                                if (Job.handled(d)) {
                                    return
                                }
                                Notify.clearIf(RequestWatcher.working_msg);
                                if (l.req.options.onFailure) {
                                    l.req.options.onFailure(e)
                                }
                            }
                        })
                    }
                    var k = h.split("/");
                    h = k[1] + "/" + k[1];
                    ProgressWatcher.done(d);
                    ModalProgress.hide()
                } else {
                    try {
                        if (l.req.options.onProgress) {
                            l.req.options.onProgress(i.responseText)
                        }
                    } catch (j) {}
                }
            },
            onFailure: function (e) {
                var f = ProgressWatcher.job_info[d];
                f.failures++;
                if (f.failures >= ProgressWatcher.FAILS_MEAN_FAIL) {
                    if (f.req.options.onFailure) {
                        f.req.options.onFailure(e, true)
                    }
                    RequestWatcher.remove(f.req);
                    ProgressWatcher.done(d);
                    ModalProgress.hide()
                }
            }
        })
    },
    done: function (b) {
        var a = ProgressWatcher.job_info[b];
        clearInterval(a.int_id);
        delete ProgressWatcher.job_info[b];
        ModalProgress.hide()
    }
};
Ajax.DBRequest = Class.create(Ajax.Request, {
    initialize: function ($super, c, b) {
        this.start_time = Util.time();
        b = b || {};
        b.method = "post";
        b.parameters = b.parameters || {};
        b.parameters.t = Constants.TOKEN;
        var e = b.cleanUp ||
        function (h) {};
        if (b.job) {
            this.job_id = Util.nonce();
            b.parameters.job_id = this.job_id;
            ProgressWatcher.watch(this)
        }
        RequestWatcher.watch(this, !! b.job);
        var d = b.onFailure;
        var g = b.onSuccess;
        var f = b.onComplete;
        b.onFailure = function (i) {
            if (Job.handled(i.request.job_id)) {
                return
            }
            if (!b.noAutonotify) {
                var j = undefined;
                if (!Constants.IS_PROD && i.status === 500 && i.getHeader("X-Debug-Url")) {
                    var h = i.getHeader("X-Debug-Url");
                    j = _("There was a problem completing this request.") + ' <a href="' + h + '">View debug</a>'
                }
                Notify.ServerError(j)
            }
            e(false);
            if (d) {
                d(i)
            }
            if ([404, 502].contains(i.status)) {
                assert(false, "Ajax " + i.status + " on " + i.request.url)
            }
        };
        b.onSuccess = function (i) {
            var h = WIT._record("AJAX", "load", i.request.url, {
                time: new Date().getTime() - i.request.start_time
            });
            if (Job.handled(i.request.job_id)) {
                return
            }
            TranslationSuggest.update_i18n_messages_from_req(i);
            if (!i.responseText.length) {
                if (!b.job) {
                    if (!b.noAutonotify) {
                        if (!i || i.status !== 0) {
                            Notify.ServerError()
                        }
                    }
                    if (d) {
                        d(i)
                    }
                }
            } else {
                if (i.responseText.indexOf("err:") === 0) {
                    if (!b.noAutonotify) {
                        Notify.ServerError(i.responseText.substr(4))
                    }
                    if (d) {
                        d(i)
                    }
                } else {
                    if (g) {
                        if (i.responseText.indexOf("ok:") === 0) {
                            Notify.ServerSuccess(i.responseText.substr(3))
                        }
                        g(i)
                    }
                    if (f) {
                        f(i)
                    }
                }
            }
            e(true)
        };
        if (b.job) {
            c += (c.indexOf("?") != -1 ? "&" : "?") + "long_running=1"
        }
        var a = $H({
            url: c
        });
        if (b.parameters) {
            a.update(b.parameters);
            a.unset("t")
        }
        b.onSuccess.__tb_ajax_info__ = b.onFailure.__tb_ajax_info__ = a.toJSON();
        $super(c, b)
    }
});
var Sharing = {
    show_invites: function (a) {
        Modal.icon_show("email", _("Shared folder invitations (%d)").format(a), $("invites-container"))
    },
    get_sharing_options: function (b) {
        Modal.show_loading("folder_user", _("Loading shared folder options..."));
        b = Util.normalize(b);
        var a = new Ajax.DBRequest("/share" + b, {
            onSuccess: function (c) {
                Sharing.reshow = function () {
                    Sharing.show_sharing_options(c.responseText, b);
                    (function () {
                        if (Sharing.tc) {
                            Sharing.tc.toggle($("members"))
                        }
                    }).defer();
                    delete Modal.onHide
                };
                Sharing.show_sharing_options(c.responseText, b)
            },
            onFailure: function () {
                Modal.hide()
            }
        })
    },
    show_sharing_options: function (b, c) {
        var d = _("Shared folder options for '%(file_name)s'").format({
            file_name: FileOps.filename(c).escapeHTML().snippet(30)
        });
        Modal.icon_show("folder_user", d, b, {}, false, 550);
        var a = new Autocompleter.Contacts("new-collab-input", "new-whobulk", contacts, lcontacts, {
            tokens: [",", ";"]
        })
    },
    reset_wizard: function () {
        SuggestionInput.reset("new-collab-input");
        SuggestionInput.reset("custom-message-wizard");
        SuggestionInput.reset("new_folder_name");
        var a = $("invite-more-form").down("input[name='folder_name']");
        if (a) {
            a.remove()
        }
    },
    validate_folder: function (g, c, h) {
        c = $(c);
        var b = c.down("#folder_name");
        if (b) {
            if ($$("#modal-content #copy-move-treeview .highlight .s_folder_user_blue").length) {
                var f = Util.urlquote($F(b));
                return Sharing.show_invite_more_modal(f)
            }
        }
        var d = $(g.target);
        if (d && d.tagName != "input") {
            var a = d.up("#modal-content");
            d = a.down("input.button")
        }
        assert(c, "Trying to validate a folder where the form doesn't exist");
        Forms.ajax_submit(c, false, function () {
            if (h && typeof(h) == "function") {
                h(g, c)
            }
        }, false, d);
        return false
    },
    start_wizard: function (a) {
        Sharing.reset_wizard();
        if (a) {
            Event.stop(a)
        }
        Modal.icon_show(BrowseActions.getIcon("share_new"), _("Share a folder"), $("shared-folder-wizard"));
        $("create-new-sf").focus()
    },
    wizard_next: function (a) {
        Event.stop(a);
        if ($("create-new-sf").checked) {
            Sharing.validate_folder(a, "validate-folder-name", Sharing.from_new_to_invitation)
        } else {
            Modal.show(new Element("span").insert(Sprite.make("folder_user", {}).addClassName("modal-h-img")).insert(_("Choose Folder to Share")), $("existing-shared-folder-wizard"));
            TreeView.move("copy-move-treeview", "share-existing-treeview", {
                onSuccess: function () {
                    $("modal").observe("db:treeview_selected", function (c) {
                        $("folder_name").setValue(c.memo.path)
                    });
                    var b = $("first-treeview-link");
                    if (!Util.ie) {
                        b.onclick()
                    }
                }
            })
        }
        $$("#modal-content .suggestion-input").each(SuggestionInput.register)
    },
    from_new_to_invitation: function (d, b) {
        var f = $F(b.down("#new_folder_name")).strip();
        assert(f, "Moving from new folder to invite modal with no path.");
        Sharing.show_invite_more_wizard(f);
        Modal.vars.action = Sharing.submit_share_new_wizard;
        Modal.vars.path = "/" + f;
        var a = $("invite-more-form");
        var c = a.down("input[name=folder_name]");
        if (!c) {
            c = new Element("input", {
                type: "hidden",
                name: "folder_name"
            });
            a.insert(c)
        }
        c.setValue(f);
        $("share-invite-button").setValue(_("Share folder"))
    },
    from_existing_to_invitation: function (f, c, d) {
        if (!d) {
            d = $F(c.down("#folder_name")).strip()
        }
        assert(d, "Moving from choose a folder to invite modal with no path.");
        Sharing.show_invite_more_wizard(FileOps.raw_filename(d));
        Modal.vars.action = Sharing.submit_share_existing_wizard;
        Modal.vars.path = d.strip();
        var b = $("invite-more-form");
        var a = b.down("input[name=path]");
        if (!a) {
            a = new Element("input", {
                type: "hidden",
                name: "path"
            });
            b.insert(a)
        }
        a.setValue(d);
        $("share-invite-button").setValue(_("Share folder"))
    },
    show_invite_more_wizard: function (b) {
        assert(b, "Folder name required");
        DomUtil.fillVal("folder", "invite-more-wizard-share-type");
        var a = _('Share "%(folder_name)s" with others').format({
            folder_name: b.escapeHTML()
        });
        Modal.icon_show("folder_user", a, $("invite-more-wizard"));
        if (!Sharing.auto_completer) {
            Sharing.auto_completer = new Autocompleter.Contacts("new-collab-input", "new-whobulk", contacts, lcontacts, {
                tokens: [",", ";"]
            })
        }
    },
    show_cli: function () {
        Referral.select_all = 0;
        Sharing.old_state = Modal.vars;
        Modal.onHide = Sharing.hide_cli;
        Referral.show_login_modal()
    },
    hide_cli: function () {
        Referral.select_no_contacts();
        Sharing.add_from_cli();
        Sharing.load_contacts();
        delete Modal.onHide;
        return false
    },
    add_from_cli: function () {
        var c = Referral.get_selected_emails();
        Sharing.show_invite_more_wizard(FileOps.raw_filename(Sharing.old_state.path));
        Modal.vars = Sharing.old_state;
        var b = $("new-collab-input");
        SuggestionInput.do_blank("new-collab-input");
        var a = $F(b);
        if (c) {
            b.setValue(a + (a.length > 0 ? ", " : "") + c);
            b.addClassName("suggestion-input-unfaded");
            b.defaulted = false
        }
        delete Modal.onHide
    },
    submit_share_new_wizard: function (b) {
        var a = $("invite-more-form");
        assert(a, "Couldn't find the invite more form.");
        Forms.ajax_submit(a, "/share_ajax/new", function () {
            Modal.hide();
            if (Sharing.is_new) {
                window.location = "/home" + Util.urlquote(Modal.vars.path)
            } else {
                var c = _('The shared folder "%(folder_name)s" has been created.').format({
                    folder_name: FileOps.raw_filename(Modal.vars.path)
                });
                Notify.ServerSuccess(c);
                Browse.reload_fqpath(Modal.vars.path);
                TreeView.schedule_reset()
            }
        }, function () {
            Forms.enable(a.down("input[type='submit']"))
        }, b.target);
        return false
    },
    submit_share_existing_wizard: function (b) {
        var a = $("invite-more-form");
        assert(a, "Couldn't find the invite more form.");
        Forms.ajax_submit(a, "/share_ajax/existing?long_running", function () {
            Modal.hide();
            if (Sharing.is_new) {
                window.location = "/home" + Util.urlquote(Modal.vars.path)
            } else {
                var c = _('Shared folder "%(folder_name)s" has been created.').format({
                    folder_name: FileOps.raw_filename(Modal.vars.path).escapeHTML()
                });
                Notify.ServerSuccess(c);
                Browse.force_reload()
            }
        }, function () {
            Forms.enable(a.down("input[type='submit']"))
        }, b.target);
        return false
    },
    show_share_existing_modal: function (a) {
        Sharing.reset_wizard();
        Sharing.from_existing_to_invitation(false, false, decodeURIComponent(a))
    },
    show_invite_more_modal: function (a) {
        Sharing.reset_wizard();
        Sharing.get_sharing_options(a)
    },
    submit_invite_more_wizard: function (b) {
        var a = $("invite-more-form");
        assert(a.down("input[name=ns_id]"), "Submit invite more wizard is missing ns_id");
        Forms.ajax_submit(a, "/share_ajax/invite_more", function () {
            Notify.ServerSuccess(_("Invited successfully."));
            Modal.hide();
            Browse.force_reload()
        }, function () {}, b.target);
        return false
    },
    show_leave_modal: function (b, a) {
        Modal.onHide = Sharing.reshow;
        var d = _('Leave the Shared Folder "%(folder_name)s"').format({
            folder_name: FileOps.filename(b).snippet().escapeHTML()
        });
        Modal.icon_show("folder_user_delete", d, DomUtil.fromElm("leave-confirm"), {
            wit_group: "share-leave-confirm"
        });
        var c = $("leave-share-form");
        c.action = "/share_ajax/leave?long_running";
        Modal.vars.ns_id = a;
        Modal.vars.folder_path = b
    },
    submit_leave: function (c) {
        delete Modal.onHide;
        var b = Modal.vars.folder_path;
        assert(b.length, "submit_leave: No shared folder path.");
        assert(Modal.vars.ns_id, "submit_leave: missing ns_id");
        var a = $("leave-share-form");
        Forms.add_vars(a, {
            ns_id: Modal.vars.ns_id
        });
        Forms.ajax_submit(a, false, function () {
            var d = _('You removed yourself from "%(msg)s".').format({
                msg: FileOps.filename(b).snippet().escapeHTML()
            });
            Notify.ServerSuccess(d);
            Modal.hide();
            if (Browse.current_nsid) {
                BrowseURL.set_path_url("", Util.parentDir(Browse.current_fqpath()))
            } else {
                if (typeof(Browse.current_path) !== "undefined") {
                    Browse.force_reload()
                } else {
                    if (window.SFController) {
                        window.SFController.convert_to_inactive(b)
                    } else {
                        window.location.reload()
                    }
                }
            }
        }, function () {}, c.target);
        return false
    },
    show_unshare_modal: function (b, a) {
        Modal.onHide = Sharing.reshow;
        var d = _('Unshare "%(folder_name)s"').format({
            folder_name: FileOps.filename(b).snippet().escapeHTML()
        });
        Modal.icon_show("link_break", d, DomUtil.fromElm("unshare-confirm"), {
            wit_group: "share-unshare-confirm"
        });
        var c = $("unshare-form");
        Modal.vars.path = b;
        Modal.vars.ns_id = a;
        c.action = "/share_ajax/unshare?long_running"
    },
    submit_unshare: function (c) {
        delete Modal.onHide;
        var a = $("unshare-form");
        var b = Browse.current_fqpath() || PAGE_PATH;
        assert(b.length, "submit_unshare: No shared folder path.");
        assert(Modal.vars.ns_id, "submit_unshare: missing ns_id");
        Forms.add_vars(a, {
            ns_id: Modal.vars.ns_id
        });
        Forms.ajax_submit(a, false, function () {
            Notify.ServerSuccess(_('You unshared the folder "%(folder_name)s"').format({
                folder_name: FileOps.filename(Modal.vars.path).snippet().escapeHTML()
            }));
            Modal.hide();
            if (Browse.files && Browse.files.length) {
                Browse.force_reload()
            } else {
                if (window.SFController) {
                    SFController.remove_by_path(Modal.vars.path)
                } else {
                    window.location.reload()
                }
            }
        }, false, c.target);
        return false
    },
    remove_div: function (a) {
        $(a).up(".bs-row").remove();
        return false
    },
    leave: function () {
        Modal.show(_("Leave Shared Folder?"), DomUtil.fromElm("leave-confirm"), {
            wit_group: "share-leave-confirm"
        })
    },
    unshare: function () {
        Modal.show(_("Unshare Folder?"), DomUtil.fromElm("unshare-confirm"), {
            wit_group: "share-unshare-confirm"
        })
    },
    ignore: function (c, a) {
        assert(a, "Share ignore did not get an ns_id");
        var d = _("Permanently Remove '%(folder_name)s'").format({
            folder_name: FileOps.filename(c).escapeHTML()
        });
        Modal.icon_show("folder_delete", d, DomUtil.fromElm("ignore-confirm"), {
            wit_group: "share-ignore-confirm"
        });
        var b = $("modal-content").down("form");
        b.action = "/share_action/ignore?longrunning";
        Forms.add_vars(b, {
            ns_id: a
        });
        Modal.vars.path = c
    },
    submit_ignore: function (b) {
        if (b) {
            Event.stop(b)
        }
        var a = $("share-ignore-form");
        assert(a, "Missing submit_ignore_form");
        Forms.ajax_submit(a, false, function (e) {
            var c = window.SFController.remove_by_path(Modal.vars.path);
            var f = {
                folder_name: FileOps.filename(Modal.vars.path).snippet().escapeHTML()
            };
            Notify.ServerSuccess(_("Permanently removed '%(folder_name)s'").format(f));
            Modal.hide()
        }, function () {
            window.location.reload()
        }, b && b.target)
    },
    rejoin: function (c, a) {
        assert(a, "Rejoin didn't get an ns_id");
        var d = _("Rejoin the Shared Folder '%(folder_name)s'?").format({
            folder_name: FileOps.filename(c).escapeHTML()
        });
        Modal.icon_show(BrowseActions.getIcon("rejoin"), d, DomUtil.fromElm("rejoin-confirm"), {
            wit_group: "share-rejoin-confirm"
        });
        var b = $("modal-content").down("form");
        b.action = "/share_action/rejoin?longrunning";
        Forms.add_vars(b, {
            ns_id: a
        });
        if (window.SFController) {
            Forms.add_vars(b, {
                from_share: "1"
            })
        }
        Modal.vars.path = c
    },
    submit_rejoin: function (c) {
        Event.stop(c);
        var a = $("rejoin-form");
        var b = Modal.vars.path;
        Forms.ajax_submit(a, false, function (d) {
            Modal.hide();
            Notify.ServerSuccess(_("Rejoined shared folder successfully."));
            if (window.SFController) {
                window.SFController.convert_to_active(b, d.responseText)
            } else {
                if (Browse.files.length) {
                    Browse.force_reload()
                } else {
                    window.location.reload()
                }
            }
        }, false, c.target);
        return false
    },
    cancel_user: function (b, a, g, c, e) {
        var f = _("Are you sure you want to uninvite %(email_address)s?").format({
            email_address: b
        });
        if (confirm(f)) {
            var d = new Ajax.DBRequest("/share_ajax/cancel_invite", {
                parameters: {
                    ns_id: a,
                    invite_id: g
                },
                onSuccess: function (h) {
                    Sharing.remove_div(c);
                    Notify.ServerSuccess(b.escapeHTML() + " has been uninvited.")
                }
            })
        }
    },
    kick_user: function (c, e, a, b, d, f) {
        DomUtil.fillVal(c, "kick-confirm-nickname");
        var g = _("Kick %(person_name)s out of Folder?").format({
            person_name: c
        });
        Modal.show(g, DomUtil.fromElm("kick-confirm"), {
            button: d,
            victim: e,
            ns_id: a,
            user_id: b,
            wit_group: "share-kick-confirm"
        })
    },
    do_kick: function (b, c, d) {
        var a = $F("keep-files-check");
        var e = new Ajax.DBRequest("/share_ajax/kick_user", {
            parameters: {
                ns_id: b,
                user_id: c,
                keep_files: a
            },
            onSuccess: function () {
                Notify.ServerSuccess(_("User removed successfully."));
                Modal.hide()
            }
        })
    },
    reinvite_user: function (b, a, d) {
        var c = new Ajax.DBRequest("/share_ajax/reinvite_user/" + PAGE_PATH, {
            parameters: {
                action: "reinvite_user",
                who: b
            },
            onSuccess: function (e) {
                Notify.ServerSuccess(_("%(person_name)s was reinvited successfully").format({
                    person_name: b
                }))
            }
        });
        return false
    },
    load_contacts: function () {
        if (Sharing.loading_contacts) {
            return false
        }
        Sharing.loading_contacts = true;
        var a = new Ajax.DBRequest("/get_contacts", {
            onSuccess: function (b) {
                var c = b.responseText.evalJSON(false);
                window.contacts = c.contacts;
                window.lcontacts = c.lcontacts;
                Sharing.loading_contacts = false;
                if (Sharing.auto_completer) {
                    Sharing.auto_completer.options.array = window.contacts;
                    Sharing.auto_completer.options.larray = window.lcontacts
                }
            }
        })
    }
};
var Upload = {

    SWFU: false,
    init: function (c) {
        var a = {};
        a[Constants.tcn] = Upload.touch;
        var b = Upload.initSWFU(a);
        if (!c) {
            Event.observe(window, "load", b)
        } else {
            b()
        }
        Upload.operaHack();
        FileQueue.clear();
        if (!c) {
            Upload.checkForFallback.delay(Util.linux_ff3 ? 0 : 5)
        }
    },
    initSWFU: function (a) {
        return function () {
            var b = new SWFUpload({
                upload_url: "https://" + Constants.BLOCK_CLUSTER + "/upload",
                file_post_name: "file",
                file_size_limit: "307200",
                file_types: "*",
                file_types_description: _("All Files"),
                file_upload_limit: "0",
                button_placeholder_id: "spanButtonPlaceholder",
                button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                button_width: 120,
                button_height: 30,
                button_image_url: Util.linux_ff3 ? "images/upload_button.gif" : "",
                button_text: Util.linux_ff3 ? "<span class='flash-button'>" + _("Select files...") + "</span>" : "",
                button_text_style: '.flash-button {color: #ffffff; font-size: 11pt;font-family: "lucida grande","lucida sans unicode",tahoma,verdana,arial,sans-serif;text-align: center; line-height: 16px;}',
                swfupload_loaded_handler: Upload.flashLoaded,
                file_dialog_start_handler: FileQueue.chooseFiles,
                file_queued_handler: Upload.fileQueued,
                file_queue_error_handler: Upload.fileQueueError,
                file_dialog_complete_handler: Upload.fileDialogComplete,
                upload_progress_handler: Upload.uploadProgress,
                upload_error_handler: Upload.uploadError,
                upload_success_handler: Upload.uploadSuccess,
                upload_complete_handler: Upload.uploadComplete,
                flash_url: "/static/swf/swfupload.swf",
                custom_settings: {
                    progress_target: "fsUploadProgress",
                    upload_successful: false
                },
                post_params: a,
                debug: Constants.upload_debug || false
            });
            Upload.SWFU = b
        }
    },
    reset: function () {
        if (FileQueue.uploading) {
            Upload.SWFU.cancelUpload()
        }
        FileQueue.clear();
        var a = $$(".swfuploader").first();
        if (a) {
            a.remove()
        }
        delete Upload.SWFU
    },
    updatePostParams: function (c) {
        var a = Upload.SWFU.getSetting("post_params");
        for (var b in c) {
            a[b] = c[b]
        }
        Upload.SWFU.setPostParams(a)
    },
    fileBrowse: function () {
        Upload.SWFU.cancelUpload();
        Upload.SWFU.selectFiles()
    },
    fileQueueError: function (f, b, d) {
        try {
            switch (b) {
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                var i = "<p>" + _("The upload limit online is 300MB. You can upload larger files with the <a href='/install'>Dropbox desktop application</a>.") + "</p>";
                var a = new Element("div");
                var h = new Element("p", {
                    style: "margin-bottom:0; text-align: right;"
                });
                var c = new Element("input", {
                    type: "button",
                    className: "button",
                    value: _("Okay")
                });
                c.observe("click", function () {
                    FileOps.show_upload(Browse.current_fqpath())
                });
                h.insert(c);
                a.insert(i);
                a.insert(h);
                Modal.icon_show("alert", _("Upload Error"), a);
                break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                alert(_("The file you selected is empty. Please select another file."));
                break;
            case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                alert(_("The file you choose is not an allowed file type."));
                break;
            default:
                alert(_("An error occurred in the upload. Try again later."));
                this.debug("Error Code: " + b + ", File name: " + f.name + ", File size: " + f.size + ", Message: " + d);
                break
            }
        } catch (g) {}
    },
    fileQueued: function (a) {
        FileQueue.push(a)
    },
    fileDialogComplete: function (a) {},
    uploadNext: function () {
        Upload.SWFU.startUpload()
    },
    pause: function () {
        Upload.SWFU.stopUpload()
    },
    uploadProgress: function (c, b, a) {
        FileQueue.update(c, b, a)
    },
    uploadSuccess: function (b, a) {
        if (a.strip() === "") {
            FileQueue.errored(b);
            Notify.ServerError()
        } else {
            if (a == "quota") {
                FileQueue.errored(b);
                Notify.ServerError(_("Your upload failed because you are over quota."))
            } else {
                FileQueue.update(b, "done")
            }
        }
    },
    uploadComplete: function (a) {
        FileQueue.completed(a);
        if (FileQueue.empty()) {
            FileQueue.doneUploading()
        } else {
            Upload.uploadNext()
        }
    },
    uploadError: function (e, b, d) {
        var c = e;
        FileQueue.queueSize -= e.size;
        if (parseInt(b, 10) != -280) {
            var a = FlashDetect.major + "." + FlashDetect.revision;
            Util.report_exception("Uploader Error: " + b + " " + d + " " + Object.toJSON(e) + " FLASH VERSION: " + a, window.location.href)
        }
        switch (b) {
        case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
            this.debug("Error Code: No backend file, File name: " + c.name + ", Message: " + d);
            break;
        case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
            this.debug("Error Code: Upload Limit Exceeded, File name: " + c.name + ", File size: " + c.size + ", Message: " + d);
            break;
        case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
            this.debug("Error Code: HTTP Error, File name: " + c.name + ", Message: " + d);
            break;
        case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
            this.debug("Error Code: Upload Failed, File name: " + c.name + ", File size: " + c.size + ", Message: " + d);
            break;
        case SWFUpload.UPLOAD_ERROR.IO_ERROR:
            this.debug("Error Code: IO Error, File name: " + c.name + ", Message: " + d);
            break;
        case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
            this.debug("Error Code: Security Error, File name: " + c.name + ", Message: " + d);
            break;
        case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
            this.debug("Error Code: Upload Cancelled, File name: " + c.name + ", Message: " + d);
            break;
        case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
            this.debug("Error Code: Upload Stopped, File name: " + c.name + ", Message: " + d);
            break;
        default:
            this.debug("Error Code: " + b + ", File name: " + c.name + ", File size: " + c.size + ", Message: " + d);
            break
        }
        FileQueue.errored(e, b);
        if (FileQueue.empty() && FileQueue.uploading) {
            FileQueue.doneUploading()
        }
    },
    grabURL: function () {
        var a = $F("file-box");
        if (/(^http|^https|^ftp):\/\//.match(a)) {
            $("url").value = a
        }
        return true
    },
    set_dest: function (b) {
        var a = b.split("/");
        var d = a[a.length - 1];
        if (!d.length) {
            d = _("Dropbox");
            b = "/"
        }
        DomUtil.fillVal(d.escapeHTML(), "dest-folder-text");
        DomUtil.fillVal(b, "dest-folder");
        $$(".dest-folder").each(function (e) {
            e.value = b
        });
        var c = Util.scry("basic-uploader-url");
        if (c) {
            c.href = c.href.replace(/(\/upload)(.*)(\?basic=1)/, function (h, g, i, e) {
                return g + Util.urlquote(b) + e
            })
        }
    },
    treeview_handler: function (b, a) {
        Upload.set_dest(b);
        FileQueue.clear()
    },
    new_folder: function () {
        TreeView.hide();
        Modal.show(_("Create New Folder..."), DomUtil.fromElm("create-folder"), {
            action: Upload.do_new_folder,
            wit_group: "new-folder-confirm"
        });
        if (!Util.ie) {
            $("first-treeview-link").onclick()
        }
    },
    do_new_folder: function () {
        if (!Modal.vars.selected_path) {
            Notify.ServerError(_("Please select a parent folder."));
            return
        }
        var d = $F("entered-name");
        var a = decodeURIComponent(Modal.vars.selected_path);
        var c = Util.urlquote(a);
        var b = new Ajax.DBRequest("/cmd/new" + c + "?to_path=" + d, {
            onSuccess: function (e) {
                Upload.treeview_handler(Util.normPath(a) + "/" + d);
                TreeView.schedule_reset()
            },
            cleanUp: function () {}
        })
    },
    flashLoaded: function () {
        Upload.flash_loaded = true;
        $("upload-loading").hide();
        $("upload-buttons").show()
    },
    checkForFallback: function () {
        if (!Upload.flash_loaded) {
            location.replace("/upload?basic=1")
        } else {
            clearInterval(Upload.opera_tid)
        }
    },
    operaHack: function () {
        if (Prototype.Browser.Opera) {
            Upload.opera_tid = setInterval(function () {
                $("opera-dummy-div").toggle()
            }, 200)
        }
    }
};
var Sprite = {
    SPACER: "images/icons/icon_spacer.gif",
    src: function (b, a) {
        b = $(b);
        Sprite.clear(b);
        b.addClassName("s_" + a)
    },
    current: function (b) {
        var a = $(b).classNames().findAll(function (c) {
            return !c.indexOf("s_")
        });
        return a.length ? a[a.length - 1].substr(2) : ""
    },
    replace: function (c, b, a) {
        c.removeClassName("s_" + b);
        c.addClassName("s_" + a)
    },
    toggle: function (c, b, a) {
        c = $(c);
        if (c.hasClassName("s_" + b)) {
            c.removeClassName("s_" + b);
            c.addClassName("s_" + a)
        } else {
            if (c.hasClassName("s_" + a)) {
                c.removeClassName("s_" + a);
                c.addClassName("s_" + b)
            }
        }
    },
    blue: function (a) {
        return a + "_blue"
    },
    clear: function (a) {
        a = $(a);
        a.className = a.classNames().reject(function (b) {
            return !b.indexOf("s_")
        }).join(" ")
    },
    make: function (c, a) {
        a = a || {};
        a.src = Sprite.SPACER;
        var d = "sprite s_" + c + " " + a["class"] || "";
        var b = new Element("img", a);
        b.addClassName(d);
        return b
    },
    html: function (b, a) {
        var d = Sprite.make(b, a);
        var c = new Element("div");
        c.update(d);
        return c.innerHTML
    },
    _get: function (a) {
        return a.className
    },
    _set: function (b, a) {
        b.className = a;
        b.src = Sprite.SPACER
    }
};
var TreeView = {
    disable_shares: false,
    tv: {},
    loaded: false,
    set_params: function (a) {
        TreeView.ajax_params = a
    },
    init: function (c, a, d) {
        d = d || "treeview";
        TreeView.tv[d] = {};
        var b = TreeView.tv[d];
        b.autohide = a === null ? true : a;
        b.handler = c;
        b.viewdiv = $(d);
        b.hidefunc = TreeView.hide.bindAsEventListener(this)
    },
    schedule_reset: function () {
        TreeView.loaded = false
    },
    reset: function (b) {
        var a = new Ajax.DBRequest("/ajax_subtreeview", {
            parameters: TreeView.ajax_params,
            onSuccess: function (d) {
                for (var c in TreeView.tv) {
                    TreeView.tv[c].viewdiv.down(".treeview-folders").update(d.responseText);
                    if (b && b.onSuccess) {
                        b.onSuccess(d)
                    }
                }
            }
        })
    },
    toggle: function (c, b) {
        Event.stop(c);
        var a = TreeView.tv[b || "treeview"];
        if (a.shown) {
            a.shown = false;
            TreeView.hide(c, b)
        } else {
            a.shown = true;
            TreeView.show(c.target, b)
        }
        return false
    },
    hide: function (c, b) {
        var a = TreeView.tv[b || "treeview"];
        if (!c || !$(c.target).descendantOf(a.viewdiv)) {
            a.viewdiv.hide();
            Event.stopObserving(window, "click", a.hidefunc);
            a.shown = false
        }
    },
    show: function (c, b) {
        var a = TreeView.tv[b || "treeview"];
        c = $(c);
        c.blur();
        var d = c.cumulativeOffset();
        a.viewdiv.setStyle({
            top: (d.top + c.getHeight()) + "px",
            left: (d.left - 4) + "px"
        });
        a.viewdiv.show();
        Event.observe(window, "click", a.hidefunc)
    },
    toggleNode: function (b) {
        b = $(b);
        var a = b.down("img");
        if (a.className.match("bullet_plus")) {
            Sprite.replace(a, "bullet_plus", "bullet_minus")
        } else {
            Sprite.replace(a, "bullet_minus", "bullet_plus")
        }
        b.up().next("div").toggle();
        b.blur();
        return false
    },
    toggleNodeAjax: function (d, b) {
        if (d.fetched_children) {
            return TreeView.toggleNode(d)
        }
        d = $(d);
        var c = d.down("img");
        var e = Sprite._get(c);
        c.src = "images/icons/ajax-loading-small.gif";
        var a = new Ajax.DBRequest("/ajax_subtreeview" + b, {
            parameters: TreeView.ajax_params,
            onSuccess: function (f) {
                var g = new Element("div", {
                    style: "display: none;"
                }).update(f.responseText);
                d.up().insert({
                    after: g
                });
                d.fetched_children = true;
                Sprite._set(c, e);
                return TreeView.toggleNode(d)
            },
            cleanUp: function (f) {
                if (/loading/.match(c.src)) {
                    Sprite._set(c, e)
                }
            }
        });
        return false
    },
    handle: function (c, b) {
        var d = $H(TreeView.tv).keys();
        var a = $(b).ancestors().find(function (e) {
            return d.include(e.id)
        });
        if (!a) {
            return
        }
        a = TreeView.tv[a.id];
        $("modal").fire("db:treeview_selected", {
            path: c
        });
        if (a.handler) {
            a.handler(c, b)
        }
        if (a.autohide) {
            TreeView.hide(a.id)
        }
    },
    move: function (c, d, b) {
        var a = $(c);
        if (!TreeView.loaded) {
            TreeView.reset({
                onSuccess: function () {
                    TreeView.loaded = 1;
                    TreeView.move(c, d, b)
                }
            })
        } else {
            if (b && b.onSuccess) {
                b.onSuccess()
            }
        }
        assert(a, "Couldn't find tree_id");
        assert($(d), "Couldn't find location_id");
        $(d).appendChild(a);
        a.show()
    },
    disable_shared: function (f) {
        var a = $(f);
        if (a.share_disabled) {
            return
        }
        a.share_disabled = true;
        var d = a.select(".s_folder_user");
        var b = d.length;
        for (var c = 0; c < b; c++) {
            var g = d[c];
            Sprite.replace(g, "folder_user", "folder_user_gray");
            var e = g.up();
            e._onclick = e.onclick;
            e.onclick = Util.nop
        }
    },
    enable_shared: function (f) {
        var a = $(f);
        if (!a.share_disabled) {
            return
        }
        a.share_disabled = false;
        var d = a.select(".s_folder_user_gray");
        var b = d.length;
        for (var c = 0; c < b; c++) {
            var g = d[c];
            Sprite.replace(g, "folder_user_gray", "folder_user");
            var e = g.up();
            e.onclick = e._onclick
        }
    }
};
var ProgressBar = {
    MAGIC: 42,
    make: function (a, b, c) {
        b = b || 300;
        var f = b.toString() + "px";
        c = typeof(c) != "undefined" ? c : "0%";
        var i = new Element("div", {
            "class": "outer-progress-bar",
            style: "width: " + f
        });
        var j = new Element("div", {
            "class": "inner-progress-bar",
            id: "pb_" + a,
            style: "width: " + f
        });
        var g = new Element("div", {
            "class": "under-pb progress-bar",
            style: "width: " + f
        });
        var e = new Element("div", {
            style: "display: none",
            "class": "over-pb progress-bar",
            id: "pb_" + a + "_over"
        });
        var d = new Element("div", {
            "class": "pb-percentage",
            id: "pb_" + a + "_upct",
            style: "width: " + f
        });
        d.update(c);
        var h = new Element("div", {
            "class": "pb-percentage",
            id: "pb_" + a + "_opct",
            style: "width: " + f
        });
        h.update(c);
        g.insert(d);
        e.insert(h);
        j.insert(g);
        j.insert(e);
        i.insert(j);
        e.progress_width = b;
        return i
    },
    reset: function (a) {
        ProgressBar.set(a, 0)
    },
    set: function (e, a, d) {
        a = Math.min(a, 1);
        d = typeof(d) != "undefined" && d !== false ? d : Math.floor(a * 100).toString() + "%";
        var c = $("pb_" + e + "_over");
        if (!c) {
            return
        }
        var b = c.progress_width * a;
        c.show();
        c.makeClipping().setStyle({
            width: b.toString() + "px",
            backgroundColor: "#348DD3"
        });
        $("pb_" + e + "_upct").innerHTML = d;
        $("pb_" + e + "_opct").innerHTML = d
    },
    get_frac: function (b) {
        var a = $("pb_" + b + "_over");
        return parseInt(a.style.width, 10) / a.progress_width
    },
    errorState: function (d, a) {
        a = a || "Error";
        var c = $("pb_" + d + "_over");
        if (!c) {
            return
        }
        var b = c.progress_width;
        c.show();
        c.makeClipping().setStyle({
            width: b.toString() + "px",
            backgroundColor: "#d23a3a"
        });
        $("pb_" + d + "_upct").innerHTML = a;
        $("pb_" + d + "_opct").innerHTML = a
    }
};
var ModalProgress = {
    show: function (c, a) {
        if (!c) {
            return
        }
        a = $(a || "browse-box");
        var b = $("modal-progress-overlay");
        b.clonePosition(a);
        if (!b.getWidth()) {
            return
        }
        $("modal-progress-text").update(c);
        $("modal-progress-bar").setOpacity(1);
        $("modal-progress-bar").update(ProgressBar.make("modal-progress", 150, ""));
        $("modal-progress-content").style.top = (Math.max(0, Util.scrollTop() - a.cumulativeOffset().top) + 120) + "px";
        Effect.Appear(b, {
            to: 0.7,
            duration: 0.25
        });
        Effect.Appear("modal-progress-content", {
            duration: 0.25
        })
    },
    update: function (a) {
        if (a.indexOf("/") > 0) {
            var b = a.split("/");
            a = Number(b[0]) / Number(b[1])
        }
        if (a) {
            ProgressBar.set("modal-progress", a, "")
        }
    },
    hide: function () {
        Effect.Fade("modal-progress-overlay", {
            duration: 0.25
        });
        Effect.Fade("modal-progress-content", {
            duration: 0.25
        })
    }
};
var InlineUploadStatus = {
    upload_box: false,
    last_update: 0,
    last_update_position: 0,
    previous_bps_list: [],
    show: function (a) {
        if (!InlineUploadStatus.upload_box) {
            InlineUploadStatus.build(a)
        }
        InlineUploadStatus.upload_box.show()
    },
    build: function () {
        if (!InlineUploadStatus.upload_box) {
            InlineUploadStatus.upload_box = $("inline-upload-status")
        }
        $("right-content").insert({
            top: InlineUploadStatus.upload_box
        })
    },
    hide: function () {
        if (InlineUploadStatus.upload_box) {
            InlineUploadStatus.upload_box.hide()
        }
    },
    update: function () {
        if ($$("#right-content #inline-upload-status").length === 0) {
            InlineUploadStatus.build()
        }
        if (FileQueue.currentFilename) {
            var d = $("inline-upload-status");
            d.removeClassName("error");
            d.removeClassName("complete");
            var c = FileQueue.numShown();
            var a = c - FileQueue.toUpload + 1;
            var e = _("Uploading file %(file_number)d of %(total)d (%(upload_speed)s)").format({
                file_number: a,
                total: c,
                upload_speed: FileQueue.formattedSpeed
            });
            d.down(".upload-info-filename").update(e);
            d.down(".upload-info-status").update("<strong>" + _("Time Left:") + "</strong> " + FileQueue.formattedTime);
            var b = (parseInt(100 * FileQueue.totalPercentage, 10) || 0) + "%";
            d.down(".upload-info-percent").update(b);
            d.down(".upload-info-icon").update(Sprite.make("sync"));
            d.down(".upload-file-progress").style.width = b
        }
    },
    errored: function (e, c) {
        var b = $("inline-upload-status");
        b.addClassName("error");
        b.removeClassName("complete");
        var d = _("Problems with %(error_count)d of %(total)d files").format({
            error_count: e,
            total: c
        });
        b.down(".upload-info-filename").update(d);
        b.down(".upload-info-percent").update("100%");
        var a = (Util.time() - FileQueue.start_time) / 1000;
        b.down(".upload-info-status").update();
        b.down(".upload-info-icon").update(Sprite.make("redx"));
        b.down(".upload-file-progress").style.width = "100%"
    },
    complete: function () {
        var b = $("inline-upload-status");
        b.addClassName("complete");
        var c = _("Uploaded %(number_uploaded)d of %(total)d files").format({
            number_uploaded: FileQueue.numShown(),
            total: FileQueue.numShown()
        });
        b.down(".upload-info-filename").update(c);
        b.down(".upload-info-percent").update("100%");
        var a = (Util.time() - FileQueue.start_time) / 1000;
        b.down(".upload-info-status").update("<strong>" + _("Time taken:") + "</strong> " + Util.formatTime(a));
        b.down(".upload-info-icon").update(Sprite.make("check"));
        b.down(".upload-file-progress").style.width = "100%"
    }
};
var FileQueue = {
    fileRows: {},
    fileProgress: {},
    uploading: false,
    toUpload: 0,
    queueSize: 0,
    completedSize: 0,
    completed_files: {},
    empty: function () {
        return !FileQueue.toUpload
    },
    numShown: function () {
        return $H(FileQueue.fileRows).keys().length
    },
    lastOne: function () {
        return 1 == FileQueue.toUpload
    },
    push: function (c) {
        var a = c.name;
        var d = c.id;
        FileQueue.queueSize += c.size;
        FileQueue.fileRows[d] = c;
        if (!FileQueue.toUpload) {
            GlobalUpload.files_added()
        }
        FileQueue.toUpload++;
        UploadFile.add(c);
        var b = $("choose-button").down(".hotbutton-content");
        b.update(_("Add more files"))
    },
    remove: function (a) {
        var b = a.id;
        Upload.SWFU.cancelUpload(b);
        a.filestatus = SWFUpload.FILE_STATUS.CANCELLED;
        UploadFile.update(a);
        delete FileQueue.fileRows[b];
        if (!FileQueue.completed_files[b]) {
            FileQueue.toUpload = Math.max(0, FileQueue.toUpload - 1)
        }
        if (FileQueue.numShown() === 0 && FileQueue.uploading) {
            FileQueue.doneUploading()
        }
    },
    update: function (b, a, h) {
        var j = false;
        var c;
        var e = false;
        if (a == "done") {
            j = _("Done");
            a = h = 1;
            e = true
        } else {
            if (a / h == 1) {
                j = _("Saving...")
            }
        }
        if (e) {
            FileQueue.completedSize += b.size;
            c = FileQueue.last_update_position
        } else {
            c = FileQueue.completedSize + a / h * b.size
        }
        var f = b.averageSpeed / 8;
        var i = _("%(bytes)s/sec").format({
            bytes: Util.formatBytes(f, 1, true)
        });
        var g = (FileQueue.queueSize - c) / f;
        var d = Util.formatTime(g + FileQueue.toUpload);
        FileQueue.last_update_position = c;
        if (!j) {
            j = parseInt((c / FileQueue.queueSize).toFixed(2) * 100, 10);
            j += "%"
        }
        FileQueue.currentFilename = b.name.snippet(20);
        FileQueue.formattedSpeed = i;
        FileQueue.formattedTime = d;
        FileQueue.statusText = j;
        FileQueue.totalPercentage = c / FileQueue.queueSize;
        FileQueue.current_file = b;
        if (b.filestatus == SWFUpload.FILE_STATUS.COMPLETE) {
            UploadFile.update(b)
        }
        if (!FileQueue.update_timer) {
            FileQueue.update_timer = true;
            FileQueue.timer = setInterval(function () {
                UploadFile.update();
                GlobalUpload.update()
            }, 250)
        }
    },
    errored: function (b, a) {
        if (a != SWFUpload.UPLOAD_ERROR.FILE_CANCELLED) {
            FileQueue.errors = (FileQueue.errors + 1) || 1
        }
        UploadFile.update(b);
        if (FileQueue.toUpload === 0 && FileQueue.uploading) {
            FileQueue.doneUploading()
        }
    },
    completed: function (a) {
        var b = FileQueue.fileRows[a.id];
        if (b) {
            FileQueue.toUpload = Math.max(0, FileQueue.toUpload - 1);
            FileQueue.completed_files[a.id] = true
        }
    },
    clear: function (a) {
        FileQueue.fileRows = {};
        FileQueue.queueSize = 0;
        FileQueue.errors = 0;
        FileQueue.toUpload = 0;
        FileQueue.completedSize = 0;
        FileQueue.uploading = false;
        window.onbeforeunload = null;
        Modal.onHide = null
    },
    chooseFiles: function () {},
    uploadFiles: function () {
        if (!FileQueue.toUpload) {
            return
        }
        Upload.updatePostParams({
            dest: $$(".dest-folder")[0].getValue(),
            t: Constants.TOKEN
        });
        if (!FileQueue.uploading) {
            FileQueue.start_time = new Date().getTime();
            Upload.uploadNext();
            FileQueue.uploading = true;
            FileQueue.updateInterval = setInterval(InlineUploadStatus.update, 250);
            window.onbeforeunload = function a() {
                return _("Leaving this page will cancel your uploads.")
            };
            Modal.hide()
        }
    },
    colorButtons: function (a) {
        $A(["choose-button", "upload-button"]).each(function (b) {
            if (b == a) {
                $(b).removeClassName("grayed")
            } else {
                $(b).addClassName("grayed")
            }
        })
    },
    doneUploading: function () {
        GlobalUpload.complete();
        InlineUploadStatus.complete();
        clearInterval(FileQueue.timer);
        FileQueue.update_timer = false;
        FileQueue.uploading = false;
        clearInterval(FileQueue.updateInterval);
        DomUtil.fillVal("", "uploading-speed");
        DomUtil.fillVal("", "uploading-time-left");
        if (FileQueue.errors) {
            InlineUploadStatus.errored(FileQueue.errors, FileQueue.numShown())
        }
        FileQueue.last_update_position = 0;
        Browse.force_reload();
        Modal.onHide = null;
        window.onbeforeunload = null
    }
};
var GlobalUpload = {
    init: function () {
        $("init-global-upload").show();
        $("global-upload-progress").hide()
    },
    files_added: function () {
        $("upload-start-buttons").show();
        $("upload-running-buttons").hide();
        $("upload-finished-buttons").hide();
        $$("#upload-start-buttons .button")[0].removeClassName("grayed")
    },
    update: function () {
        $("upload-start-buttons").hide();
        $("upload-running-buttons").show();
        $("upload-finished-buttons").hide();
        $("init-global-upload").hide();
        var f = $("global-upload-progress");
        f.show();
        f.removeClassName("complete");
        var a = f.select("td")[1];
        var e = FileQueue.numShown();
        var c = e - FileQueue.toUpload + 1;
        var h = _("Uploading file %(file_number)d of %(total)d (%(upload_speed)s)").format({
            file_number: c,
            total: e,
            upload_speed: FileQueue.formattedSpeed
        });
        a.update(h);
        var g = f.select("td")[2];
        var d = (parseInt(100 * FileQueue.totalPercentage, 10) || 0) + "%";
        f.select("td")[2].update(d);
        f.down(".upload-file-progress").style.width = (100 * FileQueue.totalPercentage || 0).toFixed(2) + "%";
        var b = $("upload-time");
        b.update("<strong>" + _("Time left:") + "</strong> " + FileQueue.formattedTime)
    },
    complete: function () {
        $("upload-start-buttons").hide();
        $("upload-running-buttons").hide();
        $("upload-finished-buttons").show();
        var c = $("global-upload-progress");
        c.down().style.width = "100%";
        c.select("td")[2].update("100%");
        var e = c.select("td")[0];
        e.update(Sprite.make("check"));
        var b = (Util.time() - FileQueue.start_time) / 1000;
        $("upload-time").update("<strong>" + _("Time taken:") + "</strong> " + Util.formatTime(b));
        var a = c.select("td")[1];
        var d = _("Uploaded %(number_uploaded)d of %(total)d files").format({
            number_uploaded: FileQueue.numShown(),
            total: FileQueue.numShown()
        });
        a.update(d)
    }
};
var UploadFile = {
    add: function (d) {
        var b = $("upload-files-container");
        var a = new Element("div", {
            id: d.id
        });
        a.addClassName("upload-file");
        var c = '<table class="upload-file-info"><tr><td class="upload-info-icon"></td><td class="upload-info-filename"></td><td class="upload-info-status"></td><td class="upload-info-action"></td></tr></table>';
        a.innerHTML = '<div class="upload-file-progress"></div>' + c;
        b.insert(a);
        UploadFile.update(d)
    },
    remove: function (a) {
        $(a).remove()
    },
    update: function (d) {
        d = d || FileQueue.current_file;
        var k = $(d.id);
        assert(k, "Could not find file_elm for " + d.name);
        var j = FileOps.filename_to_icon(d.name);
        k.down(".upload-info-icon").update(Sprite.make(j, {}));
        k.down(".upload-info-filename").update(d.name.escapeHTML().truncate(40));
        var i = "upload-file";
        var m = new Element("a", {
            href: "#"
        });
        var c = Sprite.make("thick_x", {});
        m.update(c);
        m.observe("click", function (n) {
            Event.stop(n);
            FileQueue.remove(d)
        });
        var b = 0;
        var f = k.down(".upload-info-status"),
            e = k.down(".upload-info-action"),
            a = k.down(".upload-file-progress");
        assert(f, "Couldn't find status elm");
        assert(e, "Couldn't find action elm");
        assert(a, "Couldn't find progress elm");
        f.update();
        var h = parseInt(d.percentUploaded, 10) + "%";
        switch (d.filestatus) {
        case SWFUpload.FILE_STATUS.QUEUED:
            k.className = i + " queued";
            e.update(m);
            break;
        case SWFUpload.FILE_STATUS.IN_PROGRESS:
            k.className = i + " in_progress";
            if (h == "100%") {
                f.update(_("Saving"))
            } else {
                f.update(h)
            }
            b = h;
            $$(".uploadnotch").invoke("remove");
            var g = Sprite.make("arrow_blue", {});
            g.addClassName("uploadnotch");
            k.insert(g);
            break;
        case SWFUpload.FILE_STATUS.ERROR:
            k.className = i + " error";
            f.update("Error");
            b = "100%";
            var l = Sprite.make("information");
            l.observe("mouseover", function () {
                if (parseFloat(Util.flash_version(), 10) < 10.32) {
                    var o = _('Upload failed.  Please try upgrading to the latest version of <a id="adobe_link">Adobe Flash</a> and try again.');
                    o = o.replace('id="adobe_link"', 'href="http://get.adobe.com/flashplayer/" target="_blank"');
                    Tooltip.show(l, o)
                } else {
                    var n = _('Sorry, it looks like the advanced uploader is incompatible with your system. Please use the <a id="basic_link">basic uploader</a> to upload via the website');
                    n = o.replace('id="basic_link"', 'onclick="FileOps.show_basic_upload(Browse.current_location); return false;"');
                    Tooltip.show(l, n)
                }
            });
            e.update(l);
            break;
        case SWFUpload.FILE_STATUS.COMPLETE:
            k.className = i + " complete";
            f.update("100%");
            b = "100%";
            e.update();
            $$(".uploadnotch").invoke("remove");
            break;
        case SWFUpload.FILE_STATUS.CANCELLED:
            k.className = i + " cancelled";
            b = "100%";
            f.update("Cancelled");
            e.update();
            break
        }
        if (b === 0) {
            a.style.visibility = "hidden"
        } else {
            a.style.visibility = ""
        }
        a.style.width = b
    }
};
var Platform = {
    Windows: navigator.userAgent.indexOf("Win") > -1,
    XP: navigator.userAgent.indexOf("Windows NT 5") > -1,
    Vista: navigator.userAgent.indexOf("Windows NT 6") > -1,
    Mac: navigator.appVersion.indexOf("Mac") > -1
};
var DomUtil = {
    fromElm: function (a) {
        return $(a).innerHTML
    },
    updateFromElm: function (b, a) {
        b = $(b);
        a = $(a);
        b.update(DomUtil.fromElm(a));
        Util.live_joff(a, b)
    },
    fillVal: function (b, a) {
        $$("." + a).each(function (c) {
            c = $(c);
            if (c.tagName == "INPUT") {
                c.value = b;
                c.defaultValue = b
            } else {
                c.innerHTML = b
            }
        })
    }
};
var FileSearch = {
    last_search: "",
    MAX_RETURNED: 100,
    searched: {},
    results: [],
    result_hash: {},
    per_page: function () {
        var a = $("left-content").down(".lookatme");
        if (a && a.style.display != "none") {
            return 7
        } else {
            return 10
        }
    },
    search: function (d, b) {
        $("filesearchpaging").update();
        d = d.strip();
        FileSearch.last_search = d;
        var c = $("filesearch").defaulted;
        if (d.length < 3 || c) {
            $("filesearchresults").update();
            return
        }
        var a = FileSearch.search_local(d);
        if (FileSearch.should_search_server(d)) {
            FileSearch.search_server.defer(d)
        } else {
            if (a.length === 0) {
                FileSearch.render_empty()
            }
        }
        if (a && a.length) {
            FileSearch.render(a, b)
        }
        return false
    },
    invalidate_cache: function () {
        FileSearch.searched = {};
        FileSearch.results = [];
        FileSearch.result_hash = {}
    },
    search_local: function (h) {
        var e = h.split(/\s+/);
        var d = [];
        for (var c = 0; c < FileSearch.results.length; c += 1) {
            var g = FileSearch.results[c].filename.toLowerCase();
            var f = true;
            for (var b = 0, a = e.length; b < a; b += 1) {
                f &= g.indexOf(e[b].toLowerCase()) > -1
            }
            if (f) {
                d.push(FileSearch.results[c])
            }
        }
        return d
    },
    search_server: function (b) {
        FileSearch.searching = true;
        var a = new Ajax.DBRequest("/search", {
            parameters: {
                search_string: b
            },
            onSuccess: function (d) {
                FileSearch.searching = false;
                var c = d.responseText.evalJSON();
                FileSearch.searched[b] = c.length;
                if (c && c.length > 0) {
                    FileSearch.process_results(c)
                }
                FileSearch.search(FileSearch.last_search)
            }
        })
    },
    process_results: function (b) {
        var d = 0;
        for (var a = 0; a < b.length; a += 1) {
            var c = b[a];
            var e = c.href;
            if (!FileSearch.result_hash[e]) {
                FileSearch.results.push(c);
                FileSearch.result_hash[e] = true;
                d += 1
            }
        }
    },
    render: function (h, f) {
        h.sort(function (o, i) {
            if (o.filename.length > i.filename.length) {
                return 1
            } else {
                if (o.filename.length == i.filename.length) {
                    return 0
                } else {
                    return -1
                }
            }
        });
        f = f || 0;
        var g = h.slice(f, f + FileSearch.per_page());
        var l = new Element("ul");
        for (var j = 0; j < g.length; j += 1) {
            l.insert(FileSearch.render_item(g[j]))
        }
        var e = FileSearch.advanced_search_link();
        var b = ungettext("%(number_results)s result for %(search_query)s", "%(number_results)s results for %(search_query)s", h.length).format({
            number_results: h.length + (h.length >= FileSearch.MAX_RETURNED ? "+" : ""),
            search_query: FileSearch.last_search.escapeHTML().truncate(30)
        });
        b += "<br/>" + e;
        var a = new Element("h6").update(b);
        $("filesearchresults").update(a);
        var m = f + FileSearch.per_page() < h.length;
        var n = f > 0;
        var d = $("filesearchpaging");
        if (m || n) {
            if (n) {
                var c = new Element("a", {
                    href: "#"
                });
                c.update("&laquo; " + _("prev"));
                c.observe("click", function (i) {
                    FileSearch.search(FileSearch.last_search, f - FileSearch.per_page());
                    Event.stop(i)
                });
                d.insert(c)
            }
            if (m && n) {
                d.insert(" | ")
            }
            if (m) {
                var k = new Element("a", {
                    href: "#"
                });
                k.update(_("next") + " &raquo;");
                k.observe("click", function (i) {
                    FileSearch.search(FileSearch.last_search, f + FileSearch.per_page());
                    Event.stop(i)
                });
                d.insert(k)
            }
        }
        $("filesearchresults").insert(l)
    },
    render_item: function (j) {
        var h = new Element("li");
        var f = new Element("a");
        if (j.icon.startsWith("folder")) {
            var b, g;
            if (j.target_ns) {
                b = j.target_ns;
                g = ""
            } else {
                b = j.ns_id != Constants.root_ns ? j.ns_id : "";
                g = j.path
            }
            f.href = BrowseURL.get_path_url(b, Util.urlquote(g));
            f.observe("click", function (a) {
                Event.stop(a);
                BrowseURL.set_path_url(b, Util.urlquote(g))
            })
        } else {
            f.href = j.href
        }
        var c;
        var i = j.size ? " - " + Util.formatBytes(j.size, 2, true) : "";
        f.title = j.fq_path + i;
        c = Sprite.make(j.icon);
        c.addClassName("link-img");
        f.insert(c);
        var d = new Emstring(j.filename.escapeHTML());
        var e = d.findSpot(13);
        f.insert(j.filename.escapeHTML());
        h.update(f);
        return h
    },
    advanced_search_link: function () {
        var a = '<span style="font-weight:normal;">';
        a += '(<a href="/advanced_search?submit=y&include_files=y&include_folders=y&all_terms=' + Util.urlquote(FileSearch.last_search) + '">' + _("advanced search") + "</a>)";
        a += "</span>";
        return a
    },
    render_empty: function () {
        if (!FileSearch.searching) {
            var a = FileSearch.advanced_search_link();
            var b = _("No results found for '%(search_query)s'").format({
                search_query: FileSearch.last_search.escapeHTML().truncate(30)
            });
            $("filesearchresults").update(new Element("h6", {
                style: "margin:0 0 2px 0;padding:0;"
            }).update(b));
            $("filesearchresults").insert(a)
        }
    },
    should_search_server: function (a) {
        if (FileSearch.searched[a] === undefined) {
            return true
        } else {
            return false
        }
    },
    warmup: function () {
        if (!FileSearch.warm) {
            var a = new Ajax.DBRequest("/search/warmup");
            FileSearch.warm = true
        }
    }
};
var Modal = {
    show: function (k, f, g, m, c, h) {
        $$("#modal-content .error-message, #modal-content .error-removable").invoke("hide");
        if (FileQueue.uploading && !h) {
            alert(_("You can't do this while uploading."));
            return false
        }
        assert(f, "Missing modal content!");
        Modal.vars = g || {};
        var j = Modal.vars.icon || "help";
        c = c || 520;
        var l = (document.viewport.getScrollOffsets().top + 150);
        Util.scry("modal").setStyle({
            top: l + "px"
        });
        Util.scry("modal").setStyle({
            width: c + "px",
            margin: "0 0 0 " + Math.floor(-c / 2).toString() + "px"
        });
        Util.scry("modal-title").update(k);
        if (!h) {
            if (FileQueue.numShown()) {
                Upload.reset()
            }
            var a = Util.childElement($("modal-content"), 0);
            if (a && a != f) {
                $("grave-yard").insert(a)
            }
            var b = new Element("div");
            b.update(f);
            var e = Modal.vars.wit_group;
            if (!e) {
                var d = b.down();
                e = d && d.id
            }
            if (e) {
                WIT.add_group(b, e)
            }
            Util.scry("modal-content").insert(b);
            if (f.show) {
                f.show()
            }
            Element.show("modal")
        }
        Util.scry("modal-overlay").setOpacity(0.6);
        Util.scry("modal-overlay").show();
        Util.scry("modal-behind").setStyle({
            height: (Util.scry("modal").getHeight() + 20) + "px",
            width: (Util.scry("modal").getWidth() + 20) + "px",
            margin: "0 0 0 " + Math.floor(-c / 2 - 10).toString() + "px",
            top: (l - 10) + "px"
        });
        Util.scry("modal-behind").setOpacity(0.2);
        Util.scry("modal-behind").show();
        if (m) {
            $("modal-content").select("#" + m.id).first().focus()
        } else {
            if (!Util.ie) {
                var i = Util.scry("modal").down("input[type=button]") || Util.scry("modal").down("input[type=submit]");
                if (i) {
                    i.focus()
                }
            }
        }
        if (!Modal.track_id) {
            Modal.track_resizes()
        }
        $("modal-title").show();
        ActAsBlock.register(false, "modal");
        document.observe("keydown", Modal.keydown);
        $("modal-content").style.height = "auto";
        return false
    },
    keydown: function (b) {
        var a = BrowseKeys.getKey(b);
        if (a == 27) {
            Modal.hide()
        }
    },
    icon_show: function (e, h, f, g, a, d, c) {
        var b = new Element("div");
        b.insert(Sprite.make(e, {
            "class": "modal-h-img"
        }));
        b.insert(h);
        return Modal.show(b, f, g, a, d, c)
    },
    show_loading: function (a, c) {
        var b = "<p style='margin: 3em 0; text-align: center;'><img src='images/icons/ajax-loading-small.gif' alt=''/></p>";
        Modal.icon_show(a, c, b)
    },
    shown: function () {
        return Util.scry("modal").visible()
    },
    hide: function (b) {
        if (b) {
            Event.stop(b)
        }
        if (Modal.onHide) {
            var a = Modal.onHide();
            if (!a) {
                return
            }
        }
        Modal.onHide = null;
        Element.hide("modal-behind");
        Element.hide("modal-overlay");
        if (!FileQueue.numShown()) {
            Element.hide("modal")
        } else {
            $("modal").style.marginLeft = "-10000000px";
            if (FileQueue.uploading) {
                InlineUploadStatus.show()
            }
        }
        if (Modal.track_id) {
            clearInterval(Modal.track_id);
            Modal.track_id = false
        }
        document.stopObserving("keydown", Modal.keydown)
    },
    track_resizes: function () {
        Modal.track_id = setInterval(Modal.resize_bg, 150)
    },
    resize_bg: function () {
        var a = Util.scry("modal").getHeight();
        if (Modal.old_height != a || Util.scry("modal-behind").getHeight() < a) {
            Modal.old_height = a;
            Util.scry("modal-behind").setStyle({
                height: (a + 20) + "px"
            })
        }
    },
    vars: {}
};
var Tabs = {
    init: function () {
        var h = $A(document.getElementsByClassName("tab")).concat($A(document.getElementsByClassName("subtab")));
        for (var e = 0; e < h.length; e++) {
            var b = h[e].down("a");
            var d = b.href.split("/");
            if (h[e].hasClassName("subtab")) {
                b.href = "#" + d[d.length - 1]
            }
            if (Util.ie6 || Prototype.Browser.Opera) {
                var f = b.getWidth() - parseInt(b.getStyle("padding-left"), 10) * 2;
                f = (f + 2 + (f % 2));
                b.style.width = f + "px"
            }
            var c = Sprite.make("rounded_tl", {
                "class": "rounded_tl"
            });
            var g = Sprite.make("rounded_tr", {
                "class": "rounded_tr"
            });
            b.appendChild(c);
            b.appendChild(g)
        }
        e = 20;
        $$(".events_bubble").each(function (i) {
            var a = (-1 * i.getWidth() / 2) + "px";
            i.style.marginLeft = a;
            i.style.marginRight = a;
            i.style.right = "6px";
            i.parentNode.style.zIndex = e--
        })
    },
    check_url: function (b) {
        var a = Util.url_hash();
        if (!a || Tabs.last_shown == a) {
            return
        }
        Tabs.last_shown = a;
        if (Util.url_hash()) {
            Tabs.showTab(Util.url_hash() + "-tab", Util.url_hash())
        } else {
            Tabs.showTab(b + "-tab", b)
        }
    },
    showTab: function (h, e) {
        h = $(h);
        if (h) {
            h.fire("db:tabshown")
        }
        var f = document.getElementsByClassName("subtab");
        var d;
        for (d = 0; d < f.length; d++) {
            f[d].removeClassName("selected")
        }
        var b = document.getElementsByClassName("content-tab");
        for (d = 0; d < b.length; d++) {
            b[d].hide()
        }
        var g = $(e + "-tab") || $$(".subtab").first();
        var c = $(e + "-content") || $$(".content-tab").first();
        if (g) {
            g.addClassName("selected")
        }
        if (c) {
            c.show();
            Util.syncHeight();
            var a = c.select("input[type=text]", "textarea");
            if (a) {
                Util.focus(a[0])
            }
        }
        return false
    }
};
var Hosts = {
    edit: function (d) {
        var c = $("host" + d);
        if (c.editing) {
            return
        }
        c.editing = true;
        var b = c.innerHTML.unescapeHTML();
        c.previous = b;
        c.innerHTML = "<input type='text' class='skinny-input' size='20' maxlength='256' style=\"word-wrap: break-word;\" value=\"" + b.escapeHTML().gsub('"', "&quot;") + "\">&nbsp;<input type='button' onclick='Hosts.doneEditing(\"" + d + "\");' class='button' value='" + _("Save") + "'>&nbsp;<input type='button' onclick='Hosts.cancelEditing(\"" + d + "\");' class='button grayed' value='" + _("Cancel") + "'>";
        var a = c.down("input");
        Event.observe(a, "keydown", Hosts.checkKey(d));
        a.select();
        return false
    },
    doneEditing: function (d) {
        var c = $("host" + d);
        var b = c.down("input").value;
        var a = new Ajax.DBRequest("/computer_edit?host_id=" + d + "&name=" + Util.urlquote(b), {
            onSuccess: function (e) {
                Hosts.unedit(c, e.responseText)
            }
        })
    },
    cancelEditing: function (b) {
        var a = $("host" + b);
        Hosts.unedit(a, a.previous)
    },
    unedit: function (b, a) {
        b.editing = false;
        b.innerHTML = a.escapeHTML()
    },
    unlink: function (c, b, a) {
        DomUtil.fillVal(b.escapeHTML(), "unlink-confirm-name");
        Modal.icon_show("computer_delete", _("Unlink Computer?"), DomUtil.fromElm("unlink-confirm"), {
            host_id: c,
            plat: a,
            wit_group: "unlink-confirm"
        })
    },
    doUnlink: function (c, b) {
        var a = new Ajax.DBRequest("/computer_edit?host_id=" + c + "&unlink=yessir", {
            onSuccess: function (d) {
                Hosts.killRow(c);
                Hosts.dec_count(b)
            }
        })
    },
    dec_count: function (a) {
        var c = $(a + "-count");
        if (!c) {
            return
        }
        var d = c.innerHTML.split(" ");
        var b = parseInt(d.shift(), 10);
        var e = d.join(" ");
        if (!b) {
            return
        }
        b--;
        if (b == 1 && e.charAt(e.length - 1) == "s") {
            e = e.substr(0, e.length - 1)
        } else {
            if (b != 1 && e.charAt(e.length - 1) != "s") {
                e = e + "s"
            }
        }
        c.innerHTML = b.toString() + " " + e
    },
    killRow: function (d) {
        var a = $("host" + d).up("table");
        $("host" + d).up("tr").remove();
        if (Hosts.rowCount() === 0) {
            var b = new Element("tr");
            var c = new Element("td", {
                colspan: 4
            });
            c.innerHTML = "<center>" + _("You no longer have any hosts linked.") + "</center>";
            a.insert(b);
            b.insert(c)
        }
    },
    rowCount: function () {
        return $$(".host-row").length
    },
    checkKey: function (a) {
        return function (b) {
            b = b || window.event;
            if (b.keyCode == Event.KEY_RETURN) {
                Hosts.doneEditing(a)
            }
            if (b.keyCode == Event.KEY_ESC) {
                Hosts.cancelEditing(a)
            }
        }
    }
};
Autocompleter.Contacts = Class.create(Autocompleter.Base, {
    initialize: function (c, e, d, b, a) {
        this.baseInitialize(c, e, a);
        this.options.array = d;
        this.options.larray = b;
        this.options.frequency = 0.2;
        if (!window.contacts) {
            (function () {
                Sharing.load_contacts()
            }).defer()
        }
    },
    getUpdatedChoices: function () {
        if (!this.options.array && window.contacts && window.lcontacts) {
            this.options.array = window.contacts;
            this.options.larray = window.lcontacts
        }
        this.updateChoices(this.options.selector(this))
    },
    setOptions: function (a) {
        this.options = Object.extend({
            choices: 5,
            selector: function (t) {
                var m = [];
                var s = t.getToken().toLowerCase();
                var f = t.options.array.length;
                var o = t.options.choices;
                var r = t.options.array;
                var d = t.options.larray;
                for (var j = 0; j < f && m.length < o; j++) {
                    var n = [];
                    if (s.indexOf(" ") == -1) {
                        n.push("\\s+")
                    }
                    if (s.indexOf("+") == -1) {
                        n.push("\\+")
                    }
                    if (s.indexOf("@") == -1) {
                        n.push("@")
                    }
                    if (s.indexOf(".") == -1) {
                        n.push("\\.")
                    }
                    if (s.indexOf("&lt;") == -1) {
                        n.push("&lt;")
                    }
                    var q = RegExp("(" + n.join("|") + ")");
                    var e = r[j];
                    var k = d[j];
                    var h = n.length ? k.split(q) : [k];
                    var u = 0;
                    var g = h.length;
                    for (var b = 0; b < g; b++) {
                        if (!h[b]) {
                            continue
                        }
                        if (h[b].indexOf(s) === 0) {
                            m.push("<li>" + e.substr(0, u) + "<strong>" + e.substr(u, s.length) + "</strong>" + e.substr(u + s.length) + "</li>");
                            break
                        }
                        u += h[b].length
                    }
                }
                return "<ul>" + m.join("") + "</ul>"
            }
        }, a || {})
    },
    selectEntry: function () {
        var d = this.getCurrentEntry();
        var f = d.innerHTML;
        var h = [
            ["&gt;", "&lt;"],
            [">", "&lt;"]
        ];
        for (var c = 0; c < h.length; c++) {
            var e = h[c];
            var a = f.lastIndexOf(e[0]);
            if (a == f.length - e[0].length) {
                var g = f.lastIndexOf(e[1]);
                if (g != -1) {
                    d.innerHTML = f.substr(g + e[1].length, a - g - e[1].length)
                }
            }
        }
        var b = this.options.tokens.length > 1 ? this.options.tokens[0] + " " : "";
        d.innerHTML += b;
        this.active = false;
        this.updateElement(d);
        $(this.element).fire("db:autocompleted")
    }
});
var LeftNavBox = {
    close: function (c) {
        var b = $(c).up().up("div");
        var e = 1;
        var a;
        a = new Effect.BlindUp(b, {
            duration: e
        });
        return false
    }
};
var Invitations = {
    submit: function (a) {
        a = a || window.event;
        if (a.keyCode == Event.KEY_RETURN) {
            Invitations.send()
        }
    },
    send: function (b, a) {
        var c = $("invite-recip");
        Invitations.do_send($F(c), c, b, a)
    },
    do_send: function (c, f, b, a) {
        var g = c.strip().split(/[;,\s]+/).length;
        if (!g || c === "") {
            Notify.ServerError(_("Please enter an e-mail address."));
            return
        }
        if (c != $("invite-recip").title) {
            var e = {
                emails: c,
                referral_src: b
            };
            if (Referral.source) {
                e.source = Referral.source
            }
            var d = new Ajax.DBRequest("/send_invite", {
                parameters: e,
                onSuccess: function (h) {
                    if (Invitations.custom_on_success) {
                        Invitations.custom_on_success(h.responseText, a)
                    } else {
                        Notify.ServerSuccess(h.responseText.substr(5))
                    }
                    var i = Referral.on_success && Referral.on_success(h.responseText);
                    if (f) {
                        f.setValue("")
                    }
                },
                onFailure: function (h) {
                    if (h.responseText.startsWith("err:")) {
                        Notify.ServerError(h.responseText.substr(4))
                    } else {
                        Notify.ServerError()
                    }
                },
                noAutonotify: true
            })
        } else {
            Notify.ServerError(_("Please enter an email address."))
        }
        return false
    },
    addCustomMessage: function (b) {
        Event.stop(b);
        var c = b.target.tagName == "A" ? $(b.target) : $(b.target).up("a");
        c.addHTML = c.innerHTML;
        c.update(Sprite.make("email_delete", {
            "class": "link-img"
        }));
        c.appendChild(document.createTextNode(_("Remove custom message")));
        c.stopObserving("click");
        c.observe("click", Invitations.hideCustomMessage);
        var a = new Element("textarea", {
            title: _("Enter a custom message here"),
            name: "custom_message",
            "class": "custom-message suggestion-input act_as_block textinput",
            rows: 3,
            cols: 25,
            style: "margin-top: 0.75em;"
        });
        a.setValue(Invitations.custom_message || a.title);
        SuggestionInput.register(a);
        c.up().previous("div").insert({
            bottom: a
        });
        SuggestionInput.register(a);
        ActAsBlock.resize(a);
        return false
    },
    hideCustomMessage: function (b) {
        Event.stop(b);
        var c = b.target.tagName == "A" ? $(b.target) : $(b.target).up("a");
        c.stopObserving("click");
        c.observe("click", Invitations.addCustomMessage);
        c.update(c.addHTML);
        var a = c.up().up().select(".custom-message")[0];
        Invitations.custom_message = $F(a);
        a.parentNode.removeChild(a);
        return false
    }
};
var Feed = {
    firstTime: true,
    addComment: function () {
        if (!$F("comment").length || $("comment").defaulted) {
            return false
        }
        var a = new Ajax.DBRequest("/share_ajax/add_comment", {
            parameters: {
                comment: $F("comment"),
                ns_id: Feed.ns_id
            },
            onSuccess: function (b) {
                Feed.addCommentRow(b.responseText);
                $("comment").value = ""
            }
        });
        return false
    },
    addCommentRow: function (a) {
        var f = new Element("tr");
        var e = new Element("td", {
            valign: "top",
            "class": "note"
        });
        var d = new Element("img", {
            src: "images/icons/comment.gif"
        });
        e.insert(d);
        var c = new Element("td", {
            valign: "top",
            "class": "note"
        });
        c.innerHTML = a;
        var b = new Element("td", {
            valign: "top",
            "class": "note",
            width: "100",
            nowrap: "nowrap",
            align: "right"
        });
        b.innerHTML = _("(just added)");
        f.update(e);
        f.insert(c);
        f.insert(b);
        $("event-table").down("tr").insert({
            before: f
        })
    },
    feedPages: {},
    page_num: 0,
    ns_id: "false",
    page_size: 10,
    showLoading: function (f, a, e, d) {
        e = true;
        var c = $("feed-loading");
        a = $(a);
        if (!c) {
            c = new Element("div", {
                id: "feed-loading"
            });
            var b = '<table style="height: 100%; width: 100%; background:#fff;"><tr><td valign="top"><div id="feed-loading-text" style="padding-top: 16px;text-align:center;"></div></td></tr></table>';
            c.update(b);
            document.body.appendChild(c)
        }
        c.clonePosition(a);
        if (c.getWidth() === 0) {
            return
        }
        if (Util.ie) {
            c.style.left = a.getBoundingClientRect().left + "px"
        }
        c.setOpacity(0.9);
        if (f) {
            $("feed-loading-text").update()
        } else {
            $("feed-loading-text").update("<img src='images/icons/ajax-loading.gif' style='vertical-align: bottom;'/>" + (e ? "" : _("Loading...")))
        }
        $("feed-loading").show();
        if (d) {
            c.style.zIndex = "1001"
        }
    },
    hideLoading: function () {
        $("feed-loading").hide()
    },
    changeNamespace: function (a, b) {
        Feed.ns_id = a;
        Feed.getPage(0, Feed.page_size)
    },
    changeDate: function (a, b) {
        Feed.date = a;
        Feed.nice_date = Util.niceDate(a);
        if (!b) {
            Feed.getPage(0, Feed.page_size)
        }
    },
    getPage: function (b, c) {
        Feed.page_size = c;
        Feed.page_num = b;
        if (Feed.feedPages[Feed.get_key(b)]) {
            Feed.show(b, c)
        } else {
            Feed.showLoading(false, $("events-content"));
            var d = Feed.ns_id != "false" ? "&ns_id=" + Feed.ns_id.toString() : "&is_home=yes";
            var e = c ? "&feed_items=" + c.toString() : "";
            var a = new Ajax.DBRequest("/next_events?cur_page=" + (b).toString() + d + e, {
                parameters: {
                    date: Feed.nice_date ? Feed.nice_date : ""
                },
                onSuccess: function (f) {
                    Feed.feedPages[Feed.get_key(b)] = f.responseText;
                    Feed.show(b, c)
                }
            })
        }
        return false
    },
    show: function (a, b) {
        Feed.hideLoading();
        $("events-content").update(Feed.feedPages[Feed.get_key(a)]);
        var c = $("add-comment-button");
        if (c) {
            HotButton.register(c)
        }
    },
    tabClick: function (a) {
        var b = $("event-table");
        if (!b) {
            Feed.getPage(0);
            Feed.clearNewEvents()
        }
    },
    clearNewEvents: function (a) {
        $$(".events_bubble").invoke("hide")
    },
    url_check: function (b, d, c, a) {
        b = b || "false";
        if (Feed.ns_id != b) {
            $$("#filter-list .selected").invoke("removeClassName", "selected");
            var f = $("sf" + b);
            assert(f, "Missing sf elm for " + b);
            f.addClassName("selected")
        }
        var e = (Feed.ns_id != b || Feed.page_size != d || Feed.page_num != c || Feed.nice_date != a);
        Feed.ns_id = b || Feed.ns_id;
        Feed.page_size = d || Feed.page_size;
        Feed.page_num = c || Feed.page_num;
        if (a) {
            Feed.changeDate(new Date(a), true)
        }
        if (e) {
            if (a) {
                EventDatePicker.change_date(Feed.date)
            }
            Feed.getPage(Feed.page_num, Feed.page_size)
        }
    },
    set_url: function (c) {
        var a = c.ns_id !== undefined ? c.ns_id : Feed.ns_id,
            e = c.page_size || Feed.page_size,
            d = c.page_num !== undefined ? c.page_num : Feed.page_num,
            b = c.date !== undefined ? c.date : Feed.nice_date;
        var f = ["events", a, e, d, b].join(":");
        window.location.href = "#" + f
    },
    get_key: function (a) {
        return Feed.page_size + "_" + Feed.ns_id + "_" + Feed.date + "_" + a + "_" + Feed.nice_date
    },
    show_rss_modal: function (b, a) {
        assert(a, "RSS Feed modal with no ns_id");
        Modal.icon_show("feed", _("Subscribe to this RSS Feed"), $("rss-modal"));
        $("rss_url").setValue(b);
        BrowseActions.addCopyUrlFlash(b);
        $("copy_success").update();
        $("reset-rss-link").href = "/reset_rss/" + a;
        $("rss_url").select()
    }
};
Effect.BlindFadeUp = function (d, c) {
    var b, a;
    b = new Effect.BlindUp(d, c);
    a = new Effect.Fade(d, c);
    this.cancel = function () {
        b.cancel();
        a.cancel()
    }
};
Effect.BlindFadeDown = function (d, c) {
    var b, a;
    b = new Effect.BlindDown(d, c);
    a = new Effect.Appear(d, c);
    this.cancel = function () {
        b.cancel();
        a.cancel()
    }
};
Effect.Flash = function (d, c, b) {
    assert(c.startcolor && c.endcolor, "Start and end colors must be specified");
    assert(c.cycles, "Fade cycles must be specified");
    b = b || 0;
    var a = new Effect.Highlight(d, {
        duration: 1,
        startcolor: c.startcolor,
        endcolor: c.endcolor,
        restorecolor: c.endcolor,
        afterFinish: function () {
            var e = new Effect.Highlight(d, {
                duration: 1,
                startcolor: c.endcolor,
                endcolor: c.startcolor,
                restorecolor: c.startcolor,
                afterFinish: function () {
                    if (b < c.cycles) {
                        Effect.Flash(d, c, b + 1)
                    }
                }
            })
        }
    })
};
var Base = {
    mouseOut: false,
    sf_hidden: false,
    showSharedFolders: function (b, c) {
        Event.stop(c);
        var a = $("shared-folder-dropdown");
        Event.observe(a, "mouseover", Base.mouseOverList);
        Event.observe(a, "mouseout", Base.mouseOutList);
        Event.observe(c.target, "mouseout", Base.mouseOutList);
        Event.observe(c.target, "mouseover", Base.mouseOverList);
        Event.observe(document, "click", Base.hideSharedFolders);
        Base.sf_hidden = false;
        setTimeout(function () {
            if (Base.sf_hidden) {
                return
            }
            var e = $("share-menu-shadow");
            var d = a.select("li").length;
            a.clonePosition($(b).down("img"), {
                offsetTop: 8,
                offsetLeft: 1,
                setWidth: false,
                setHeight: false
            });
            a.style.height = (d > 9) ? "200px" : "";
            a.show();
            e.clonePosition($(b).down("img"), {
                offsetTop: 9,
                offsetLeft: 2,
                setWidth: false,
                setHeight: false
            });
            e.clonePosition(a, {
                setTop: false,
                setLeft: false
            });
            e.setOpacity(0.2);
            e.show()
        }, 350);
        return false
    },
    hideSharedFolders: function (b) {
        var a = $("shared-folder-dropdown");
        $("shared-folder-dropdown").hide();
        $("share-menu-shadow").hide();
        Event.stopObserving(window, "click", Base.hideSharedFolders);
        Event.stopObserving(a, "mouseover", Base.mouseOverList);
        Event.stopObserving(a, "mouseout", Base.mouseOutList);
        clearTimeout(Base.mouseOut);
        Base.mouseOut = false;
        Base.sf_hidden = true
    },
    mouseOverList: function () {
        clearTimeout(Base.mouseOut);
        Base.mouseOut = false
    },
    mouseOutList: function (b, a) {
        clearTimeout(Base.mouseOut);
        Base.mouseOut = setTimeout(Base.hideSharedFolders, a || 200)
    }
};
var Notify = {
    ServerError: function (a) {
        return Notify.showDiv(a, "server-error", _("There was a problem completing this request."), "#ffdddd", "#fff0f0")
    },
    ServerSuccess: function (a) {
        return Notify.showDiv(a, "server-success", _("Your request completed successfully."), "#e5fdd0", "#f7fff0")
    },
    showDiv: function (g, h, f, c, b) {
        var d = false;
        if (g && g.indexOf("important") === 0) {
            d = true;
            g = g.substr(10)
        }
        Notify.last_msg = g;
        Notify.clearAll();
        g = g || f;
        var e = Util.scry(h);
        if (!e) {
            return
        }
        e.down("span").update(g);
        if (!Notify.dont_center) {
            Util.center(e)
        }
        var a;
        a = new Effect.BlindFadeDown(e, {
            duration: 0.5,
            scaleTo: 75,
            queue: {
                scope: "notify"
            }
        });
        a = new Effect.Flash($(h).down("td"), {
            cycles: 3,
            startcolor: c,
            endcolor: b
        });
        if ($(h).down(".r0")) {
            a = new Effect.Flash($(h).down(".r0"), {
                cycles: 3,
                startcolor: c,
                endcolor: b
            })
        }
        if (!d) {
            a = new Effect.BlindFadeUp(e, {
                duration: 0.3,
                scaleFrom: 75,
                delay: 10,
                queue: {
                    scope: "notify"
                }
            })
        }
        if (Util.ie6) {
            e.scrollTo()
        }
    },
    clearAll: function () {
        $$(".notify").invoke("hide");
        var a = Effect.Queues.get("notify");
        a.effects = [];
        clearInterval(a.interval);
        a.interval = null
    },
    clearIf: function (a) {
        if (Notify.last_msg == a) {
            Notify.clearAll()
        }
    }
};
var Tooltip = {
    attach: function (g, b, a) {
        g = $(g);
        a = a ? $(a) : null;
        var f = g.id ? g.id : Math.floor(Math.random() * 10000 + 1);
        var e = Bubble.make(b, g.tail_position);
        e.setStyle({
            display: "none",
            position: "absolute"
        });
        $("floaters").insert(e);
        if (g.match("#modal-content *")) {
            e.style.zIndex = "13001"
        } else {
            e.style.zIndex = ""
        }
        if (g.tail_position == "right") {
            var c = Util.ie ? 32 : 12;
            e.style.marginLeft = -(e.getWidth() + g.getWidth() + c) + "px"
        }
        g.tooltip = e;
        g.out_target = a ? true : false;
        g.observe("mouseout", Tooltip.mouseout("target", g));
        g.observe("mouseover", Tooltip.mouseover("target", g));
        g.out_trigger = a ? false : true;
        if (a) {
            a.observe("mouseout", Tooltip.mouseout("trigger", g));
            a.observe("mouseover", Tooltip.mouseover("trigger", g))
        }
        g.out_tooltip = true;
        e.observe("mouseout", Tooltip.mouseout("tooltip", g));
        e.observe("mouseover", Tooltip.mouseover("tooltip", g))
    },
    update: function (b, a) {
        if (b.tooltip) {
            $(b.tooltip).update(a)
        }
    },
    mouseover: function (a, b) {
        return function () {
            b["out_" + a] = false
        }
    },
    mouseout: function (a, b) {
        return function () {
            b["out_" + a] = true;
            Tooltip.hide_if_out.defer(b)
        }
    },
    show_by: function (b) {
        var c = $(b.tooltip);
        c.show();
        var a = Math.floor(c.getHeight() / 2);
        c.clonePosition(b, {
            setWidth: false,
            setHeight: false,
            offsetTop: Math.floor(b.getHeight() / 2) - a,
            offsetLeft: b.getWidth() + 1
        })
    },
    hide_if_out: function (a) {
        if (!a.out_target || !a.out_trigger || !a.out_tooltip) {
            return
        }
        var b = $(a.tooltip);
        b.hide()
    },
    show: function (d, c, b, a) {
        a = a || "left";
        d = $(d);
        if (!d.tail_position) {
            d.tail_position = a
        }
        b = b ? $(b) : null;
        if (!d.tooltip) {
            Tooltip.attach(d, c, b)
        }
        Tooltip.show_by(d)
    }
};
var BrowseURL = {
    PATH: 0,
    SORT: 1,
    DEL: 2,
    NS: 3,
    ALL_FIELDS: ["PATH", "SORT", "DEL", "NS"],
    get_sort: function () {
        return Util.url_hash().split(":")[BrowseURL.SORT]
    },
    get_path: function () {
        return Util.url_hash().split(":")[BrowseURL.PATH]
    },
    get_del: function () {
        return Util.url_hash().split(":")[BrowseURL.DEL]
    },
    get_ns: function () {
        return Util.url_hash().split(":")[BrowseURL.NS]
    },
    make_url: function (b) {
        var c = Util.url_hash().split(":");
        for (var a in b) {
            c[BrowseURL[a]] = Util.falsy_to_empty(b[a])
        }
        return "#" + c.join(":")
    },
    clean_url_hash: function () {
        var g = Util.url_hash().split(":");
        var h = {};
        for (var c = 0, a = BrowseURL.ALL_FIELDS.length; c < a; c++) {
            var e = BrowseURL.ALL_FIELDS[c];
            h[e] = g[BrowseURL[e]]
        }
        var b = BrowseURL.make_url(h);
        return b.substr(1)
    },
    get_sort_url: function (b, a) {
        return BrowseURL.make_url({
            SORT: b + "," + (a ? 1 : 0)
        })
    },
    get_path_url: function (a, c) {
        a = Util.falsy_to_empty(a);
        var b = BrowseURL.make_url({
            PATH: Util.normPath(c),
            NS: a
        });
        return b
    },
    set_path_url: function (a, d, c) {
        var b = BrowseURL.make_url({
            PATH: Util.normPath(d),
            NS: a
        });
        if (c) {
            BrowseURL.last_hash = b.substr(1)
        }
        if (b.toLowerCase() != "#" + Util.url_hash().toLowerCase()) {
            location.href = b
        }
    },
    get_del_url: function (a) {
        return BrowseURL.make_url({
            DEL: a ? 1 : 0
        })
    },
    check_url: function () {
        var e = Util.url_hash();
        if (!e.length && BrowseURL.last_hash && BrowseURL.last_hash.length) {
            return
        }
        if (BrowseURL.last_hash != e) {
            var d = e.split(":");
            var a = BrowseURL.last_hash ? BrowseURL.last_hash.split(":") : [];
            BrowseURL.last_hash = e;
            if (a.length > BrowseURL.SORT - 1 && a[BrowseURL.SORT] != d[BrowseURL.SORT]) {
                SortSet.url_sort()
            }
            var f = Util.normPath(decodeURIComponent(a[BrowseURL.PATH])) != Util.normPath(decodeURIComponent(d[BrowseURL.PATH]));
            var b = Util.falsy_to_empty(a[BrowseURL.NS]) != Util.falsy_to_empty(d[BrowseURL.NS]);
            var c = Util.falsy_to_empty(a[BrowseURL.DEL]) != Util.falsy_to_empty(d[BrowseURL.DEL]);
            if (!e || f || b || c) {
                Browse.deleted_shown = d[BrowseURL.DEL] == "1" ? 1 : 0;
                Browse.reload(d[BrowseURL.NS], d[BrowseURL.PATH], c || b)
            }
        }
    }
};
var SortSet = {
    sort: function (c, a) {
        BrowseKeys.clear_highlight();
        c.blur();
        var b = SortSet.pick(c);
        Browse.sort(a, !b);
        return true
    },
    pick: function (c) {
        var b = Util.toggle(c.id);
        var a = $$(".sort_option");
        a.each(function (d) {
            if (d != c) {
                Sprite.src(d.down("img"), "downtick-spacer");
                d.onmouseout = null;
                d.onmouseover = null;
                Util.reset_toggle(d.id);
                d.href = BrowseURL.get_sort_url(d.id, false)
            } else {
                var e = b ? "up" : "down";
                Sprite.src(d.down("img"), "sort-" + e + "tick-on");
                d.onmouseout = function () {
                    Sprite.src(d.down("img"), "sort-" + e + "tick-off")
                };
                d.onmouseover = function () {
                    Sprite.src(d.down("img"), "sort-" + e + "tick-on")
                };
                d.href = BrowseURL.get_sort_url(d.id, b)
            }
        });
        return b
    },
    make_url: function (b, a) {
        return b + "," + (a ? 1 : 0)
    },
    last_url: "",
    url_sort: function () {
        var a = BrowseURL.get_sort();
        if (a && a.length) {
            var b = a.split(",");
            var c = document.getElementById(b[0]);
            if (!c) {
                return false
            }
            Util.set_next_toggle(c.id, b[1] == "1" ? true : false);
            c.onclick();
            return true
        }
        return false
    }
};
var Sort = {
    FILES_BY_NAME: function (b, c) {
        var a = c.dir - b.dir;
        if (a) {
            return a
        }
        return b.filename_ind - c.filename_ind
    },
    FILES_BY_KEY: function (c, e) {
        var b = e.dir - c.dir;
        if (b) {
            return b
        }
        var a = c.filename_key;
        var d = e.filename_key;
        return a < d ? -1 : (a > d ? 1 : 0)
    },
    FILES_BY_SIZE: function (b, c) {
        var a = c.dir - b.dir;
        if (a) {
            return a
        }
        if (b.dir) {
            return Sort.FILES_BY_NAME(b, c)
        }
        return b.bytes - c.bytes
    },
    FILES_BY_MODIFIED: function (a, d) {
        var c = a.ts;
        var b = d.ts;
        return c == b ? 0 : (c > b ? 1 : -1)
    }
};
var Browse = {
    listen: function (a) {
        $("browse-files").observe("mouseover", Browse.over);
        $("browse-files").observe("mouseout", Browse.out);
        $("browse-files").observe("mousedown", Browse.down);
        $("browse-files").observe("mouseup", Browse.up);
        $("browse-files").observe("click", Browse.click);
        $("browse-files").oncontextmenu = Browse.onContext;
        Browse.allow_drag = typeof(a) == "boolean" ? a : true
    },
    over: function (a) {
        var b = Util.resolve_target(a.target, ".browse-file-box-details");
        if (b && b.file) {
            if (!b.title) {
                b.title = b.file.filename
            }
            b.file.over(a)
        }
    },
    out: function (a) {
        var b = Util.resolve_target(a.target, ".browse-file-box-details");
        if (b && b.file) {
            b.file.out(a)
        }
    },
    down: function (a) {
        if (Browse.down_file) {
            return
        }
        var b = Util.resolve_target(a.target, ".browse-file-box-details");
        if (b && b.file) {
            Browse.down_file = b.file;
            b.file.down(a)
        }
    },
    up: function (a) {
        var b = Util.resolve_target(a.target, ".browse-file-box-details");
        if (b && b.file) {
            Browse.down_file = null;
            b.file.up(a)
        }
    },
    click: function (f) {
        var d = f.target;
        var h = Util.resolve_target(d, ".browse-file-box-details");
        if (h && h.file) {
            var b = h.file;
            var g = Util.resolve_target(d, "a");
            if (g) {
                if (b.dir) {
                    Event.stop(f);
                    var a, c;
                    if (b.target_ns) {
                        a = b.target_ns;
                        c = ""
                    } else {
                        if (Browse.is_share && b.where.length < Browse.parent_ns_path.length) {
                            a = "";
                            c = b.where
                        } else {
                            a = Browse.current_nsid;
                            c = Browse.fqpath_to_nspath(b.where, "click")
                        }
                    }
                    BrowseURL.set_path_url(a, c)
                }
            } else {
                if (b.filename && f.target.className.indexOf("checkbox") == -1) {
                    b.click_select(f)
                }
            }
        }
    },
    msg: false,
    files: [],
    selected_files: [],
    checked_files: [],
    drop_targets: [],
    selection: [],
    drag_watch: null,
    drag_end_watch: null,
    dragging: false,
    drag_startPos: null,
    drag_box: {},
    details: true,
    first_load: true,
    last_sort: [Sort.FILES_BY_NAME, false],
    highlight_index: -1,
    emptyCheck: function () {
        if (!Browse.files.length) {
            Browse.show_message(_("Folder contains deleted files."))
        }
    },
    show_message: function (c) {
        if (typeof(c) != typeof("string")) {
            var a = $("browse-files").down(".browse-message");
            if (a) {
                a.show()
            }
            return
        }
        Browse.msg = c;
        var b = new Element("div", {
            "class": "browse-message"
        });
        b.update(c);
        $("browse-files").insert(b)
    },
    hide_message: function () {
        $$(".browse-message").invoke("hide")
    },
    sort: function (b, a, c) {
        if (!c && b == Browse.last_sort[0] && a == Browse.last_sort[1]) {
            return
        }
        Browse.last_sort = [b, a];
        if (a) {
            var d = b;
            b = function (e, f) {
                return -1 * d(e, f)
            }
        }
        Browse.files.sort(b);
        Browse.drop_targets.sort(b);
        Browse.refill();
        Browse.refresh_positions();
        return false
    },
    resort: function (b) {
        BrowseKeys.clear_highlight();
        var a = Browse.last_sort;
        if (b) {
            Browse.fix_filename_keys(b)
        }
        Browse.sort(a[0], a[1], true);
        Browse.refresh_drop_positions()
    },
    fix_filename_keys: function (d) {
        var b = Browse.files.slice();
        b.sort(Sort.FILES_BY_KEY);
        for (var c = 0, a = b.length; c < a; c++) {
            b[c].filename_ind = c
        }
    },
    refill: function () {
        var b = $("browse-files");
        for (var c = 0; c < Browse.files.length; c += 1) {
            var a = Browse.files[c];
            b.insert(a.div);
            if (a.selected) {
                a.select()
            }
        }
    },
    add_file: function (b, a) {
        if (b.filename) {
            Browse.files.push(b)
        } else {
            Browse.has_parent_link = true;
            Browse.parent_link = b
        }
        if (!Browse.file_div) {
            Browse.file_div = $("browse-files")
        }
        b.render(a, b.href);
        b.cachePos.bind(b).defer();
        if (b.drop_target) {
            Browse.drop_targets.push(b)
        }
        if (b.bytes < 0) {
            Browse.deleted_shown = true
        }
    },
    refresh_drop_positions: function () {
        Browse.drop_targets.invoke("cachePos")
    },
    refresh_positions: function () {
        Browse.files.invoke("cachePos");
        if (Browse.has_parent_link) {
            Browse.parent_link.cachePos()
        }
        Browse.redraw_checks()
    },
    redraw_checks: function () {
        var b = Browse.checked_files.slice();
        for (var a = 0; a < b.length; a += 1) {
            b[a].decheck();
            b[a].check()
        }
    },
    remove_selected: function () {
        Browse.files.each(function (a) {
            if (a.selected) {
                a.div.remove()
            }
        });
        Browse.files = Browse.files.findAll(function (a) {
            return !a.selected
        });
        Browse.refresh_positions()
    },
    find_icons: function () {
        if (!Browse.files.length) {
            return
        }
        Browse.updateOffset();
        var b = Browse.files[0];
        if (b.box) {
            var a = b.box.top;
            b.cachePos()
        }
        if (!b.box || a != b.box.top) {
            Browse.refresh_positions()
        }
    },
    cache_selection: function () {
        Browse.selection = Browse.files.pluck("selected")
    },
    get_selected: function () {
        return Browse.selected_files
    },
    check_all: function () {
        BrowseActions.kill_dropdowns();
        var c = Browse.files;
        var b = c.length;
        Browse.deselect_all();
        if (Browse.checked_files.length == b) {
            Browse.decheck_all()
        } else {
            for (var a = 0; a < b; a += 1) {
                if (!c[a].checked) {
                    c[a].check(a)
                }
            }
            if (Browse.checked_files.length == b) {
                DBCheckbox.select(Browse.global_checkbox())
            }
        }
    },
    check_range: function (f, a, e) {
        var d = f > a ? -1 : 1;
        for (var c = f; c != a + d; c += d) {
            var b = Browse.files[c];
            if (e && b.checked) {
                b.decheck()
            } else {
                if (!e && !b.checked) {
                    b.check()
                }
            }
        }
    },
    uncheck_range: function (b, a) {
        Browse.check_range(b, a, true)
    },
    check_these: function (a) {
        for (var b = 0; b < a.length; b += 1) {
            a[b].check()
        }
    },
    hide_checked: function () {
        Browse.hidden_checked_files = Browse.checked_files.slice();
        Browse.decheck_all()
    },
    restore_checked: function () {
        Browse.check_these(Browse.hidden_checked_files);
        Browse.hidden_checked_files = false
    },
    decheck_all: function () {
        var a = Browse.checked_files;
        var b = a.length;
        while (b--) {
            a[b].decheck(b, true)
        }
        Browse.checked_files = [];
        Browse.deselect_all()
    },
    watch_for_deselect: function () {
        Event.observe(document.body, "click", function (a) {
            if (a.which !== 1 && a.button !== 0) {
                return
            }
            if (a.target.nodeType == 3 || (a.target.tagName.toLowerCase() != "a" && a.target.parentNode && a.target.parentNode.tagName.toLowerCase() != "a")) {
                Browse.deselect_all()
            }
        })
    },
    deselect_all: function () {
        BrowseActions.clear();
        var b = Browse.selected_files.length;
        for (var a = 0; a < b; a += 1) {
            Browse.selected_files[0].deselect()
        }
    },
    deselect_all_but: function (a) {
        Browse.deselect_all();
        a.select()
    },
    clicked_scrollbar: function (g) {
        var a = $("browse-files");
        var f = a.viewportOffset();
        var d = f.left + a.clientWidth;
        var c = f.left + a.offsetWidth;
        return d < g.clientX && g.clientX < c
    },
    drag_start: function (a) {
        return
    },
    drag: function (b) {
        if (!Browse.dragging) {
            return
        }
        Event.stop(b);
        var a = Browse.drag_box;
        Util.calcBox(b.clientY, b.clientX, Browse.drag_startPos.top, Browse.drag_startPos.left, a);
        Browse.draw_box(a);
        a.ctrl = b.ctrlKey;
        a.shift = b.shiftKey;
        if (a.width + a.height > 10) {
            Browse.select_under.defer()
        }
    },
    select_under: function () {
        var c = Browse.drag_box;
        var b = c.shift;
        var e = c.ctrl;
        if (!Browse.dragging) {
            return
        }
        for (var a = 0; a < Browse.files.length; a++) {
            var d = Browse.files[a];
            if (d.overlaps(c)) {
                if (e) {
                    d.toggle(Browse.selection[a])
                } else {
                    d.select()
                }
            } else {
                if (e) {
                    d.set(Browse.selection[a])
                } else {
                    if (!b) {
                        d.deselect()
                    }
                }
            }
        }
    },
    select_range_to: function (g, b) {
        var a = Browse.shift_start;
        if (!a) {
            Browse.shift_start = g;
            g.select()
        } else {
            var e = false;
            for (var c = 0; c < Browse.files.length; c++) {
                var d = Browse.files[c];
                if (!b) {
                    d.set(e)
                } else {
                    if (e) {
                        d.select()
                    }
                }
                if (d == g || d == a) {
                    d.select();
                    e = !e
                }
            }
        }
    },
    drag_end: function (b) {
        if (b) {
            var a = Browse.drag_box;
            if (a.width + a.height < 10) {
                Browse.deselect_all()
            }
        }
        Browse.dragging = false;
        Event.stopObserving(document, "mousemove", Browse.drag_watch);
        Event.stopObserving(document, "mouseup", Browse.drag_end_watch);
        Browse.drag_watch = null;
        $("browse-selection").hide()
    },
    draw_box: function (b) {
        var a = $("browse-selection").style;
        a.top = b.top + "px";
        a.left = b.left + "px";
        a.width = b.width + "px";
        a.height = b.height + "px";
        a.display = ""
    },
    clone_selected: function (h) {
        Browse.sel_clones = $A();
        Browse.sel_clone_origin = {
            y: h.clientY,
            x: h.clientX,
            st: Util.scrollTop(),
            sl: Util.scrollLeft()
        };
        Util.scry("ghost-icons").update("");
        for (var a = 0; a < Browse.selected_files.length; a++) {
            var b = Browse.selected_files[a];
            var j = b.div.cloneNode(true);
            j.file = null;
            j.hide();
            j.absolutize();
            b.cachePos();
            var g = b.box;
            var d = g.top + Util.scrollTop();
            var c = g.left + Util.scrollLeft();
            j.style.top = d + "px";
            j.style.left = c + "px";
            j.style.width = g.width + "px";
            j.style.height = g.height + "px";
            j.removeClassName("file-select");
            j.removeClassName("file-highlight");
            j.removeClassName("file-selected-highlight");
            j.origin = {
                top: d,
                left: c
            };
            j.setOpacity(0.5);
            Util.scry("ghost-icons").insert(j);
            Browse.sel_clones.push(j)
        }
    },
    draw_clones: function (g) {
        if (!this.sel_clone_origin) {
            return
        }
        var b = g.clientX - this.sel_clone_origin.x;
        var a = g.clientY - this.sel_clone_origin.y;
        var f = Util.scrollTop() - this.sel_clone_origin.st;
        var c = Util.scrollLeft() - this.sel_clone_origin.sl;
        for (var d = 0; d < Browse.sel_clones.length; d += 1) {
            var h = Browse.sel_clones[d];
            h.style.display = "";
            h.style.top = (h.origin.top + a + f).toString() + "px";
            h.style.left = (h.origin.left + b + c).toString() + "px"
        }
    },
    kill_clones: function () {
        if (this.sel_clones) {
            this.sel_clones.map(Util.yank);
            this.sel_clones = null;
            this.sel_clone_origin = null
        }
    },
    find_drop_target: function (c) {
        if (!Browse.sel_clone_origin) {
            return
        }
        var a = c.clientX + Util.scrollLeft() - Browse.sel_clone_origin.sl;
        var d = c.clientY + Util.scrollTop() - Browse.sel_clone_origin.st;
        var b = Util.bsearch(Browse.drop_targets, 0, function (e) {
            var g = Util.cmpBox(a, d, e.box);
            return (g !== 0) ? -g : (e.selected ? -1 : 0)
        });
        if (b != -1) {
            return Browse.drop_targets[b]
        }
        return false
    },
    can_drop: function (a) {
        var b = Browse.profile_files(Browse.selected_files);
        if ((a.is_share || a.is_sandbox) && (b.shared_folders > 0 || b.sandboxes > 0)) {
            if (b.sandboxes > 0) {
                if (a.is_share) {
                    return _("You're not allowed to put an application folder inside a shared folder.")
                } else {
                    return _("You're not allowed to put an application folder inside another application folder.")
                }
            } else {
                if (a.is_share) {
                    return _("You're not allowed to nest shared folders.")
                } else {
                    return _("You're not allowed to put a shared folder inside an application folder.")
                }
            }
        } else {
            if (a.where == "/Public" && b.shared_folders > 0) {
                return _("You're not allowed to move shared folders to your Public folder.")
            } else {
                if (b.public_folder > 0) {
                    return _("You're not allowed to move your Public folder.")
                } else {
                    if (b.photos_folder > 0) {
                        return _("You're not allowed to move your Photos folder.")
                    } else {
                        if (b.deleted > 0) {
                            return _("Moving deleted folders or files is not allowed.")
                        }
                    }
                }
            }
        }
        return true
    },
    remove_drop_target: function (e) {
        var b = Browse.drop_targets;
        var a = b.length;
        var c = [];
        for (var d = 0; d < a; d++) {
            var f = b[d];
            if (e != f) {
                c.push(f)
            }
        }
        Browse.drop_targets = c
    },
    highlight_drop_target: function (b) {
        var a = Browse.find_drop_target(b);
        if (Browse.last_drop_target && Browse.last_drop_target != a) {
            Browse.last_drop_target.drop_lowlight()
        }
        Browse.last_drop_target = a;
        if (a) {
            if (Browse.can_drop(a) === true) {
                a.drop_highlight()
            } else {
                a.drop_highlight_bad()
            }
        }
    },
    show_copy_move: function (c) {
        if (Browse.copy_move_over == c) {
            return
        }
        Browse.copy_move_over = c;
        var a = Browse.copy_move_texts();
        var b = Browse.copy_move_overlays();
        var d = b.concat(a);
        var f = c.box.left + Browse.sel_clone_origin.sl;
        var e = c.box.top + Browse.sel_clone_origin.st;
        if (c.box.height > c.box.width) {
            d.each(function (g) {
                var h = g.style;
                h.width = this.box.width + "px";
                h.height = Math.round(this.box.height / 2) + "px";
                h.left = f + "px";
                h.display = "";
                h.lineHeight = h.height
            }, c);
            b[0].style.top = e + "px";
            b[1].style.top = (e + Math.round(c.box.height / 2)) + "px";
            a[0].style.top = e + "px";
            a[1].style.top = (e + Math.round(c.box.height / 2)) + "px"
        } else {
            d.each(function (g) {
                var h = g.style;
                h.height = this.box.height + "px";
                h.width = Math.round(this.box.width / 2) + "px";
                h.top = e + "px";
                h.display = "";
                h.lineHeight = h.height
            }, c);
            b[0].style.left = f + "px";
            b[1].style.left = (f + Math.round(c.box.width / 2)) + "px";
            a[0].style.left = f + "px";
            a[1].style.left = (f + Math.round(c.box.width / 2)) + "px"
        }
        a[0].box = Util.getBox(a[0]);
        a[1].box = Util.getBox(a[1])
    },
    bold_copy_move: function (c) {
        var b = Browse.copy_move_texts();
        var a = 0;
        if (c.clientY > b[1].box.top) {
            a = 1
        }
        if (b[0].last_highlight == a) {
            return
        }
        b[0].last_highlight = a;
        b[a].addClassName("copy-move-bold");
        b[1 - a].removeClassName("copy-move-bold")
    },
    hide_copy_move: function () {
        Browse.copy_move_over = false;
        Browse.copy_move_overlays().invoke("hide");
        Browse.copy_move_texts().invoke("hide")
    },
    over_copy_option: function (a) {
        return Util.pointOnBox(a.clientX, a.clientY, Util.getBox("copy-text"))
    },
    cmos: [],
    copy_move_overlays: function () {
        if (!Browse.cmos.length) {
            Browse.cmos = $$(".copy-move-overlay")
        }
        return Browse.cmos
    },
    cmts: [],
    copy_move_texts: function () {
        if (!Browse.cmts.length) {
            Browse.cmts = $$(".copy-move-text")
        }
        return Browse.cmts
    },
    find_file: function (a) {
        return Browse.files.find(function (b) {
            return b.where == a
        })
    },
    pull_file: function (c) {
        var g = Browse.files;
        var a = g.length;
        var b = [];
        var e = false;
        for (var d = 0; d < a; d++) {
            var h = g[d];
            if (h.where == c) {
                e = h
            } else {
                b.push(h)
            }
        }
        Browse.files = b;
        return e
    },
    reset_state: function () {
        Browse.msg = false;
        Browse.dragging = false;
        Browse.files = [];
        Browse.selected_files = [];
        Browse.checked_files = [];
        Browse.lact_checked = null;
        Browse.sel_clones = [];
        Browse.sel_clone_origin = null;
        Browse.drop_targets = [];
        Browse.last_drop_target = null;
        Browse.selection = [];
        Browse.file_div_cache = null;
        Browse.has_parent_link = false;
        Browse.parent_link = null;
        Browse.in_placer = null;
        BrowseActions.kill_dropdowns()
    },
    update: function (a) {
        $("browse-files").update(a)
    },
    reload_fqpath: function (a) {
        return Browse.reload(null, a)
    },
    force_reload: function () {
        return Browse.reload(Browse.current_nsid, Browse.current_path, true)
    },
    reload: function (b, f, e) {
        if (Browse.reloading) {
            return
        }
        b = b || "";
        f = Util.normPath(f || "");
        if (Util.normPath(f) == Util.normPath(Browse.current_path) && b == Browse.current_nsid && !e) {
            return
        }
        if (!f && f !== "" && !b) {
            f = Browse.current_path;
            b = Browse.current_nsid
        }
        Browse.reloading = true;
        Browse.current_path = f;
        Browse.current_nsid = b;
        var d = Browse.first_load ? Constants.referrer : "";
        if (Browse.first_load) {
            Browse.first_load = false;
            BrowseURL.set_path_url(b, f)
        }
        Feed.showLoading(false, "browse-files", true);
        if (Util.ie) {
            $("feed-loading").style.left = $("browse-box").viewportOffset()[0] + "px"
        }
        var c = Browse.deleted_shown ? "&show_deleted=yah" : "";
        var a = new Ajax.DBRequest("/browse2" + Util.normalize(f) + "?ajax=yes" + c, {
            parameters: {
                ns_id: b,
                referrer: d
            },
            onSuccess: function (g) {
                Browse.reset_state();
                Browse.update(g.responseText);
                if (Browse.select_file) {
                    (function () {
                        var j = Browse.current_fqpath() + "/" + Util.urlquote(Browse.select_file);
                        var i = Browse.find_file(j);
                        if (i) {
                            i.select();
                            i.show_dropdown();
                            Browse.select_file = false
                        }
                    }).defer()
                }
                var h = Browse.global_checkbox();
                if (h.selected) {
                    DBCheckbox.deselect(h)
                }
                if (Browse.force_sort) {
                    Browse.force_sort = false;
                    Browse.resort.defer()
                }
                Browse.listen()
            },
            cleanUp: function () {
                Feed.hideLoading();
                Browse.reloading = false;
                if (document.activeElement && document.activeElement != document.body) {
                    document.activeElement.blur()
                }
                Util.childElementCache = {}
            },
            no_feed_reload: true
        });
        FileSearch.invalidate_cache();
        BrowseKeys.clear_highlight();
        return true
    },
    unload: function () {
        Browse.reset_state();
        var a = $("dropdown");
        if (a) {
            a = Util.yank(a)
        }
    },
    breadcrumb: function (m) {
        m = Util.normPath(m);
        var c = m.split("/");
        var h = "";

        function a(n, i, r, q, s, o) {
            n = n.snippet(40);
            if (!(s || q)) {
                o = ""
            } else {
                o = '<img src="images/icons/icon_spacer.gif" class="sprite s_' + o + ' link-img"  alt=""/>'
            }
            var p;
            if (!q) {
                p = "<a href='" + BrowseURL.get_path_url(i, r) + "'";
                p += " onclick='return BrowseURL.set_path_url(\"" + i + '", "' + r + "\");'";
                p += ">";
                p += o + n;
                p += "</a>";
                p = p + " &#187; ";
                return p
            } else {
                return o + n
            }
        }
        assert(!Browse.current_nsid || Browse.parent_ns_path, "in some nsid but no parent path set");
        var g, e;
        for (var d = 0; d < c.length; d++) {
            var b = new Emstring(decodeURIComponent(c[d] || _("Dropbox")).escapeHTML()).toString();
            var l = d + 1 === c.length;
            var f = d === 0;
            g = c.slice(0, d + 1).join("/") || "/";
            if (Browse.current_nsid && g.length >= Browse.parent_ns_path.length) {
                e = Browse.current_nsid
            } else {
                e = ""
            }
            var k = !e ? g : Browse.fqpath_to_nspath(g, "breadcrumb");
            var j = f && b.toString() == _("Dropbox") ? "dropbox" : FileOps.folder_to_icon(Browse.current_fqpath(), Browse.is_share, Browse.is_sandbox);
            h += a(b, e, k, l, f, j)
        }
        $("browse-location").update(h)
    },
    viewportOffset: function () {
        if (!Browse.files.length) {
            return
        }
        if (!Browse.div_parent) {
            var c = Browse.files[0].div.offsetParent;
            if (!c) {
                return
            }
            Browse._viewportOffset = {};
            Browse.div_parent = $(c);
            Browse._cumulativeOffset = Browse.div_parent.cumulativeOffset()
        }
        var a = Util.scrollLeft(Browse.div_parent);
        var b = Util.scrollTop(Browse.div_parent);
        if (!Browse.scrollTop || !Browse.scrollLeft || Browse.scrollTop != b || Browse.scrollLeft != a) {
            Browse._viewportOffset.top = Browse._cumulativeOffset.top - b;
            Browse._viewportOffset.left = Browse._cumulativeOffset.left - a;
            Browse.scrollLeft = a;
            Browse.scrollTop = b
        }
        return Browse._viewportOffset
    },
    watch_for_resize: function () {
        Event.observe(window, "resize", Browse.updateOffset)
    },
    updateOffset: function () {
        if (!Browse.div_parent) {
            return
        }
        Browse._cumulativeOffset = Browse.div_parent.cumulativeOffset();
        Browse.viewportOffset()
    },
    selectable: function () {
        Util.enableSelection(Util.scry("browse-files"))
    },
    unselectable: function () {
        Util.disableSelection(Util.scry("browse-files"))
    },
    profile_files: function (a) {
        var d = {
            files: 0,
            folders: 0,
            shared_folders: 0,
            deleted: 0,
            public_folder: 0,
            photos_folder: 0,
            rejoinables: 0,
            sandboxes: 0
        };
        for (var c = 0; c < a.length; c += 1) {
            var b = a[c];
            if (b.dir) {
                d.folders += 1
            } else {
                d.files += 1
            }
            if (b.is_sandbox) {
                d.sandboxes += 1
            }
            if (b.is_share) {
                d.shared_folders += 1
            }
            if (b.bytes == -1) {
                d.deleted += 1
            }
            if (b.where == "/Public") {
                d.public_folder = 1
            } else {
                if (b.where == "/Photos") {
                    d.photos_folder = 1
                }
            }
            if (b.main_actions.indexOf("rejoin") >= 0) {
                d.rejoinables += 1
            }
        }
        return d
    },
    profile_summary: function (b) {
        var c = ungettext("%d file", "%d files", b.files).format(b.files);
        var a = ungettext("%d folder", "%d folders", b.folders).format(b.folders);
        if (b.files && b.folders) {
            return _("%(x_files)s and %(y_folders)s").format({
                x_files: c,
                y_folders: a
            })
        } else {
            if (b.files) {
                return c
            } else {
                if (b.folders) {
                    return a
                } else {
                    return ""
                }
            }
        }
    },
    global_checkbox: function () {
        return Util.childElement(document.getElementById("select-all-sorter"), 0)
    },
    onContext: function (a) {
        if (a) {
            Event.stop(a)
        }
        return false
    },
    current_fqpath: function () {
        return Util.normPath((Browse.parent_ns_path || "") + Browse.current_path)
    },
    fqpath_to_nspath: function (b, c) {
        var a = Browse.parent_ns_path || "";
        assert(decodeURIComponent(b.toLowerCase()).startsWith(decodeURIComponent(a.toLowerCase())), "fqpath " + b + " and parent_ns_path " + a + " don't match (from " + (c || "?") + ")");
        return b.substr(a.length)
    }
};
var BrowseFile = Class.create({
    initialize: function (q, h, n, p, m, k, j, f, a, i, c, l, b, o, e, d, g, r) {
        this.icon = q;
        this.caption = p;
        this.filename = m;
        this.where = h;
        this.hash = c;
        this.href = n;
        this.size = k != "None" ? k : "";
        this.bytes = j;
        this.ago = f;
        this.ts = a;
        this.selected = false;
        this.drop_target = b;
        this.dir = l ? 1 : 0;
        this.is_share = q == "folder_user";
        this.is_sandbox = q == "folder_star";
        this.tkey = e;
        this.target_ns = d;
        this.main_actions = i.strip().replace("  ", " ").split(" ");
        this.filename_ind = g || 0;
        this.filename_key = r || [];
        Browse.add_file(this, o)
    },
    drag_dist: function (a) {
        return Math.abs(this.drag_startPos.x - a.clientX) + Math.abs(this.drag_startPos.y - a.clientY)
    },
    render: function (c, e) {
        var d;
        if (c) {
            d = new Element("div", {
                "class": Browse.details ? "browse-file-box-details" : "browse-file-box-iconic"
            });
            this.div = d;
            var a = this.bytes != "-1" ? "" : " deleted_file_line";
            var b = e ? e : "#";
            this.div.update(" <div style='position:relative;'><div class='details-check'><img class='sprite s_checkbox checkbox' src='images/icons/icon_spacer.gif' align='absbottom'></div> <div class='details-icon'><a><img class='sprite s_" + this.icon + "' src='images/icons/icon_spacer.gif' align='absbottom'></a></div><div class='details-filename" + a + "'><a href='" + b + "'>" + this.caption + "</a></div> <div class='details-size'>" + (this.size || "&nbsp;") + "</div> <div class='details-modified'>" + this.ago + "</div> <a class='dropdown-arrow' style='visibility: hidden;' href='#'><img src='images/big-dropdown.gif'></a><br class='clear'/><div class='miniscule-text' style='line-height: 1px'>&nbsp;</div></div>");
            (function () {
                DBCheckbox.register(this.div.down("img"))
            }).bind(this).defer()
        } else {
            if (!Browse.file_div_cache) {
                Browse.file_div_cache = Browse.file_div.childElements()
            }
            d = Browse.file_div_cache[Browse.files.length - (Browse.has_parent_link ? 0 : 1)];
            this.div = d
        }
        d.file = this;
        return d
    },
    tooltip: function () {
        if (this.caption.unescapeHTML() != this.filename && this.filename.length) {
            Tooltip.show(this.a, this.filename)
        }
    },
    rename: function (d, e, h, c) {
        var f = FileOps.filename(encodeURIComponent(d));
        this.caption = f.snippet();
        this.filename = f;
        this.where = Util.urlquote(d);
        this.hash = h;
        this.filename_key = c;
        this.ago = e ? "" : _("just now");
        if (e) {
            this.href = BrowseURL.get_path_url(this.target_ns, this.target_ns ? "" : this.where)
        } else {
            var g = this.href.split("/");
            g[g.length - 1] = Util.urlquote(f) + "?w=" + h;
            this.href = g.join("/")
        }
        var b = this.div.down(".details-filename").down("a");
        b.update(this.caption);
        b.title = this.filename;
        b.href = this.href;
        if (this.main_actions.contains("view_token")) {
            this.main_actions.removeItem("view_token");
            this.main_actions.push("token_share")
        }
    },
    move: function (b) {
        var a = new Effect.Fade(this.div, {
            afterFinish: b
        })
    },
    del: function (d) {
        if (!Browse.deleted_shown) {
            var b = new Effect.Fade(this.div, {
                afterFinish: d
            });
            Browse.emptyCheck()
        } else {
            this.size = "None";
            this.bytes = -1;
            this.ago = this.dir ? "" : _("just now");
            this.main_actions = this.dir ? ["full_restore"] : "undelete purge".split(" ");
            var c = this.div.down("a");
            c.addClassName("deleted_file_line");
            if (this.dir) {
                Sprite.src(this.div.down("img"), "folder_gray")
            }
        }
    },
    purge: function (b) {
        var a = new Effect.Fade(this.div, {
            afterFinish: b
        });
        Browse.emptyCheck()
    },
    setOpacity: function () {
        if (this.size == "None") {
            this.div.down("div").down("img").setOpacity(0.5)
        }
    },
    cachePos: function () {
        if (!this.div) {
            return
        }
        if (!this.box) {
            this.box = {}
        }
        var a = Browse.viewportOffset();
        if (!a) {
            return
        }
        this.box.left = a.left + this.div.offsetLeft;
        this.box.top = a.top + this.div.offsetTop;
        if (!this.box.width) {
            this.box.width = this.div.getWidth();
            this.box.height = this.div.getHeight()
        }
    },
    overlaps: function (a) {
        return Util.boxOnBox(a, this.box)
    },
    over: function () {
        if (Browse.dragging) {
            return
        }
        if (!this.editing && this.filename && (!this.checked || (this.checked && Browse.checked_files.length == 1))) {
            this.dropdown_arrow(true)
        }
        if (!this.selected) {
            this.div.addClassName("file-highlight")
        }
    },
    out: function (a) {
        if (!this.div) {
            return
        }
        if (a.toElement) {
            if (a.toElement.className == "tooltip" || $(a.toElement) == this.div || $(a.toElement).descendantOf(this.div)) {
                return
            }
        }
        if (!this.selected) {
            this.div.removeClassName("file-highlight");
            if (this.filename) {
                this.dropdown_arrow(false)
            }
        } else {
            this.div.removeClassName("file-selected-highlight")
        }
    },
    down: function (a) {
        if (this.editing || !this.filename) {
            return
        }
        if (a) {
            Event.stop(a)
        }
        this.click_select(a);
        Browse.find_icons();
        BrowseActions.kill_dropdowns();
        this.drag_startPos = {
            x: a.clientX,
            y: a.clientY
        };
        this.drag_watch = this.drag.bindAsEventListener(this);
        this.up_watch = this.up.bindAsEventListener(this);
        Event.observe(document, "mousemove", this.drag_watch);
        Event.observe(document, "mouseup", this.up_watch)
    },
    show_dropdown: function () {
        BrowseActions.kill_dropdowns();
        if (!this.checked || Browse.checked_files.length == 1 && this.checked) {
            this.dropdown_arrow(true);
            BrowseActions.dropdown(this, true)
        } else {
            BrowseActions.showMore()
        }
    },
    down_dropdown: function (a) {
        this.click_select(a);
        this.show_dropdown(true)
    },
    up: function (a) {
        if (this.editing || !this.filename) {
            return
        }
        if (!Browse.dragging) {
            this.deselect()
        }
        Event.stop(a);
        var b = this.drag_end(a);
        if (a.target.tagName == "IMG" && $(a.target).hasClassName("checkbox")) {
            this.click_check(a)
        } else {
            if (!b && (a.target.tagName != "A" && a.target.parentNode && a.target.parentNode.tagName != "A" || Util.is_right_click(a))) {
                this.click_select(a);
                this.show_dropdown()
            }
        }
        Event.stopObserving(document, "mousemove", this.drag_watch);
        Event.stopObserving(document, "mouseup", this.up_watch)
    },
    click_check: function (c) {
        Browse.deselect_all();
        var a = $("dropdown");
        if (a) {
            Util.yank(a)
        }
        var b = c.shiftKey;
        if (b && Browse.last_checked) {
            if (this.checked) {
                Browse.uncheck_range(Browse.files.indexOf(Browse.last_checked), Browse.files.indexOf(this))
            } else {
                Browse.check_range(Browse.files.indexOf(Browse.last_checked), Browse.files.indexOf(this))
            }
        } else {
            if (!this.checked) {
                this.check()
            } else {
                if (this.checked) {
                    this.decheck()
                }
            }
        }
        Browse.last_checked = this
    },
    click_select: function (a) {
        Event.stop(a);
        if (false && a.shiftKey && a.ctrlKey) {
            Browse.select_range_to(this, true)
        } else {
            if (false && a.shiftKey) {
                Browse.select_range_to(this)
            } else {
                if (false && a.ctrlKey) {
                    this.toggle();
                    this.over()
                } else {
                    if (!this.selected) {
                        Browse.deselect_all();
                        this.select()
                    }
                }
            }
        }
        if (false && (!a.shiftKey || a.ctrlKey)) {
            Browse.shift_start = this
        }
    },
    drag: function (b) {
        Event.stop(b);
        var a = this.drag_dist(b);
        if (!Browse.allow_drag) {
            return
        }
        if (!Browse.dragging && a >= 10) {
            this.drag_start(b)
        }
        if (a < 10) {
            return
        }
        Browse.dragging = true;
        Browse.draw_clones(b);
        Browse.highlight_drop_target(b)
    },
    drag_start: function (b) {
        Browse.dragging = true;
        if (Browse.checked_files.length > 0 && Browse.checked_files.indexOf(this) == -1) {
            Browse.hide_checked()
        } else {
            if (Browse.checked_files.indexOf(this) > -1) {
                for (var a = 0; a < Browse.checked_files.length; a += 1) {
                    Browse.checked_files[a].select()
                }
            }
        }
        this.select();
        Browse.clone_selected(b);
        Util.noHorizScroll()
    },
    drag_end: function (d) {
        if (!Browse.dragging) {
            return false
        }
        Browse.dragging = false;
        var c = Browse.find_drop_target(d);
        Util.allowHorizScroll();
        var g = false;
        if (c) {
            c.drop_lowlight();
            var b = Browse.can_drop(c);
            if (b !== true) {
                Notify.ServerError(b)
            } else {
                if (c != Browse.down_file) {
                    assert(Browse.selected_files.length > 0, "Tried to move 0 files by dragging");
                    var a = c;
                    FileOps.show_move_confirm(Browse.selected_files.slice(), decodeURIComponent(a.where));
                    BrowseActions.kill_dropdowns();
                    Browse.down_file = null;
                    g = true
                }
            }
        }
        if (Browse.hidden_checked_files) {
            Browse.restore_checked()
        }
        Browse.deselect_all();
        Browse.kill_clones(d);
        Browse.down_file = null;
        return g
    },
    highlight: function () {
        var a = document.viewport.getHeight();
        var c = this.div.viewportOffset();
        if (c.top < 0) {
            this.div.scrollIntoView(true)
        } else {
            if (c.top + this.div.getHeight() > a) {
                this.div.scrollIntoView(false)
            }
        }
        var b = $("highlight-arrow");
        b.show();
        b.clonePosition(this.div, {
            setWidth: false,
            setHeight: false,
            offsetLeft: -17,
            offsetTop: 6
        })
    },
    dehighlight: function () {
        $("highlight-arrow").hide()
    },
    check: function (e) {
        if (this.editing) {
            return false
        }
        var d = this.div;
        assert(!this.checked, "Tried to check a file that was already checked.");
        this.checked = true;
        this.checkbox = $(this.checkbox || Util.childElementByIndexPath(d, [0, 0, 0]));
        DBCheckbox.select(this.checkbox);
        d.addClassName("file-select");
        Browse.checked_files.push(this);
        e = e || Browse.files.indexOf(this);
        var c = Browse.files;
        var b = c[e - 1];
        var a = c[e + 1];
        if (b && b.checked) {
            d.style.borderWidth = "0 1px 1px 1px";
            d.style.paddingTop = "4px"
        }
        if (a && a.checked) {
            a.div.style.borderWidth = "0 1px 1px 1px";
            a.div.style.paddingTop = "4px"
        }
    },
    decheck: function (d, b) {
        if (this.editing) {
            return false
        }
        assert(this.checked, "Tried to decheck a file that was not checked.");
        this.checked = false;
        var c = Browse.global_checkbox();
        if (c.selected) {
            DBCheckbox.deselect(c)
        }
        DBCheckbox.deselect(this.checkbox);
        if (!b) {
            d = d || Browse.checked_files.indexOf(this);
            Browse.checked_files.remove(d)
        }
        var f = this.div;
        Util.removeClassName(this.div, "file-select");
        Util.removeClassName(this.div, "file-highlight");
        this.deselect();
        f.style.borderWidth = "1px";
        f.style.paddingTop = "";
        if (!b) {
            var e = Browse.files.indexOf(this);
            var a = Browse.files[e + 1];
            if (a && a.checked) {
                a.div.style.borderWidth = "1px";
                a.div.style.paddingTop = ""
            }
        }
    },
    select: function () {
        if (!this.selected) {
            this.selected = true;
            this.div.addClassName("file-select");
            Browse.selected_files.push(this)
        }
    },
    deselect: function () {
        if (this.selected) {
            Browse.selected_files.remove(Browse.selected_files.indexOf(this));
            this.selected = false;
            var a = this.div;
            if (!this.checked) {
                this.div.removeClassName("file-select");
                this.div.removeClassName("file-highlight");
                this.div.removeClassName("file-selected-highlight");
                this.dropdown_arrow(false)
            }
        }
    },
    toggle: function (a) {
        if (a === undefined) {
            a = this.selected
        }
        if (a) {
            return this.deselect()
        } else {
            return this.select()
        }
    },
    set: function (a) {
        return this.toggle(!a)
    },
    drop_highlight: function () {
        this.div.addClassName("drop-highlight")
    },
    drop_highlight_bad: function () {
        this.div.addClassName("drop-highlight-bad")
    },
    drop_lowlight: function () {
        this.div.removeClassName("drop-highlight");
        this.div.removeClassName("drop-highlight-bad")
    },
    dropdown_arrow: function (a) {
        if (this.div) {
            if (a) {
                if (this.div.select(".dropdown-arrow").length) {
                    this.div.select(".dropdown-arrow")[0].style.visibility = "visible"
                }
            } else {
                if (this.div.select(".dropdown-arrow").length) {
                    this.div.select(".dropdown-arrow")[0].style.visibility = "hidden"
                }
            }
        }
    },
    edit: function (g) {
        if (Browse.in_placer) {
            Browse.in_placer.file.editing = false;
            Browse.in_placer.editor.dispose();
            Browse.in_placer.name.innerHTML = Browse.in_placer.name_old_innerHTML;
            if (Browse.in_placer.new_folder) {
                Browse.in_placer.file.del(Browse.show_message)
            }
            Browse.in_placer = null
        }
        Browse.selectable();
        this.editing = true;
        var b = this.div.down(".details-filename").down("a");
        var e = b.innerHTML;
        b.innerHTML = this.filename.escapeHTML();
        var f = g ? "new" : "rename";
        var a = g ? _("Create") : _("Rename");
        var d = this.dir ? "yes" : "";
        var c = new Ajax.InPlaceEditor(b, "/cmd/" + f + Util.normalize(this.where) + "?long_running", {
            okControl: "link",
            cancelControl: "link",
            htmlResponse: false,
            highlightColor: "#ddf0ff",
            highlightEndColor: "#fafdff",
            okText: a,
            cancelText: _("Cancel"),
            clickToEditText: "",
            cols: 25,
            callback: function (h, i) {
                i = i.gsub("/", ":");
                return {
                    to_path: i,
                    t: Constants.TOKEN,
                    folder: d
                }
            },
            ajaxOptions: {
                method: "post"
            },
            onComplete: (function (p) {
                if (p) {
                    TranslationSuggest.update_i18n_messages_from_req(p);
                    var l = p.status.toString().charAt(0);
                    if (l == "5" || l == "4") {
                        return
                    }
                }
                Browse.unselectable();
                c.dispose();
                this.editing = false;
                Browse.in_placer = null;
                if (!p) {
                    if (g) {
                        this.purge(Browse.show_message)
                    } else {
                        b.innerHTML = e
                    }
                    return
                }
                if (p.responseText.indexOf("err:") === 0) {
                    Notify.ServerError(p.responseText.substr(4));
                    c.dispose();
                    this.editing = false;
                    Browse.in_placer = null;
                    Browse.unselectable();
                    if (g) {
                        this.del(Browse.show_message)
                    } else {
                        this.rename(decodeURIComponent(this.where), d, this.hash)
                    }
                } else {
                    var h = p.responseText.split(":");
                    var i = h.slice(0, -2).join(":");
                    var o = h[h.length - 2];
                    var m = h[h.length - 1].evalJSON();
                    if (g) {
                        var k = Browse.find_file(Util.urlquote(i));
                        if (k && k.bytes.toString() == "-1") {
                            k.purge()
                        }
                    }
                    if (Browse.reload_on_rename) {
                        Browse.force_reload()
                    } else {
                        this.rename(i, d, o, m);
                        Browse.resort(this);
                        this.div.scrollTo()
                    }
                    if (f == "new") {
                        var n = _("The folder '%(folder_name)s' was created successfully.").format({
                            folder_name: FileOps.filename(i).escapeHTML()
                        });
                        Notify.ServerSuccess(n)
                    } else {
                        if (f == "rename") {
                            var j = d ? _("Folder renamed to %(new_name)s.") : _("File renamed to %(new_name)s.");
                            j = j.format({
                                new_name: FileOps.filename(i).escapeHTML()
                            });
                            Notify.ServerSuccess(j)
                        }
                    }
                    TreeView.schedule_reset()
                }
            }).bind(this),
            onFailure: (function () {
                c.dispose();
                this.editing = false;
                Browse.in_placer = null;
                Browse.unselectable();
                if (g) {
                    this.del(Browse.show_message)
                } else {
                    b.innerHTML = e
                }
                Notify.ServerError()
            }).bind(this)
        });
        c.enterEditMode();
        Browse.in_placer = {
            file: this,
            editor: c,
            new_folder: g,
            name: b,
            name_old_innerHTML: e
        }
    }
});
BrowseFile.make_basic = function (b, e, d, c) {
    var a = FileOps.raw_filename(b);
    return new BrowseFile("", b, Util.urlquote(b), a.snippet(), a, 0, 0, 0, 0, e, "", d, 0, 0, c)
};
var BrowseActions = {
    option_dict: {
        api_app_edit: {
            icon: "application_edit",
            text: _("Edit Settings"),
            onclick: function (a) {
                Event.stop(a);
                window.location.href = "/developers/edit?id=" + this.app_id
            }
        },
        api_app_remove: {
            icon: "application_delete",
            text: _("Remove Application"),
            onclick: function (a) {
                Apps.show_confirm(a, this.name, this.app_id, "delete_app", "delete")
            }
        },
        restore_sandbox: {
            icon: "folder_star",
            text: _("Restore App Folder"),
            onclick: function () {
                Apps.restore_sandbox(this.where)
            }
        },
        sharing_options: {
            icon: "folder_user",
            text: _("Shared folder options"),
            onclick: function (a) {
                Event.stop(a);
                Sharing.get_sharing_options(this.where)
            }
        },
        token_share_options: {
            icon: "link",
            text: _("Get shareable link"),
            onclick: function (a) {
                Event.stop(a);
                Modal.show_loading("cog", "Loading Share...");
                SharingModel.get_token(this.where, function (b) {
                    SharingModel.show_post_options(b)
                })
            }
        },
        view_token: {
            icon: "link",
            text: _("Get shareable link"),
            onclick: function () {
                var a = "/s/" + this.tkey;
                if (!this.is_dir) {
                    a += "/" + Util.urlquote(FileOps.filename(this.where))
                }
                window.location.href = a
            }
        },
        remove_share: {
            icon: "link_delete",
            text: _("Disable shareable link"),
            onclick: function () {
                SharingModel.confirm_remove(FileOps.filename(this.where), this.tkey, false, window.LinkController)
            }
        },
        share_here: {
            icon: "folder_user",
            text: _("Invite to folder"),
            onclick: function (a) {
                Sharing.show_share_existing_modal(Browse.current_fqpath());
                Event.stop(a)
            }
        },
        share_new: {
            icon: "folder_user",
            text: _("Share a folder"),
            onclick: function (a) {
                Sharing.start_wizard(a);
                Event.stop(a)
            }
        },
        share: {
            icon: "folder_user",
            text: _("Invite to folder"),
            onclick: function (a) {
                Sharing.show_share_existing_modal(this.where);
                Event.stop(a)
            }
        },
        share_invite_more: {
            icon: "group",
            text: _("Invite more people"),
            onclick: function (a) {
                Sharing.show_invite_more_modal(this.where);
                Event.stop(a)
            }
        },
        share_leave: {
            icon: "folder_user_delete",
            text: _("Leave shared folder"),
            onclick: function (a) {
                PAGE_PATH = this.where;
                Sharing.show_leave_modal(this.where);
                Event.stop(a)
            }
        },
        share_unshare: {
            icon: "link_break",
            text: _("Unshare this folder"),
            onclick: function (a) {
                PAGE_PATH = this.where;
                Sharing.show_unshare_modal(this.where);
                Event.stop(a)
            }
        },
        share_opts_here: {
            verb: "share",
            icon: "user_add",
            text: _("Sharing info")
        },
        share_opts: {
            verb: "share",
            icon: "user_add",
            text: _("Sharing info")
        },
        revisions: {
            verb: "revisions",
            icon: "time_back",
            text: _("Previous versions")
        },
        token_share: {
            icon: "link",
            text: _("Get shareable link"),
            onclick: function (a) {
                window.location = "/sm/create" + this.where
            }
        },
        undelete: {
            icon: "basket_remove",
            text: _("Undelete"),
            onclick: function (b) {
                Event.stop(b);
                var a = Browse.find_file(this.where);
                FileOps.show_undelete(a)
            }
        },
        copy_url: {
            icon: "world_link",
            text: _("Copy public link"),
            public_href: function () {
                return "http://" + Constants.PUBSERVER + "/u/" + Constants.uid + this.where.substring(7)
            },
            onclick: function (a) {
                BrowseActions.showCopyPublicUrlModal("http://" + Constants.PUBSERVER + "/u/" + Constants.uid + this.where.substring(7));
                Event.stop(a)
            }
        },
        download: {
            href: function () {
                return Constants.protocol + "://" + Constants.block + "/get" + this.where + this.hash + "&dl=1"
            },
            icon: "download_arrow",
            text: _("Download file")
        },
        view: {
            href: function () {
                return Constants.protocol + "://" + Constants.block + "/get" + this.where + this.hash
            },
            icon: "page_white_magnify",
            text: _("View file")
        },
        zipped_dl: {
            icon: "page_white_compressed",
            text: _("Download folder"),
            onclick: function (b) {
                var a = Browse.find_file(this.where);
                FileOps.do_bulk_download([a]);
                Event.stop(b)
            }
        },
        xattr_dl: {
            icon: "download_arrow",
            text: _("Download file"),
            onclick: function (b) {
                var a = Browse.find_file(this.where);
                FileOps.do_bulk_download([a]);
                Event.stop(b)
            }
        },
        photos: {
            href: function () {
                return "/photos" + this.where.substring(7)
            },
            icon: "pictures",
            text: _("Gallery")
        },
        a_photo: {
            href: function () {
                return "/photoshow" + this.where.substring(7)
            },
            icon: "pictures",
            text: _("Gallery view")
        },
        rejoin: {
            onclick: function () {
                var a = decodeURIComponent(this.where).toLowerCase();
                a = Util.normalize(a);
                assert(Browse.old_namespaces[a], "Rejoin missing ns");
                Sharing.rejoin(this.where, Browse.old_namespaces[a])
            },
            icon: "folder_user",
            text: _("Rejoin shared folder")
        },
        ignore: {
            onclick: function () {
                Sharing.ignore(this.where)
            },
            icon: "folder_user_delete",
            text: _("Permanently remove")
        },
        restore: {
            href: function () {
                return "/restore" + this.where + "?prev=" + encodeURIComponent(location.href)
            },
            icon: "time_go",
            text: _("Restore folder")
        },
        full_restore: {
            href: function () {
                return "/restore" + this.where + "?prev=" + encodeURIComponent(location.href)
            },
            icon: "time_back",
            text: _("Restore folder")
        },
        show_del: {
            onclick: function (a) {
                window.location.href = BrowseURL.get_del_url(true);
                Event.stop(a)
            },
            icon: "show_del",
            text: _("Show deleted files")
        },
        hide_del: {
            onclick: function (a) {
                window.location.href = BrowseURL.get_del_url(false);
                Event.stop(a)
            },
            icon: "hide_del",
            text: _("Hide deleted files")
        },
        copy: {
            icon: "page_white_copy",
            text: _("Copy to..."),
            onclick: function (a) {
                FileOps.show_copy(this.where);
                Event.stop(a)
            }
        },
        copy_folder: {
            icon: "folder_page",
            text: _("Copy to..."),
            onclick: function (a) {
                FileOps.show_copy(this.where, true);
                Event.stop(a)
            }
        },
        copy_package: {
            icon: "package_add",
            text: _("Copy package to..."),
            onclick: function (a) {
                FileOps.show_copy(this.where, true);
                Event.stop(a)
            }
        },
        move: {
            icon: "page_white_go",
            text: _("Move..."),
            onclick: function (a) {
                FileOps.show_move(this.where);
                Event.stop(a)
            }
        },
        move_folder: {
            icon: "folder_go",
            text: _("Move..."),
            onclick: function (a) {
                FileOps.show_move(this.where, true);
                Event.stop(a)
            }
        },
        move_package: {
            icon: "package_go",
            text: _("Move..."),
            onclick: function (a) {
                FileOps.show_move(this.where, true);
                Event.stop(a)
            }
        },
        rename: {
            icon: "page_white_edit",
            text: _("Rename..."),
            onclick: function (b) {
                var a = Browse.find_file(this.where);
                if (a) {
                    a.edit()
                }
                Event.stop(b)
            }
        },
        rename_folder: {
            icon: "folder_edit",
            text: _("Rename..."),
            onclick: function (b) {
                var a = Browse.find_file(this.where);
                if (a) {
                    a.edit()
                }
                Event.stop(b)
            }
        },
        rename_package: {
            icon: "package",
            text: _("Rename..."),
            onclick: function (b) {
                var a = Browse.find_file(this.where);
                if (a) {
                    a.edit()
                }
                Event.stop(b)
            }
        },
        "delete": {
            icon: "cancel",
            text: _("Delete..."),
            onclick: function (a) {
                FileOps.show_delete(this.where);
                Event.stop(a)
            }
        },
        delete_folder: {
            icon: "cancel",
            text: _("Delete..."),
            onclick: function (a) {
                FileOps.show_delete(this.where, true);
                Event.stop(a)
            }
        },
        delete_package: {
            icon: "cancel",
            text: _("Delete..."),
            onclick: function (a) {
                FileOps.show_delete(this.where, true);
                Event.stop(a)
            }
        },
        purge: {
            icon: "purge",
            text: _("Permanently delete"),
            onclick: function (a) {
                FileOps.show_purge(this.where);
                Event.stop(a)
            }
        },
        purge_folder: {
            icon: "purge",
            text: _("Permanently delete"),
            onclick: function (a) {
                FileOps.show_purge(this.where, true);
                Event.stop(a)
            }
        },
        new_folder: {
            icon: "folder_add",
            text: _("New folder"),
            onclick: function (a) {
                FileOps.inplace_new_folder(this.where);
                Event.stop(a);
                return false
            }
        },
        upload: {
            icon: "page_white_get",
            text: _("Upload"),
            onclick: function (a) {
                FileOps.show_upload(this.where);
                Event.stop(a)
            }
        },
        app_info: {
            icon: "application_double",
            text: _("Application info"),
            href: function () {
                return "/account/applications"
            }
        },
        more_actions: {
            text: function () {
                var a = _("More");
                var b = " <img src='images/icons/icon_spacer.gif' class='sprite s_big-dropdown icon_no_hover' style='margin-right:-4px;' alt=''/><img style='margin-right:-4px;' src='images/icons/icon_spacer.gif' class='sprite s_big-dropdown_blue icon_hover' alt=''/>";
                return a + b
            },
            onclick: function (a) {
                Event.stop(a, true);
                BrowseActions.showMore()
            }
        },
        move_bulk: {
            icon: "folder_go",
            text: function () {
                return _("Move %d items").format(Browse.checked_files.length)
            },
            onclick: function (a) {
                FileOps.show_move_bulk(Browse.checked_files);
                Event.stop(a)
            }
        },
        copy_bulk: {
            icon: "folder_page",
            text: function () {
                return _("Copy %d items").format(Browse.checked_files.length)
            },
            onclick: function (a) {
                FileOps.show_copy_bulk(Browse.checked_files);
                Event.stop(a)
            }
        },
        delete_bulk: {
            icon: "cancel",
            text: function () {
                return _("Delete %d items").format(Browse.checked_files.length)
            },
            onclick: function (a) {
                FileOps.show_bulk_delete(Browse.checked_files);
                Event.stop(a)
            }
        },
        download_bulk: {
            icon: "page_white_compressed",
            text: function () {
                return _("Download items")
            },
            onclick: function (a) {
                FileOps.do_bulk_download(Browse.checked_files);
                Event.stop(a)
            }
        },
        purge_bulk: {
            icon: "purge",
            text: _("Permanently delete"),
            onclick: function (a) {
                FileOps.show_bulk_purge(Browse.checked_files);
                Event.stop(a)
            }
        },
        restore_bulk: {
            icon: "time_go",
            text: function () {
                return _("Undelete %d items").format(Browse.checked_files.length)
            },
            onclick: function (a) {
                FileOps.show_bulk_restore(Browse.checked_files);
                Event.stop(a)
            }
        }
    },
    generate_li: function (f, k, d, g, i, h) {
        assert(BrowseActions.option_dict[k], "Couldn't find li action '" + k + "' for where '" + f + "'");
        var e = Object.clone(BrowseActions.option_dict[k]);
        e.where = f;
        e.hash = d ? "?w=" + d : "";
        e.is_dir = i;
        e.tkey = h;
        var l = new Element("li");
        var c = "",
            b = "";
        if (e.icon) {
            c = Sprite.make(e.icon, {
                "class": "icon_no_hover"
            });
            b = Sprite.make(e.icon + "_blue", {
                "class": "icon_hover"
            })
        }
        var j;
        if (typeof(e.text) == "function") {
            e.text = e.text()
        }
        if (g) {
            var m = new Element("span").update(c).insert(b).insert(e.text);
            j = HotButton.make(m)
        } else {
            j = new Element("a").update(c).insert(b).insert(e.text);
            j.addClassName("background-icon");
            HoverIconSwap.register(j)
        }
        j.target = "_top";
        if (!e.onclick) {
            j.href = e.verb ? ("/" + e.verb + f) : e.href()
        }
        if (e.width) {
            j.style.width = e.width
        }
        if (e.onclick) {
            j.observe("mouseup", (function (a) {
                e.onclick(a);
                if (k != "more_actions") {
                    BrowseActions.kill_dropdowns()
                }
            }).bindAsEventListener(e))
        }
        l.update(j);
        return l
    },
    sizeDropdownAnchors: function (c) {
        var e = $$(c).first();
        if (!e) {
            return
        }
        var h = e.select("a");
        if (!h) {
            return
        }
        var g = parseInt(e.getStyle("width"), 10) - parseInt(h[0].getStyle("padding-left"), 10) - parseInt(h[0].getStyle("padding-right"), 10) - 2;
        for (var f = 0, b = h.length; f < b; f += 1) {
            var d = h[f];
            d.style.width = g + "px"
        }
    },
    availMoreActions: function () {
        if (Browse.checked_files.length === 0) {
            var c = BrowseURL.get_del() === "1" ? "hide_del" : "show_del";
            if (Browse.show_deleted_button && !Browse.showing_deleted_button) {
                return [c]
            } else {
                return []
            }
        } else {
            if (Browse.checked_files.length === 1) {
                return Browse.checked_files[0].main_actions
            }
        }
        var a = ["move_bulk", "copy_bulk", "delete_bulk", "restore_bulk", "purge_bulk", "download_bulk"];
        var b = Browse.profile_files(Browse.checked_files);
        if (b.deleted > 0 || b.public_folder > 0 || b.photos_folder > 0) {
            a.removeItem("move_bulk");
            a.removeItem("copy_bulk");
            a.removeItem("delete_bulk")
        }
        if (b.shared_folders > 0) {
            a.removeItem("copy_bulk")
        }
        if (b.deleted > 0) {
            a.removeItem("delete_bulk");
            a.removeItem("download_bulk")
        }
        if (b.deleted != Browse.checked_files.length) {
            a.removeItem("restore_bulk");
            a.removeItem("purge_bulk")
        }
        return a
    },
    showMore: function () {
        BrowseActions.kill_dropdowns();
        var g = $("show-more-dropdown");
        if (g) {
            Util.yank(g)
        }
        var a = new Element("ul", {
            id: "show-more-dropdown"
        });
        a.addClassName("dropdown dropdown-lite");
        var e = BrowseActions.availMoreActions();
        var d = _("Select one or more files using the checkboxes.");
        var f = _("No actions available for these files");
        if (!e.length) {
            a.insert(new Element("li").update(new Element("p", {
                style: "padding: 5px 4px; margin: 0; text-align: center;"
            }).update(Browse.checked_files.length === 0 ? d : f)));
            a.style.width = "150px"
        } else {
            e.each(function (i) {
                var h = Browse.checked_files[0];
                if (h) {
                    a.insert(BrowseActions.generate_li(h.where, i, Browse.checked_files[0].hash, false, h.dir, h.tkey))
                } else {
                    a.insert(BrowseActions.generate_li(Browse.current_fqpath(), i, false, false, false, false))
                }
            });
            if (Util.ie) {
                BrowseActions.sizeDropdownAnchors.defer("#show-more-dropdown")
            }
        }
        $("browse-files").insert(a);
        var b = $$("#browse-root-actions li").last();
        a.clonePosition(b, {
            setWidth: false
        });
        a.style.height = "auto";
        a.style.top = parseInt(a.style.top, 10) + 1 + b.getHeight() + "px";
        var c = parseInt(a.style.left, 10) - (parseInt(a.getWidth(), 10) - b.getWidth()) + 1 + "px";
        a.style.left = c;
        if (a.viewportOffset().top < 0) {
            $("browse-location").scrollIntoView()
        }
        Event.observe(document, "click", BrowseActions.hideMore)
    },
    hideMore: function (c) {
        var b = $$("#browse-root-actions li").last();
        if (c && c.target && $(c.target).descendantOf(b)) {
            return
        }
        var a = $("show-more-dropdown");
        if (a) {
            Util.yank(a)
        }
        Event.stopObserving(document, "click", BrowseActions.hideMore)
    },
    fillActionUL: function (a, e, b, f, d) {
        if (e.length < 4 && Browse.show_deleted_button) {
            var c = BrowseURL.get_del() === "1" ? "hide_del" : "show_del";
            e.push(c);
            Browse.showing_deleted_button = 1
        } else {
            Browse.showing_deleted_button = 0
        }
        b.update(f ? "<li class='action-separator'>|</li>" : "");
        e.push("more_actions");
        if (e && e.length) {
            b.show();
            e.each(function (g) {
                if (g) {
                    b.insert(BrowseActions.generate_li(a, g, d, true))
                }
            })
        } else {
            b.hide()
        }
        Browse.root_actions = e.join(" ")
    },
    clear: function (c) {
        var b = $("browse-file-actions");
        if (b) {
            b.down("ul").update()
        }
        var a = $("more-file-actions");
        if (a) {
            a.update()
        }
    },
    kill_dropdowns: function () {
        BrowseActions.hideMore();
        var a = $("dropdown");
        if (a) {
            for (var b = 0; b < Browse.checked_files.length; b += 1) {
                Browse.checked_files[b].dropdown_arrow(false)
            }
            a.hide()
        }
    },
    dropdown: function (d, i, m) {
        var f = d.div;
        if (m) {
            Event.stop(m)
        }
        if (!f || !d.selected) {
            return
        }
        var j = d.where;
        var h = d.hash;
        var q = d.main_actions;
        if (!q.length) {
            return
        }
        var p = $("dropdown");
        if (p) {
            Event.stopObserving(document, "click", p.listener);
            p = Util.yank(p);
            if (Browse.more_link) {
                Event.stopObserving(Browse.more_link, "click", Browse.more_link_action);
                Browse.more_link = null;
                Browse.more_link_action = null
            }
        }
        f = $(f);
        var a = new Element("div", {
            id: "dropdown"
        });
        var c = new Element("ul", {
            "class": "dropdown dropdown-lite note"
        });
        $A(q).each(function (e) {
            c.insert(BrowseActions.generate_li(j, e, h, false, d.dir, d.tkey))
        });
        var g = null;
        a.insert(c);
        c.listener = function (s) {
            var t = $(s.target);
            if (t.descendantOf(d.div)) {
                return
            }
            Event.stopObserving(document, "click", c.listener);
            if (Browse.more_link) {
                Event.stopObserving(Browse.more_link, "click", Browse.more_link_action);
                Browse.more_link = null;
                Browse.more_link_action = null
            }
            if (s.target.parentNode.tagName != "A" && s.target.tagName != "A" || (s.target.href && s.target.href.length <= 2)) {
                Event.stop(s)
            }
            var r = $("dropdown");
            if (r) {
                r = Util.yank(r);
                if (d.checked) {
                    d.dropdown_arrow(false)
                }
            }
        };
        Event.observe(document, "click", c.listener);
        $(f.offsetParent).insert(a);
        var o = f.positionedOffset();
        var k = f.getDimensions();
        var n = a.getDimensions();
        var b = a.down().getDimensions();
        a.style.left = (o.left - b.width + k.width) + "px";
        a.style.top = (o.top + k.height - 1) + "px";
        if (!Util.ie) {
            var l = a.cumulativeOffset().top - Util.scrollTop();
            if (n.height + l > (window.innerHeight || document.documentElement.clientHeight)) {
                setTimeout(function () {
                    a.scrollIntoView(false);
                    a = null
                }, 100)
            }
        } else {
            BrowseActions.sizeDropdownAnchors.defer("#dropdown .dropdown")
        }
        window.focus();
        return false
    },
    hide_dropdown: function () {
        var a = $("dropdown");
        if (a) {
            a.remove()
        }
    },
    showCopyPublicUrlModal: function (a) {
        Modal.icon_show(BrowseActions.getIcon("copy_url"), _("Copy Public Link"), DomUtil.fromElm("copy-public-url"), {
            wit_group: "copy_public_link"
        });
        BrowseActions.addCopyUrlFlash(a);
        var b = $("modal-content").down("#public_url");
        assert(b, "Text element not found for copy pulic link");
        b.setValue(a);
        b.select()
    },
    clipboard_copy_done: function () {
        $("copy_success").update(Sprite.make("tick", {
            style: "vertical-align:middle;"
        }));
        $("copy_success").insert("&nbsp;" + _("Copied!"))
    },
    getIcon: function (a) {
        return BrowseActions.option_dict[a].icon
    },
    shortenPublicLink: function () {
        Util.shorten_url($F("public_url"), BrowseActions.updatePublicLink);
        var a = new Element("img", {
            id: "publink_loading",
            src: "images/icons/ajax-loading-small.gif"
        });
        a.addClassName("right");
        $("modal-content").down("a").update(a)
    },
    updatePublicLink: function (a) {
        $("public_url").setValue(a);
        $("public_url").select();
        $("publink_loading").remove();
        BrowseActions.addCopyUrlFlash(a)
    },
    addCopyUrlFlash: function (a, c, b) {
        c = c || "real_copy";
        b = b || "copy_button";
        var d = {
            wmode: "transparent",
            flashVars: "copy_text=" + Util.urlquote(a) + "&callback=BrowseActions.clipboard_copy_done()"
        };
        swfobject.embedSWF("swf/copy_to_clipboard.swf", "copy_button", "100%", "100%", "6.0.65", false, false, d);
        b = $(b);
        b.absolutize();
        b.clonePosition($(c), {
            offsetTop: -3,
            offsetLeft: -3,
            offsetHeight: 6,
            offsetWidth: 6
        })
    }
};
var BrowseKeys = {
    init: function () {
        document.observe("keypress", BrowseKeys.pressed);
        document.observe("keydown", BrowseKeys.keydown)
    },
    getKey: function (b) {
        var a = b.keyCode || b.which || b.charCode;
        return a
    },
    focus_in_input: function (a) {
        return document.activeElement && ["INPUT", "TEXTAREA", "SELECT"].indexOf(document.activeElement.tagName) != -1
    },
    keydown: function (b) {
        var a = BrowseKeys.getKey(b);
        if (BrowseKeys.focus_in_input()) {
            if (a == 27) {
                document.activeElement.blur()
            }
            return
        } else {
            if (!document.activeElement) {
                return
            }
        }
        if (a == 27) {
            BrowseKeys.hide_chart();
            Modal.hide()
        }
    },
    pressed_dict: {
        search: {
            title: _("Search your files"),
            key: "/",
            onPress: function (a) {
                $("filesearch").focus();
                $(document.body).scrollTo()
            }
        },
        move: {
            title: _("Move checked files"),
            key: "m",
            onPress: function (a, b) {
                if (b.indexOf("move") > -1) {
                    BrowseActions.option_dict.move_bulk.onclick(a)
                }
            }
        },
        check_invert: {
            title: _("Invert checked files"),
            key: "i",
            onPress: function () {
                for (var a = 0; a < Browse.files.length; a += 1) {
                    var b = Browse.files[a];
                    if (b.checked) {
                        b.decheck()
                    } else {
                        b.check()
                    }
                }
            }
        },
        check_deleted: {
            title: _("Check deleted files"),
            key: "p",
            onPress: function () {
                for (var a = 0; a < Browse.files.length; a += 1) {
                    var b = Browse.files[a];
                    if (b.bytes == "-1" && !b.checked) {
                        b.check()
                    } else {
                        if (b.bytes != "-1" && b.checked) {
                            b.decheck()
                        }
                    }
                }
            }
        },
        check_all: {
            title: _("Check all files"),
            key: "a",
            onPress: function () {
                Browse.check_all()
            }
        },
        check_none: {
            title: _("Uncheck all files"),
            key: "n",
            onPress: function () {
                Browse.decheck_all()
            }
        },
        show_del: {
            title: _("Show/hide deleted files"),
            key: "d",
            onPress: function () {
                window.location.href = BrowseURL.get_del_url(BrowseURL.get_del() != 1)
            }
        },
        help: {
            title: _("Show keyboard shorcuts"),
            key: "?",
            shift: true,
            onPress: function () {
                BrowseKeys.toggle_chart()
            }
        },
        copy: {
            title: _("Copy checked files"),
            key: "c",
            onPress: function (a, b) {
                if (b.indexOf("copy") > -1) {
                    BrowseActions.option_dict.copy_bulk.onclick(a)
                }
            }
        },
        up_dir: {
            title: _("Up a directory"),
            key: "u",
            onPress: function () {
                if (!Browse.reloading) {
                    var b, a;
                    if (Browse.is_share) {
                        b = "";
                        a = Util.parentDir(Util.normPath(Browse.parent_ns_path))
                    } else {
                        b = Browse.current_nsid;
                        a = Util.parentDir(Util.normPath(Browse.current_path))
                    }
                    if (Browse.current_path != a || Browse.current_nsid != b) {
                        BrowseURL.set_path_url(b, a)
                    }
                }
            }
        },
        highlight_up: {
            title: _("Highlight previous file"),
            key: "k",
            onPress: function () {
                BrowseKeys.highlight_up()
            }
        },
        highlight_top: {
            title: _("Highlight first file"),
            key: "k",
            shift: true,
            onPress: function () {
                if (Browse.highlight_index >= 0) {
                    Browse.files[Browse.highlight_index].dehighlight()
                }
                Browse.highlight_index = 0;
                Browse.files[0].highlight();
                $("header").scrollTo()
            }
        },
        highlight_down: {
            title: _("Highlight next file"),
            key: "j",
            onPress: function () {
                BrowseKeys.highlight_down()
            }
        },
        highlight_bottom: {
            title: _("Highlight last file"),
            key: "j",
            shift: true,
            onPress: function () {
                if (Browse.highlight_index >= 0) {
                    Browse.files[Browse.highlight_index].dehighlight()
                }
                Browse.highlight_index = Browse.files.length - 1;
                Browse.files[Browse.highlight_index].highlight();
                $("footer").scrollTo()
            }
        },
        check_file: {
            title: _("Check highlighted file"),
            key: " ",
            shift: "optional",
            stop_event: false,
            onPress: function (b) {
                if (Browse.highlight_index >= 0) {
                    var a = Browse.files[Browse.highlight_index];
                    a.click_check(b);
                    Event.stop(b)
                }
            }
        },
        open_file: {
            title: _("Open highlighted file"),
            key: "o",
            onPress: function () {
                if (Browse.highlight_index >= 0 && !Browse.reloading) {
                    var b = Browse.files[Browse.highlight_index];
                    var a;
                    if (b.dir) {
                        a = "#" + b.where
                    } else {
                        a = b.div.down(".details-filename a").href
                    }
                    window.location = a
                }
            }
        }
    },
    pressed: function (g) {
        var f = BrowseKeys.getKey(g);
        var c = String.fromCharCode(f).toLowerCase();
        var a = g.shiftKey;
        if (!document.activeElement || BrowseKeys.focus_in_input()) {
            return
        }
        var h = BrowseActions.availMoreActions().join(" ");
        var b;
        for (b in BrowseKeys.pressed_dict) {
            var d = BrowseKeys.pressed_dict[b];
            if (d.key == c && ((d.shift || false) == a || d.shift == "optional")) {
                d.onPress(g, h);
                if (d.stop_event !== false) {
                    Event.stop(g)
                }
                break
            }
        }
    },
    clear_highlight: function () {
        if (Browse.highlight_index >= 0 && Browse.highlight_index < Browse.files.length) {
            Browse.files[Browse.highlight_index].dehighlight()
        }
        Browse.highlight_index = -1
    },
    highlight_up: function () {
        if (!Browse.files.length) {
            return
        }
        if (Browse.highlight_index > 0 && Browse.highlight_index < Browse.files.length) {
            Browse.files[Browse.highlight_index].dehighlight()
        }
        if (Browse.highlight_index < 0) {
            Browse.highlight_index = Browse.files.length - 1
        } else {
            if (Browse.highlight_index === 0) {
                return
            } else {
                Browse.highlight_index = Browse.highlight_index - 1
            }
        }
        Browse.files[Browse.highlight_index].highlight()
    },
    highlight_down: function () {
        if (!Browse.files.length) {
            return
        }
        if (Browse.highlight_index >= 0 && Browse.highlight_index < Browse.files.length) {
            Browse.files[Browse.highlight_index].dehighlight()
        }
        if (Browse.highlight_index < 0) {
            Browse.highlight_index = 0
        } else {
            if (Browse.highlight_index == Browse.files.length - 1) {
                Browse.highlight_index = Browse.files.length - 1
            } else {
                Browse.highlight_index = Browse.highlight_index + 1
            }
        }
        Browse.files[Browse.highlight_index].highlight()
    },
    toggle_chart: function () {
        if ($("keys-chart").style.display == "none") {
            BrowseKeys.show_chart()
        } else {
            BrowseKeys.hide_chart()
        }
    },
    show_chart: function () {
        var a = $("keys-chart");
        a.absolutize();
        a.clonePosition($("browse-files"));
        var b = $("browse-files").viewportOffset()[1];
        if (b < 0) {
            a.style.top = parseInt(a.style.top, 10) - $("browse-files").viewportOffset()[1] + 10 + "px"
        }
        a.setOpacity(0.85);
        a.show()
    },
    hide_chart: function () {
        $("keys-chart").hide()
    }
};
var FileOps = {
    folder_to_icon: function (c, a, b) {
        assert(c, "folder_to_icon was not given a path.");
        c = Util.normalize(c.toLowerCase());
        if (b) {
            return "folder_star"
        } else {
            if (a) {
                return "folder_user"
            } else {
                if (c == "/photos") {
                    return "folder_photos"
                } else {
                    if (c == "/public") {
                        return "folder_public"
                    } else {
                        return "folder"
                    }
                }
            }
        }
    },
    filename_to_icon: function (a) {
        var c = FileOps.file_extension(a).toLowerCase();
        var b = {
            exe: "page_white_gear",
            dll: "page_white_gear",
            xls: "page_white_excel",
            xlsx: "page_white_excel",
            ods: "page_white_tux",
            c: "page_white_c",
            h: "page_white_c",
            php: "page_white_php",
            mp3: "page_white_sound",
            wav: "page_white_sound",
            m4a: "page_white_sound",
            wma: "page_white_sound",
            aiff: "page_white_sound",
            au: "page_white_sound",
            ogg: "page_white_sound",
            doc: "page_white_word",
            docx: "page_white_word",
            odt: "page_white_tux",
            ppt: "page_white_powerpoint",
            pptx: "page_white_powerpoint",
            odp: "page_white_tux",
            txt: "page_white_text",
            rtf: "page_white_text",
            sln: "page_white_visualstudio",
            vcproj: "page_white_visualstudio",
            html: "page_white_code",
            htm: "page_white_code",
            psd: "page_white_paint",
            pdf: "page_white_acrobat",
            fla: "page_white_actionscript",
            swf: "page_white_flash",
            gif: "page_white_picture",
            png: "page_white_picture",
            jpg: "page_white_picture",
            jpeg: "page_white_picture",
            tiff: "page_white_picture",
            tif: "page_white_picture",
            bmp: "page_white_picture",
            odg: "page_white_picture",
            py: "page_white_code",
            gz: "page_white_compressed",
            tar: "page_white_compressed",
            rar: "page_white_compressed",
            zip: "page_white_compressed",
            iso: "page_white_dvd",
            css: "page_white_code",
            xml: "page_white_code",
            tgz: "page_white_compressed",
            bz2: "page_white_compressed",
            rb: "page_white_ruby",
            cpp: "page_white_cplusplus",
            java: "page_white_cup",
            cs: "page_white_csharp",
            ai: "page_white_vector"
        };
        return b[c] || "page_white"
    },
    file_extension: function (a) {
        return a.split(".").last()
    },
    raw_filename: function (a) {
        return FileOps.filename(encodeURIComponent(a))
    },
    filename: function (c) {
        var b = decodeURIComponent(c);
        c = Util.normPath(b);
        c = c.split("/");
        var a = c.pop();
        if (a === "") {
            return _("Dropbox")
        }
        return a
    },
    dir_handler: function (h, g) {
        if (typeof(g) == "string") {
            g = $(g)
        }
        var f = $$(".treeview .highlight")[0];
        if (f) {
            f.removeClassName("highlight");
            var d = f.down(".link-img");
            if (d) {
                d.className = d.className.replace("_blue ", " ")
            }
        }
        var c = g.up("div");
        c.addClassName("highlight");
        var e = c.down(".link-img");
        if (e) {
            var b = e.className.split(" ");
            for (var a = 0; a < b.length; a += 1) {
                if (b[a].startsWith("s_") && !b[a].match(/_blue$/)) {
                    b[a] = b[a] + "_blue"
                }
            }
            e.className = b.join(" ")
        }
        Modal.selected_div = c;
        if (Modal.shown()) {
            g.blur()
        }
        document.fire("db:dir_click", {
            path: h
        });
        Modal.vars.selected_path = encodeURIComponent(h)
    },
    show_folder_pick: function (g, b, e, f, a) {
        DomUtil.fillVal(FileOps.filename(b).escapeHTML(), "folder-pick-file");
        TreeView.move("copy-move-treeview", "folder-pick-treeview");
        TreeView.enable_shared("copy-move-treeview");
        var c = a ? BrowseActions.getIcon("move_bulk") : BrowseActions.getIcon("copy_bulk");
        Modal.icon_show(c, g, $("folder-pick"), {
            where: b,
            action: e,
            folder: f
        });
        var d = $("first-treeview-link");
        if (!Util.ie) {
            d.onclick()
        }
    },
    show_bulk_folder_pick: function (h, g, d, f) {
        var c = Browse.profile_files(d);
        var a = Browse.profile_summary(c);
        DomUtil.fillVal(a, "bulk-folder-pick-file");
        TreeView.move("copy-move-treeview", "bulk-folder-pick-treeview");
        TreeView.enable_shared("copy-move-treeview");
        document.observe("db:dir_click", function (k) {
            var i = $$("#modal-content .bulk-folder-pick-action-text").first();
            if (i) {
                var j = {
                    copy: ungettext("Copy %(item-count)d item to %(path)s", "Copy %(item-count)d items to %(path)s", d.length),
                    move: ungettext("Move %(item-count)d item to %(path)s", "Move %(item-count)d items to %(path)s", d.length)
                };
                assert(g in j, "unexpected action name %s".format(g));
                i.setValue(j[g].format({
                    "item-count": d.length,
                    path: FileOps.raw_filename(k.memo.path)
                }))
            }
        });
        var b = g == "move" ? BrowseActions.getIcon("move_bulk") : BrowseActions.getIcon("copy_bulk");
        Modal.icon_show(b, h, $("bulk-folder-pick"), {
            files: d,
            action: f
        });
        var e = $("first-treeview-link");
        if (!Util.ie) {
            e.onclick()
        }
    },
    show_copy: function (a, b) {
        var c = b ? _("Copy Folder") : _("Copy File");
        DomUtil.fillVal(c, "folder-pick-action-text");
        DomUtil.fillVal(b ? _("Folder") : _("File"), "folder-pick-file-folder");
        FileOps.show_folder_pick(_("Copy to..."), a, FileOps.do_copy, b, false)
    },
    show_copy_bulk: function (a) {
        var b = ungettext("Copy %(item_count)s Item to...", "Copy %(item_count)s Items to...", a.length).format({
            item_count: a.length
        });
        FileOps.show_bulk_folder_pick(b, "copy", a, FileOps.do_bulk_copy)
    },
    show_move_bulk: function (a) {
        var b = ungettext("Move %(item_count)s Item to...", "Move %(item_count)s Items to...", a.length).format({
            item_count: a.length
        });
        FileOps.show_bulk_folder_pick(b, "move", a, FileOps.do_bulk_move)
    },
    show_move: function (a, b) {
        var d = b ? _("Move Folder") : _("Move File");
        DomUtil.fillVal(d, "folder-pick-action-text");
        DomUtil.fillVal(b ? _("Folder") : _("File"), "folder-pick-file-folder");
        var c = b ? _("Move Folder to...") : _("Move File to...");
        FileOps.show_folder_pick(c, a, FileOps.do_move, b, true)
    },
    show_move_confirm: function (b, f) {
        var a = Browse.profile_files(b);
        var c = Browse.profile_summary(a);
        var e = b.length == 1 ? "'" + b[0].filename + "'" : c;
        DomUtil.fillVal(e, "move-confirm-filename");
        DomUtil.fillVal(FileOps.raw_filename(f), "move-confirm-dest");
        var d = _("Move %(x_files_and_y_folders)s").format({
            x_files_and_y_folders: c
        });
        DomUtil.fillVal(d, "move-confirm-action-text");
        e = _("Move %(x_files_and_y_folders)s?").format({
            x_files_and_y_folders: e
        });
        Modal.icon_show(BrowseActions.getIcon("move"), e, DomUtil.fromElm("move-confirm"), {
            files: b,
            to: encodeURIComponent(f),
            wit_group: "move-confirm"
        })
    },
    show_rename: function (a) {
        DomUtil.fillVal(FileOps.filename(a), "rename-filename");
        Modal.icon_show(BrowseActions.getIcon("rename"), _("Rename File"), DomUtil.fromElm("rename-file"), {
            where: a,
            action: FileOps.do_rename,
            wit_group: "rename-file"
        })
    },
    show_delete: function (a, c) {
        DomUtil.fillVal("'" + FileOps.filename(a).escapeHTML() + "'", "delete-filename");
        var b = c ? BrowseActions.getIcon("delete_folder") : BrowseActions.getIcon("delete");
        var d = c ? _("Delete Folder?") : _("Delete File?");
        Modal.icon_show(b, d, DomUtil.fromElm("delete-file"), {
            where: a,
            action: FileOps.do_delete,
            folder: c,
            wit_group: "delete-confirm"
        })
    },
    show_bulk_delete: function (b) {
        var a = Browse.profile_files(b);
        var c = Browse.profile_summary(a);
        DomUtil.fillVal(FileOps.filename(c), "delete-filename");
        Modal.icon_show(BrowseActions.getIcon("delete"), _("Delete %(file_summary)s?").format({
            file_summary: c
        }), DomUtil.fromElm("delete-file"), {
            files: b,
            action: FileOps.do_bulk_delete,
            wit_group: "delete-bulk-confirm"
        })
    },
    show_purge: function (c, e) {
        var a = FileOps.filename(c).escapeHTML();
        var g = _("'%(file_name)s'").format({
            file_name: a
        });
        DomUtil.fillVal(g, "purge-filename");
        var f = e ? _("Folder") : _("File");
        DomUtil.fillVal(f, "purge-file-folder");
        var d = e ? _("Permanently Delete Folder") : _("Permanently Delete File");
        DomUtil.fillVal(d, "purge-action-text");
        var b = e ? _('Permanently Delete the Folder "%(file_name)s"?') : _('Permanently Delete the File "%(file_name)s"?');
        b = b.format({
            file_name: a
        });
        Modal.icon_show(BrowseActions.getIcon("purge"), b, DomUtil.fromElm("purge-file"), {
            where: c,
            action: FileOps.do_purge,
            folder: e,
            wit_group: "purge-file-confirm"
        })
    },
    show_bulk_purge: function (b) {
        var a = Browse.profile_files(b);
        var c = Browse.profile_summary(a);
        DomUtil.fillVal(c, "purge-filename");
        DomUtil.fillVal(_("Permanently Delete %(x_files_and_y_folders)s").format({
            x_files_and_y_folders: c
        }), "purge-action-text");
        var d = ungettext("Permanently Delete %d Item...", "Permanently Delete %d Items...", b.length).format(b.length);
        Modal.icon_show(BrowseActions.getIcon("purge_bulk"), d, DomUtil.fromElm("purge-file"), {
            files: b,
            action: FileOps.do_bulk_purge,
            wit_group: "purge-bulk-confirm"
        })
    },
    show_bulk_restore: function (b) {
        var a = Browse.profile_files(b);
        var c = Browse.profile_summary(a);
        DomUtil.fillVal(c, "restore-filename");
        DomUtil.fillVal("Restore %(x_files_and_y_folders)s".format({
            x_files_and_y_folders: c
        }), "restore-action-text");
        var d = ungettext("Restore %d Item...", "Restore %d Items...", b.length).format(b.length);
        Modal.icon_show(BrowseActions.getIcon("restore_bulk"), d, DomUtil.fromElm("restore-file"), {
            files: b,
            action: FileOps.do_bulk_restore,
            wit_group: "restore-bulk-confirm"
        })
    },
    show_new_folder: function (a) {
        Modal.show(_("Create Folder"), DomUtil.fromElm("new-folder"), {
            where: a,
            action: FileOps.do_new_folder,
            wit_group: "show-new-folder"
        })
    },
    show_upload: function (a, b) {
        a = a || Browse.current_fqpath();
        var d = FileOps.filename(a);
        DomUtil.fillVal(d, "upload-dest");
        var c = _("Upload to '%(folder_name)s'").format({
            folder_name: d.escapeHTML()
        });
        Modal.icon_show("page_white_get", c, DomUtil.fromElm("advanced-upload-modal"), {
            where: a,
            action: FileOps.do_upload,
            wit_group: "advanced-uploader"
        }, false, 500, FileQueue.numShown() && !b);
        if (FileQueue.empty()) {
            Upload.set_dest(Util.normPath(decodeURIComponent(a)))
        }
        if (!FileQueue.numShown() || b) {
            Upload.init(true)
        }
        InlineUploadStatus.hide()
    },
    show_basic_upload: function (a) {
        DomUtil.fillVal(FileOps.filename(a), "upload-dest");
        Modal.icon_show(BrowseActions.getIcon("upload"), _("Upload"), $("basic-upload-modal"), {}, false, 600)
    },
    show_undelete: function (a) {
        DomUtil.fillVal(a.filename.escapeHTML(), "undelete-filename");
        DomUtil.fillVal(a.ago, "undelete-date-time");
        var b = Sprite.make(a.icon, {});
        b.addClassName("link-img");
        b.style.backgroundColor = "transparent";
        var c = "/revisions" + a.where + "?undelete=1";
        $$(".undelete-icon").invoke("update", b);
        $$(".undelete-other-versions")[0].href = c;
        $$(".undelete-link")[0].href = c;
        $("undelete-form").action = "/revisions" + a.where;
        var d = _('Undelete the File "%(file_name)s"?').format({
            file_name: a.filename.escapeHTML()
        });
        Modal.icon_show(BrowseActions.getIcon("undelete"), d, $("undelete-modal"), {
            file: a
        })
    },
    submit_undelete: function (b) {
        var a = $("undelete-form");
        var c = _("'%(file_name)s' restored successfully.").format({
            file_name: Modal.vars.file.filename
        });
        Forms.ajax_submit(a, false, function () {
            Modal.hide();
            Notify.ServerSuccess(c);
            Browse.force_reload()
        }, function () {
            var d = _("Unable to restore %(file_name)s").format({
                file_name: Modal.vars.file.filename
            });
            Notify.ServerError(d)
        }, b.target);
        return false
    },
    do_copy: function (c, b) {
        c = c || Modal.vars.where;
        b = b || Modal.vars.selected_path;
        var a = Browse.find_file(Modal.vars.where);
        assert(a, "Trying to copy a file we couldn't find.");
        FileOps.do_bulk_copy([a], b)
    },
    do_bulk_copy: function (f, g) {
        f = f || Modal.vars.files;
        assert(f.length > 0, "Tried to copy 0 files");
        g = g || Modal.vars.selected_path;
        g = decodeURIComponent(g);
        if (!g) {
            Notify.ServerError(_("You should select a destination for the file."));
            return
        }
        var b = false;
        var c = false;
        for (var d = 0; d < f.length; d += 1) {
            if (f[d].dir && Util.normDir(decodeURIComponent(g)).indexOf(Util.normDir(decodeURIComponent(f[d].where))) === 0) {
                Notify.ServerError(_("You cannot copy a folder into itself."));
                return
            }
            c = c || f[d].dir;
            if (decodeURIComponent(f[d].where) == Util.normPath(g) + "/" + FileOps.filename(f[d].where)) {
                b = true
            }
        }
        var e = f.collect(function (h) {
            return decodeURIComponent(h.where)
        });
        var a = new Ajax.DBRequest("/cmd/copy", {
            parameters: {
                files: e,
                to_path: g
            },
            job: true,
            progress_text: _("Copying..."),
            onSuccess: function (h) {
                if (b) {
                    Browse.force_reload()
                }
                var i = ungettext("Copied %d item successfully", "Copied %d items successfully", e.length).format(e.length);
                Notify.ServerSuccess(i);
                TreeView.schedule_reset()
            },
            cleanUp: function (h) {}
        })
    },
    do_move: function (c, b) {
        c = c || Modal.vars.where;
        b = b || Modal.vars.selected_path;
        var a = Browse.find_file(Modal.vars.where);
        assert(a, "Trying to move a file we couldn't find.");
        FileOps.do_bulk_move([a], b)
    },
    do_bulk_move: function (e, f) {
        e = e || Modal.vars.files;
        if (!e) {
            return
        }
        assert(e.length > 0, "Tried to move 0 files");
        f = f || Modal.vars.selected_path;
        f = decodeURIComponent(f);
        if (!f) {
            Notify.ServerError(_("You should select a destination for the file."));
            return
        }
        var b = false;
        for (var c = 0; c < e.length; c += 1) {
            if (e[c].dir && Util.normDir(decodeURIComponent(f)).indexOf(Util.normDir(decodeURIComponent(e[c].where))) === 0) {
                Notify.ServerError(_("You cannot move a folder into itself."));
                return
            }
        }
        var d = e.collect(function (g) {
            return decodeURIComponent(g.where)
        });
        var a = new Ajax.DBRequest("/cmd/move", {
            parameters: {
                files: d,
                to_path: f
            },
            job: true,
            progress_text: _("Moving..."),
            onSuccess: function (g) {
                Notify.ServerSuccess(ungettext("Moved item successfully", "Moved items successfully", d.length));
                TreeView.schedule_reset()
            },
            cleanUp: function (g) {
                Browse.force_reload()
            }
        })
    },
    do_rename: function (b) {
        var d = Modal.vars.where;
        var c = encodeURIComponent(b);
        var a = new Ajax.DBRequest("/cmd/rename" + d + "?to_path=" + c, {
            onSuccess: function (h) {
                var j = h.responseText.split(":");
                var e = j[0];
                var f = j[1];
                var i = FileOps.filename(e);
                var k = _("Renamed '%(old_name)s' to '%(new_name)s' successfully.").format({
                    old_name: FileOps.filename(d).snippet(),
                    new_name: i.snippet()
                });
                Notify.ServerSuccess(k);
                var g = Browse.find_file(d);
                g.rename(e, g.dir, f);
                TreeView.schedule_reset()
            },
            cleanUp: function (e) {}
        })
    },
    do_bulk_delete: function (d) {
        d = d || Modal.vars.files;
        assert(d.length > 0, "Tried to delete 0 files");
        var c = d.collect(function (f) {
            return decodeURIComponent(f.where)
        });
        var e = Modal.vars.where;
        var b = Modal.vars.folder;
        var a = new Ajax.DBRequest("/cmd/delete", {
            parameters: {
                files: c
            },
            job: true,
            progress_text: _("Deleting..."),
            onSuccess: function (f) {
                var g = ungettext("Deleted %d item successfully.", "Deleted %d items successfully.", c.length).format(c.length);
                Notify.ServerSuccess(g);
                TreeView.schedule_reset()
            },
            cleanUp: function (f) {
                Browse.force_reload()
            }
        })
    },
    do_delete: function () {
        var a = Browse.find_file(Modal.vars.where);
        assert(a, "Trying to delete a file we couldn't find.");
        FileOps.do_bulk_delete([a])
    },
    do_purge: function () {
        var a = Browse.find_file(Modal.vars.where);
        assert(a, "Trying to purge a file we couldn't find.");
        FileOps.do_bulk_purge([a])
    },
    do_bulk_purge: function (d) {
        d = d || Modal.vars.files;
        assert(d.length > 0, "Tried to purge 0 files");
        var c = d.collect(function (g) {
            return decodeURIComponent(g.where)
        });
        var f = Modal.vars.where;
        var b = Modal.vars.folder;
        var e = ungettext("Permanently deleted %d item successfully", "Permanently deleted %d items successfully.", c.length).format(c.length);
        var a = new Ajax.DBRequest("/cmd/purge", {
            parameters: {
                files: c
            },
            job: true,
            progress_text: _("Deleting..."),
            onSuccess: function (g) {
                Notify.ServerSuccess(e);
                Browse.force_reload();
                TreeView.schedule_reset()
            },
            cleanUp: function (g) {}
        })
    },
    do_bulk_restore: function (d) {
        d = d || Modal.vars.files;
        assert(d.length > 0, "Tried to restore 0 files");
        var c = d.collect(function (g) {
            return decodeURIComponent(g.where)
        });
        var f = Modal.vars.where;
        var b = Modal.vars.folder;
        var e = ungettext("Restored %d item successfully.", "Restored %d items successfully.", c.length).format(c.length);
        var a = new Ajax.DBRequest("/cmd/restore", {
            parameters: {
                files: c
            },
            job: true,
            progress_text: _("Restoring..."),
            onSuccess: function (g) {
                Notify.ServerSuccess(e);
                Browse.force_reload();
                TreeView.schedule_reset()
            },
            cleanUp: function (g) {}
        })
    },
    do_upload: function () {
        $("dest-folder").value = decodeURIComponent(Modal.vars.where);
        $("upload-form").submit();
        frames["upload-frame"].onload = function (a) {
            var b = a.target.documentElement.textContent;
            if (b == "winner!") {
                Browse.force_reload();
                Notify.ServerSuccess(_("Uploaded file successfully"))
            } else {
                Notify.ServerError()
            }
        }
    },
    do_bulk_download: function (b) {
        var c = new Element("form", {
            action: "https://" + Constants.BLOCK_CLUSTER + "/zip_batch",
            method: "post"
        });
        for (var a = 0; a < b.length; a += 1) {
            Forms.add_vars(c, {
                files: decodeURIComponent(b[a].where)
            })
        }
        Forms.add_vars(c, {
            parent_path: Util.normDir(decodeURIComponent(Browse.current_fqpath())),
            w: Browse.current_path_hash,
            user_id: Constants.uid
        });
        $(document.body).insert(c);
        c.submit()
    },
    inplace_new_folder: function (b) {
        if (Browse.in_placer && Browse.in_placer.new_folder) {
            return
        }
        var a = _("New Folder");
        if (b.charAt(b.length - 1) != "/") {
            b += "/"
        }
        Browse.hide_message();
        var d = "share zipped_dl upload copy_folder move_folder rename_folder delete_folder";
        if (Constants.can_shmodel) {
            d = d + " token_share"
        }
        var c = new BrowseFile("folder", b, "/browse2" + b + a, a, a, false, 0, "", Util.ts(), d, "", true, true, true, null, 0, -1, []);
        Browse.resort();
        c.edit(true)
    }
};
var Forms = {
    submitOnlyOnce: function () {
        var a = Forms.submitted !== true;
        Forms.submitted = true;
        return a
    },
    disable: function (a) {
        if (a) {
            setTimeout(function () {
                a.disabled = true
            }, 0)
        }
    },
    enable: function (a) {
        if (a) {
            setTimeout(function () {
                a.disabled = false
            }, 0)
        }
    },
    clearInput: function (b, a) {
        b = $(b);
        if (b.value == a) {
            b.value = "";
            b.style.color = "#444444"
        }
    },
    add_vars: function (b, c) {
        b = $(b);
        for (var a in c) {
            var d = new Element("input", {
                type: "hidden",
                name: a
            });
            d.setValue(c[a]);
            d.addClassName("added-vars");
            b.insert(d)
        }
    },
    clear_added_vars: function (a) {
        $$(".added-vars").each(Element.remove)
    },
    mirror: function (c, b) {
        c = $(c);
        b = $(b);

        function a(e, d) {
            d.setValue($F(e));
            d.fire("db:value_change")
        }
        if (c && b) {
            c.observe("keyup", function () {
                a(c, b)
            });
            c.observe("db:autocompleted", function () {
                a(c, b)
            });
            b.observe("keyup", function () {
                a(b, c)
            });
            b.observe("db:autocompleted", function () {
                a(b, c)
            })
        }
    },
    collect_form_vars: function (d) {
        d = d || $(document.body);
        var c = d.select("input").concat(d.select("textarea")).concat(d.select("select"));
        var a = {};
        for (var b = 0; b < c.length; b++) {
            var f = c[b];
            if (f.name && f.name != "t") {
                var e = f.getValue();
                if (e) {
                    if (typeof(e) != "string") {
                        e = e.join(",")
                    }
                    if (a[f.name] !== undefined) {
                        if (typeof(a[f.name]) == "string") {
                            a[f.name] = [a[f.name], e]
                        } else {
                            a[f.name].push(e)
                        }
                    } else {
                        a[f.name] = e
                    }
                }
            }
        }
        return a
    },
    add_loading: function (b) {
        if (b) {
            b = $(b);
            var a = new Element("img", {
                src: "images/icons/ajax-loading-small.gif"
            });
            a.addClassName("text-img ajax_submit_loading");
            b.insert({
                before: a
            })
        }
    },
    remove_loading: function (a) {
        $$(".ajax_submit_loading").each(function (b) {
            Util.yank(b)
        })
    },
    ajax_submit: function (c, a, h, b, f, e) {
        if (c.ajax_submitted) {
            return false
        }
        c.ajax_submitted = true;
        var g = c.select(".suggestion-input").each(function (j) {
            SuggestionInput.blank(j.identify())()
        });
        if (f) {
            Forms.add_loading(f)
        }
        var d = Forms.collect_form_vars(c);
        if (e) {
            d = $H(d).update(e).toObject()
        }
        var i = new Ajax.DBRequest(a || c.action, {
            noAutonotify: true,
            parameters: d,
            onSuccess: function (j) {
                if (h && typeof(h) == "function") {
                    h(j)
                }
            },
            onFailure: function (l) {
                if (l) {
                    if (l.responseText.indexOf("err:") === 0) {
                        var j = l.responseText.substr(4);
                        if (j.indexOf("{") === 0) {
                            var k = j.evalJSON(true);
                            Forms.fill_errors(c, k)
                        } else {
                            Notify.ServerError(j)
                        }
                    } else {
                        Notify.ServerError()
                    }
                    if (b && typeof(b) == "function") {
                        b(l)
                    }
                }
            },
            onComplete: function (j) {
                c.ajax_submitted = false;
                Forms.remove_loading()
            }
        });
        return false
    },
    clear_errors: function (a) {
        a = a || $(document.body);
        a.select(".error-removable").invoke("remove")
    },
    fill_errors: function (d, c) {
        c = c || {};
        d = d || $(document.body);
        Forms.clear_errors(d);
        for (var e in c) {
            var f = d.down("input[name='" + e + "']") || d.down("textarea[name='" + e + "']") || d.down("select[name='" + e + "']");
            if (f) {
                var b = new Element("br", {
                    "class": "error-removable"
                });
                var a = new Element("span", {
                    "class": "error-message error-removable"
                });
                a.update(c[e]);
                f.insert({
                    before: a
                });
                f.insert({
                    before: b
                })
            }
        }
    },
    value: function (c) {
        var b = $$('input[name="' + c + '"]');
        var e = null;
        var a = b.length;
        for (var d = 0; d < a; d++) {
            e = $(b[d]).getValue() || e
        }
        return e
    }
};
var Upgrade = {
    card_toggle: function (a) {
        return function (c) {
            var b = $(c);
            if (c == a || !a) {
                b.removeClassName("cc-icon-off")
            } else {
                b.addClassName("cc-icon-off")
            }
        }
    },
    highlightCardtype: function () {
        var e = $("ccn");
        if (Upgrade.last_val == e.value) {
            return
        }
        Upgrade.last_val = e.value;
        var b = e.value;
        var d = b.substr(0, 2);
        var c = $A(["visa", "mastercard", "amex"]);
        var a = null;
        if (b.charAt(0) == "4") {
            a = "visa"
        } else {
            if (d == "34" || d == "37") {
                a = "amex"
            } else {
                if (parseInt(d, 10) >= 51 && parseInt(d, 10) <= 55) {
                    a = "mastercard"
                }
            }
        }
        c.each(Upgrade.card_toggle(a))
    },
    runCardHighlighter: function () {
        setInterval(Upgrade.highlightCardtype, 200)
    },
    highlightPlan: function () {
        var b = $A(["fifty-plan", "100-plan", "250-plan", "free-plan"]);
        var a = b.map(Util.scry).find(function (c) {
            if (c) {
                return c.checked
            }
        });
        if (Upgrade.last_checked == a) {
            return
        }
        if (Upgrade.last_checked) {
            Util.scry(Upgrade.last_checked.id + "-div").removeClassName("payment-option-selected")
        }
        if (a) {
            Util.scry(a.id + "-div").addClassName("payment-option-selected")
        }
        Upgrade.last_checked = a
    },
    enableNext: function () {
        var a = $("next-button");
        a.enable();
        a.removeClassName("disabled-button")
    },
    disableNext: function () {
        var a = $("next-button");
        a.disable();
        a.addClassName("disabled-button")
    },
    runPlanHighlighter: function () {
        setInterval(Upgrade.highlightPlan, 100)
    },
    showPlanInfo: function (b) {
        var a = {
            "50-plan": _("It's 50 GB"),
            "100-plan": _("It's 100 GB"),
            "250-plan": _("It's 250 GB"),
            "free-plan": _("It's free")
        };
        Util.scry("plan-specific").update(a[b.id])
    }
};
var Home = {
    showScreencast: function (e, c, d) {
        d = d || 532;
        var a = (360 / 640) * d;
        a = parseInt(a, 10);
        var f = {
            allowfullscreen: "true",
            wmode: "transparent"
        };
        var b = {
            file: localized_path("http://www.sharebits.net/video/dropbox_introX.mp4", ["es", "fr", "de", "ja"]),
            skin: "../video/bekle.swf",
            controlbar: "over",
            image: "../video/cc_endframe.jpg"
        };
        if (c) {
            b.autostart = "true"
        }
        var g = new Element("div", {
            id: "commoncraft-embed",
            style: "display: inline-block; border:1px solid #adcfea;background:#fff;"
        });
        $(e).update(g);
        swfobject.embedSWF("../video/player-licensed.swf", "commoncraft-embed", d.toString(), a.toString(), "9", false, b, f);
        MCLog.log("commoncraft_views")
    },
    showFeedback: function (a) {
        if (a) {
            Event.stop(a)
        }
        Modal.icon_show("comments", _("Tell Us What You Think"), $("feedback-div"), {
            icon: "information"
        }, $("feedback_textarea"));
        return false
    },
    hide: function (c, b) {
        $(c).up("div").hide();
        var a = new Ajax.DBRequest("/hide/" + b)
    }
};
var Install = {
    pingForLinkedHost: function (b) {
        var a = new Ajax.Request("/host_linked", {
            method: "get",
            onSuccess: function () {
                location.href = "/share" + b
            },
            onFailure: function () {
                setTimeout(Install.pingForLinkedHost.curry(b), 3000)
            }
        })
    }
};
var Tour = {
    pages: {},
    loading: false,
    register: function () {
        var b = 1;
        $$(".tour-page a").each(function (c) {
            c.href = "#" + b;
            b += 1
        });
        var a = $$(".abutton")[0];
        if (a) {
            a.href = "#" + (Tour.current_page + 1)
        }
        Tour.interval = setInterval(Tour.check_url, 100)
    },
    load: function (b, d) {
        if (Tour.loading) {
            return
        }
        b = b <= Tour.page_count && b > 0 ? b : 1;
        Tour.current_page = b;
        Tour.select_tab(b);
        Tour.loading = true;
        if (Tour.pages[b]) {
            Tour.show_page(b)
        } else {
            Feed.showLoading(false, "tour-content", true);
            var a = Tour.db_pro ? "?db_pro" : "";
            var c = new Ajax.Request("/tour/" + b + a, {
                method: "get",
                onSuccess: function (e) {
                    Tour.pages[b] = e.responseText;
                    Tour.show_page(b);
                    Feed.hideLoading()
                }
            })
        }
    },
    select_tab: function (d) {
        var a, e, b;
        $$("a.selected").each(function (f) {
            f.removeClassName("selected");
            a = f.down(".sidebar-tab-rounded-tl").remove();
            e = f.down(".sidebar-tab-rounded-bl").remove();
            b = f.down(".sidebar-tab-rounded-l").remove()
        });
        var c = $$(".sidebar-tabs ul li a")[d - 1];
        c.blur();
        c.addClassName("selected");
        c.insert(a);
        c.insert(e);
        c.insert(b)
    },
    show_page: function (c) {
        $("tour-content").update(Tour.pages[c]);
        if (c < Tour.page_count) {
            var d = new Element("div", {
                style: "text-align: right;"
            });
            var b = new Element("a", {
                href: "#" + (c + 1)
            });
            b.update(_("Next") + "&raquo;");
            b.addClassName("abutton");
            d.update(b);
            $("tour-content").insert(d)
        }
        Tour.loading = false
    },
    check_url: function () {
        var a = Util.url_hash();
        if (!a || Tour.loading) {
            return
        }
        a = parseInt(a, 10);
        if (a != Tour.current_page) {
            Tour.load(a)
        }
    }
};
var Dropdown = {
    init: function () {
        $$("#tabs-container > ul > li").each(function (a) {
            a.observe("mouseenter", Dropdown.over);
            a.observe("mouseleave", Dropdown.out)
        })
    },
    over: function (a) {
        clearTimeout(Dropdown.timeout);
        $$("#tabs-container > ul > li.hover").invoke("removeClassName", "hover");
        var b = $(a.target);
        if (!b.match("#tabs-container > ul > li")) {
            b = b.up("#tabs-container > ul > li")
        }
        b.addClassName("hover")
    },
    out: function (a) {
        var b = $(a.target);
        if (!b.match("#tabs-container > ul > li")) {
            b = b.up("#tabs-container > ul > li")
        }
        Dropdown.timeout = setTimeout(function () {
            b.removeClassName("hover")
        }, 300)
    }
};
var LiveSearch = {
    search: function (g, f, d, b, c) {
        g = g.strip();
        if (g.length < 3) {
            $(f).update("");
            if (b.onEmpty) {
                b.onEmpty(g)
            }
        } else {
            var e = {
                search_string: g,
                "short": c ? 1 : ""
            };
            var a = new Ajax.Request(d, {
                parameters: e,
                method: "get",
                onSuccess: function (h) {
                    var i = h.responseText.strip();
                    if (!i) {
                        if (b.onEmpty) {
                            b.onEmpty(g)
                        }
                        return
                    }
                    $(f).update(h.responseText);
                    LiveSearch.highlight(f, g);
                    if (b.onComplete) {
                        b.onComplete(g)
                    }
                }
            })
        }
    },
    highlight: function (c, b) {
        var a = b.split(" ");
        a.each(function (e) {
            if (e.length < 4) {
                return
            }
            var d = new RegExp(RegExp.escape(e), "i");
            c = $(c);
            $$(".livesearch_result_a").each(function (f) {
                f.innerHTML = f.innerHTML.gsub(d, function (g) {
                    return "<span class='highlight'>" + g[0] + "</span>"
                })
            });
            $$(".livesearch_result_p").each(function (f) {
                f.innerHTML = f.innerHTML.stripTags().gsub(d, function (g) {
                    return "<span class='highlight'>" + g[0] + "</span>"
                })
            })
        })
    },
    MAX_RESULTS: 10
};
var Email = {
    mailto: function (c, b, d, a) {
        if (!d) {
            d = "dropbox.com"
        }
        c.href = "mailto:" + b + "@" + d;
        if (a) {
            c.href += "?body=" + a
        }
        c.onMouseover = null
    }
};
var SuggestionInput = {
    register: function (c) {
        c = $(c);
        var b = c.up("form");
        var a = c.getValue();
        if (a === "" || a === c.title) {
            c.setValue(c.title);
            c.defaulted = true
        } else {
            c.defaulted = false;
            c.addClassName("suggestion-input-unfaded")
        }
        c.observe("blur", SuggestionInput.blur);
        c.observe("focus", SuggestionInput.focus);
        c.observe("db:value_change", SuggestionInput.focus);
        if (b) {
            if (!c.id) {
                c.id = "r_elm_id_" + Math.random().toString()
            }
            b.observe("submit", SuggestionInput.blank(c.id))
        }
    },
    register_all: function () {
        $$(".suggestion-input").each(SuggestionInput.register)
    },
    blank: function (a) {
        return function () {
            var b = $(a);
            if (!b) {
                return
            }
            if (b && b.defaulted) {
                b.setValue("")
            }
        }
    },
    do_blank: function (a) {
        SuggestionInput.blank(a)()
    },
    clear: function (a) {
        var b = {
            target: a
        };
        SuggestionInput.focus(b)
    },
    focus: function (a) {
        var b = $(a.target);
        if (!b) {
            return
        }
        if (b.defaulted) {
            b.addClassName("suggestion-input-unfaded");
            b.setValue("");
            b.defaulted = false
        }
    },
    blur: function (a) {
        var b = $(a.target);
        if (!b) {
            return
        }
        if (b.getValue() === "") {
            b.removeClassName("suggestion-input-unfaded");
            b.setValue(b.title);
            b.defaulted = true
        }
    },
    reset: function (b) {
        var a = $(b);
        if (!a) {
            return
        }
        a.removeClassName("suggestion-input-unfaded");
        a.setValue(a.title);
        a.defaulted = true
    }
};
document.observe("dom:loaded", SuggestionInput.register_all);
var HoverIconSwap = {
    register_all: function () {
        $$(".background-icon").each(HoverIconSwap.register)
    },
    register: function (a) {
        a = $(a);
        a.db_observe("mouseenter", HoverIconSwap.mouseenter);
        a.db_observe("mouseleave", HoverIconSwap.mouseleave)
    },
    mouseenter: function (a, b) {
        b.addClassName("hover_swap")
    },
    mouseleave: function (a, b) {
        b.removeClassName("hover_swap")
    },
    getFileName: function (b) {
        var a = b.src.split("/");
        return a[a.length - 1]
    }
};
document.observe("dom:loaded", HoverIconSwap.register_all);
var BrowseStyleRows = {
    register_all: function () {
        $$(".bs-row").each(BrowseStyleRows.register);
        Event.observe(document, "click", BrowseStyleRows.kill_current)
    },
    register: function (a) {
        a = $(a);
        a.db_observe("mouseover", BrowseStyleRows.mouseover);
        a.db_observe("mouseout", BrowseStyleRows.mouseout);
        a.db_observe("click", BrowseStyleRows.click)
    },
    mouseover: function (b, a) {
        a.addClassName("hover")
    },
    mouseout: function (b, a) {
        a.removeClassName("hover")
    },
    click: function (d, b) {
        if (d.target.tagName == "A") {
            return
        }
        Event.stop(d);
        BrowseStyleRows.kill_current(false);
        var c = $(d.target);
        if (!c.match(".bs-actions-list *")) {
            b.addClassName("selected")
        }
        var a = c.hasClassName("bs-row") ? c : c.up(".bs-row");
        if (Util.ie6) {
            a.down(".bs-actions-list").style.position = "absolute"
        }
        a.style.zIndex = 9
    },
    kill_current: function (a) {
        $$(".bs-row.selected").each(function (b) {
            b.removeClassName("selected");
            b.style.zIndex = ""
        })
    }
};
var EventBubble = {
    make: function (b) {
        var a = '<table class="ebubble"><tr><td class="tl"></td><td class="t"></td><td class="tr"></td></tr><tr><td class="l"></td><td class="c">#{content}</td><td class="r"></td></tr><tr><td class="bl"></td><td class="b"><img src="images/events_bubble_tail.gif" alt="" class="events_bubble_tail"/></td><td class="br"></td></tr></table>';
        return a.interpolate({
            content: b
        })
    }
};
var HotButton = {
    make: function (b) {
        var a = new Element("a");
        a.addClassName("hotbutton");
        var d = new Element("span");
        d.addClassName("hotbutton-content");
        d.update(b);
        a.update(d);
        var c = new Element("span");
        c.addClassName("shadow");
        a.insert(c);
        return HotButton.register(a)
    },
    register: function (a) {
        var b = a.select(".hotbutton-icon").pop();
        if (b) {
            a._icon = b;
            a._sprite = Sprite.current(b)
        }
        a.observe("mouseenter", function () {
            HotButton.mouseenter(a)
        });
        a.observe("mouseleave", function () {
            HotButton.mouseleave(a)
        });
        a.observe("mousedown", function (c) {
            HotButton.mousedown(c, a)
        });
        a.observe("mouseup", function () {
            HotButton.mouseup(a)
        });
        Util.disableSelection(a);
        return a
    },
    mouseenter: function (a) {
        a.addClassName("hover");
        a.style.zIndex = 1
    },
    mouseleave: function (a) {
        a.removeClassName("hover");
        a.removeClassName("down");
        a.removeClassName("hover_swap");
        a.style.zIndex = 0;
        if (a._icon) {
            Sprite.src(a._icon, a._sprite)
        }
    },
    mousedown: function (b, a) {
        a.addClassName("down");
        a.addClassName("hover_swap");
        if (a._icon) {
            Sprite.src(a._icon, Sprite.blue(a._sprite))
        }
        Event.stop(b)
    },
    mouseup: function (a) {
        a.removeClassName("down");
        a.removeClassName("hover_swap");
        if (a._icon) {
            Sprite.src(a._icon, a._sprite)
        }
    }
};
var ActAsBlock = {
    elm_list: ["margin-left", "margin-right", "padding-left", "padding-right", "border-left-width", "border-right-width"],
    parent_list: ["padding-left", "padding-right", "border-left-width", "border-right-width"],
    register: function (c, d) {
        d = d || document.body;
        var b = $(d).getElementsByClassName("act_as_block");
        for (var a = 0; a < b.length; a = a + 1) {
            ActAsBlock.resize(b[a])
        }
    },
    resize: function (e) {
        e = $(e);
        var c = e.up();
        var a = Util.sumStyles(e, ActAsBlock.elm_list);
        var d = Util.sumStyles(c, ActAsBlock.parent_list);
        e.style.width = "1px";
        var b = (c.getWidth() - a - d);
        if (b > 0) {
            e.style.width = b + "px"
        }
    }
};
Event.observe(window, "load", ActAsBlock.register);
var Inbox = {
    overQuotaModal: function (b, f, c, e) {
        Modal.show(_("Quota Warning"), $("overquota-modal"));
        var a = $("modal-content");
        $$(".shared-folder-name").invoke("update", f);
        $$(".shared-folder-size").invoke("update", c);
        var d = a.getElementsByClassName("joinbutton");
        d[0].onclick = function () {
            b.onclick = null;
            b.click()
        };
        d[0].value = _("Join %(folder_name)s").format({
            folder_name: f
        });
        return false
    }
};
var Downloading = {
    registerAll: function () {
        if (Prototype.Browser.IE) {
            $$(".downloading-link").each(Downloading.register)
        }
    },
    register: function (a) {
        a = $(a);
        a.observe("click", Downloading.clicked)
    },
    clicked: function (b) {
        Event.stop(b);
        var c = $(b.target);
        if (c.nodeName === "SPAN") {
            c = c.up("a")
        }
        var a = c.href.split("?").last();
        window.location = "/download?" + a;
        setTimeout(function () {
            window.location = "/downloading?" + a
        }, 4000)
    }
};
document.observe("dom:loaded", Downloading.registerAll);
var Referral = {
    select_all: 1,
    show_login_modal: function (a) {
        Modal.show(_("Invite Contacts From Your Email Address Book"), $("cli-login"), a || {})
    },
    get_selected_emails: function () {
        var a = [];
        $$("#contact-list input").each(function (b) {
            if (b.checked) {
                a.push(b.value)
            }
        });
        return a.join(", ")
    },
    send_invites: function (a) {
        var b = Referral.get_selected_emails();
        Invitations.do_send(b, false, a, true);
        Modal.hide()
    },
    show_contact_info_modal: function () {
        Modal.show(_("Invite Contacts From Your Email Account"), DomUtil.fromElm("contact-info-modal"), {
            action: Referral.fetch_contacts,
            wit_group: "contact_importer_login"
        });
        $("email-prefix").focus();
        return false
    },
    show_error: function (a) {
        Referral.hide_captcha();
        $("contact-info-error").update(a);
        $("contact-info-error").show()
    },
    error_messages: [N_("Bad user name or password"), N_("Bad user name"), N_("Bad password"), N_("Captcha challenge was raised"), N_("Captcha challenge raised"), N_("Captcha challenge was issued. Please login through Yahoo mail manually."), N_("AOL requires you to answer some security questions"), N_("Email address has not been verified"), N_("Account closed by system operator"), N_("Account deleted"), N_("Account disabled"), N_("Service disabled"), N_("Authorization required"), N_("Unknown gmail error"), N_("Gmail terms not agreed"), N_("Google contacts service unavailable. Try again later.")],
    show_captcha: function (a) {
        Referral.hide_captcha();
        a = a.evalJSON(true);
        $("captcha-row").hide();
        $("contact-info-captcha-image").src = a.image.replace("http://", "https://");
        $("contact-info-captcha-image").hide();
        Element.observe("contact-info-captcha-image", "load", function () {
            $("contact-info-captcha-image").show()
        });
        $("contact-info-captcha-id").value = a.id;
        $("contact-info-captcha-answer").value = "";
        $("captcha-row").show();
        $("captcha-answer-row").show();
        $("contact-info-error").update(_("Captcha required"));
        $("contact-info-error").show()
    },
    hide_captcha: function () {
        $("contact-info-captcha-id").value = "";
        $("contact-info-captcha-answer").value = "";
        $("captcha-row").hide();
        $("captcha-answer-row").hide()
    },
    parse_contacts: function (a) {
        a = a.substr(9);
        return a
    },
    fetch_contacts: function (b) {
        Event.stop(b);
        var d = $F("username");
        var c = "";
        if (d.indexOf("@") > 0) {
            var a = d.split("@");
            d = a.first();
            c = a.last()
        }
        Referral.fetch_and_show_contacts(b, d, c, $F("email-password"), $F("contact-info-captcha-id"), $F("contact-info-captcha-answer"))
    },
    fetch_and_show_contacts: function (g, d, i, c, b, f) {
        if (g) {
            Event.stop(g)
        }
        $("contact-info-error").hide();
        Referral.show_loading_modal(i.split(".")[0]);
        d = i !== "" ? d + "@" + i : d;
        var h = {
            email: d,
            password: c,
            select_all: Referral.select_all ? 1 : 0
        };
        if (b && f) {
            Object.extend(h, {
                captcha_id: b,
                captcha_answer: f
            })
        }
        var a = new Ajax.DBRequest("/import_contacts", {
            noAutonotify: true,
            parameters: h,
            onSuccess: function (e) {
                contacts = Referral.parse_contacts(e.responseText);
                Referral.show_select_contacts(contacts)
            },
            onFailure: function (j) {
                if (j.responseText.indexOf("err:") === 0) {
                    var e = j.responseText.substr(4);
                    if (e.indexOf("captcha:") !== 0) {
                        if (Referral.hide_on_error) {
                            Modal.hide()
                        } else {
                            Referral.show_login_modal()
                        }
                        Referral.show_error(_(e))
                    } else {
                        if (Referral.hide_on_error) {
                            Modal.hide()
                        } else {
                            Referral.show_login_modal()
                        }
                        Referral.show_captcha(e.substr(8))
                    }
                } else {
                    Referral.show_error(_("Unexpected server error."));
                    if (Referral.hide_on_error) {
                        Modal.hide()
                    } else {
                        Referral.show_login_modal()
                    }
                }
            },
            cleanUp: function () {
                $("modal-title").show()
            }
        })
    },
    show_loading_modal: function (a) {
        var b = ["gmail", "yahoo", "aol", "hotmail", "live", "msn"];
        if (b.indexOf(a) > -1) {
            $("email-provider-img").src = "images/referrals_" + a + ".png";
            $("email-provider-img").show()
        } else {
            $("email-provider-img").hide()
        }
        Modal.show("Loading Contacts", $("loading-contacts-modal"), {}, "", 490);
        $("modal-title").hide()
    },
    show_select_contacts: function (h) {
        var d = 70;
        if (h.length) {
            $("contact-list").innerHTML = h;
            SuggestionInput.reset("contact-filter");
            var j = $$("#contact-list img").length;
            if (j === 0) {
                $("dropbox-users-text").style.visibility = "hidden"
            }
            var f = $$(".contact-row").length;
            var a = ungettext("Good news! We've found %d contact from your contact list. Select the contact if you'd like to invite.", "Good news! We've found %d contacts from your contact list. Select the contacts you'd like to invite.", f).format(f);
            $("contact-import-msg").update(a);
            Referral.contact_container = document.getElementById("contact-list");
            Referral.contact_rows = Referral.contact_container.childNodes;
            for (var b = 0; b < Referral.contact_rows.length; b += 1) {
                var k = Referral.contact_rows[b];
                k.search_text = k.childNodes[1].firstChild.innerHTML + k.childNodes[2].firstChild.innerHTML;
                var c = $(k.firstChild.firstChild);
                c.observe("click", Referral.checkbox_clicked)
            }
            Referral.fresh = true;
            Referral.update_invite_count()
        }
        var g = !h.length ? "no-contacts-modal" : "select-contacts-modal";
        var e = !h.length ? _("Oops! No Contacts Here.") : _("Choose Contacts");
        Modal.show(e, $(g), {
            action: Referral.action
        }, null, 600);
        Referral.filter_observer = new Form.Element.Observer("contact-filter", 0.5, function (i, l) {
            if (!i.defaulted) {
                Referral.filter(l)
            }
        })
    },
    checkbox_clicked: function (a) {
        Referral.fresh = false;
        Referral.update_invite_count()
    },
    update_invite_count: function (b) {
        if (!b && Referral.contact_rows) {
            b = 0;
            for (var a = 0; a < Referral.contact_rows.length; a += 1) {
                if (Referral.contact_rows[a].firstChild.firstChild.checked) {
                    b += 1
                }
            }
        }
        var c = ungettext("Invite %d friend", "Invite %d friends", b).format(b);
        $("select-contacts-modal").down("input[type=button]").setValue(c)
    },
    select_all_contacts: function () {
        $$(".contact-check input").each(function (a) {
            a.checked = true
        });
        Referral.update_invite_count();
        return false
    },
    select_no_contacts: function () {
        $$(".contact-check input").each(function (a) {
            a.checked = false
        });
        Referral.update_invite_count(0);
        return false
    },
    insert_contacts: function () {
        var b = [];
        $$(".contact-check").each(function (c) {
            if (c.checked) {
                b.push(c.value)
            }
        });
        if (b.length) {
            SuggestionInput.clear("invite-recip");
            var a = $F("invite-recip");
            if (a) {
                a += ", "
            }
            $("invite-recip").setValue(a + b.join(", "))
        }
        Modal.hide()
    },
    filter: function (f) {
        if (f === Referral.last_search || (Referral.last_search === undefined && f === "")) {
            return
        }
        if (Referral.fresh) {
            Referral.fresh = false;
            Referral.select_no_contacts()
        }
        Referral.last_search = f;
        var a = 0;
        var e = new RegExp(RegExp.escape(f.strip()).split(/[;,\s]+/).join(".*"), "i");
        Referral.contact_container.style.display = "none";
        var b = Referral.contact_rows.length;
        while (b--) {
            var d = Referral.contact_rows[b];
            var c = d.style;
            if (e.test(d.search_text)) {
                if (a % 2 === 0) {
                    c.background = "#ffffff"
                } else {
                    c.background = "#f4faff"
                }
                c.display = "";
                a += 1
            } else {
                c.display = "none"
            }
        }
        Referral.update_invite_count();
        Referral.contact_container.style.display = ""
    },
    do_submit: function (a) {
        assert(Referral.action && typeof(Referral.action) == "function", "Finished with contact list importer but have no callback");
        Referral.action(a)
    },
    do_cancel: function () {
        assert(Referral.cancel_action && typeof(Referral.cancel_action) == "function", "Finished with contact list importer but have no cancel callback");
        Referral.cancel_action()
    },
    hide_warning: function (c, a) {
        var b = function () {
            Referral.hide(c, a)
        };
        Modal.icon_show("group_add", _("Remove Referral?"), $("referral_warning"), {
            action: b
        })
    },
    hide: function (c, b) {
        c = $(c);
        assert(c, "Referral elm doesn't exist");
        assert(Util.isNumber(b), "Referral id is not a number");
        Modal.hide();
        var a = new Ajax.DBRequest("/account/hide_referral", {
            parameters: {
                referral_id: b
            },
            onSuccess: function (d) {
                var f = c.up("tr");
                var e = new Effect.Fade(f)
            }
        })
    },
    status_tooltip: function (d, a, c) {
        var b = a <= 4 ? a.toString() : "invalid";
        Tooltip.show(d, $("referral_" + b).innerHTML.format({
            "email-address": c
        }))
    },
    get_invite_status: function () {
        var b = $("referral_email");
        if (!b || b.defaulted || !b.value.strip()) {
            return
        }
        $("invite_status_result").update();
        Forms.add_loading("status-button");
        var a = new Ajax.DBRequest("/referral_status", {
            parameters: {
                email: b.value
            },
            onSuccess: function (c) {
                b.blur();
                SuggestionInput.reset("referral_email");
                b.focus();
                $("invite_status_result").update(c.responseText)
            },
            cleanUp: function () {
                Forms.remove_loading()
            }
        })
    }
};
var Account = {
    referralPages: {},
    referralCurrentPage: -1,
    referralTabClick: function () {
        if (Account.referralCurrentPage != -1) {
            return
        }
        Account.getReferralsPage(0)
    },
    getReferralsPage: function (b) {
        Account.referralCurrentPage = b;
        if (Account.referralPages[b]) {
            Account.showReferrals(b)
        } else {
            Feed.showLoading(false, $("referrals-container"));
            var a = new Ajax.DBRequest("/account/referralspage/" + (b).toString(), {
                onSuccess: function (c) {
                    Account.referralPages[b] = c.responseText;
                    Account.showReferrals(b)
                }
            })
        }
        return false
    },
    showReferrals: function (a) {
        Feed.hideLoading();
        $("referrals-container").update(Account.referralPages[a])
    }
};
var LP = {
    interval: 10000,
    slideshow: function () {
        if (LP.slideshow_index === undefined) {
            LP.slideshow_index = 0
        } else {
            var a = $$(".subtab");
            if (a.length - 1 <= LP.slideshow_index) {
                LP.slideshow_index = 0
            } else {
                LP.slideshow_index += 1
            }
            var b = a[LP.slideshow_index];
            Tabs.fadeShow(b.down("a"), b.id.split("-").first())
        }
        LP.timeout = setTimeout(LP.slideshow, LP.interval)
    },
    stop_slideshow: function () {
        clearTimeout(LP.timeout)
    }
};
var Help = {
    toggle_more_help: false,
    search_complete: function (b) {
        $("hide_on_search").hide();
        if (Help.toggle_more_help) {
            $("morehelp").show()
        }
        var a = _("Search results for '%(search_query)s'").format({
            search_query: b.escapeHTML()
        });
        $("search-results-title").update(a);
        $("search-results-container").show()
    },
    search_empty: function () {
        if (Help.toggle_more_help) {
            $("morehelp").hide()
        }
        $("hide_on_search").show();
        $("search-results-container").hide()
    },
    show_os: function (b, c, a) {
        c = $(c);
        $$(".os-filter").invoke("removeClassName", "selected");
        c.addClassName("selected");
        $$(".help-os-section").invoke("hide");
        $$(".help-os-" + a).invoke("show");
        Event.stop(b)
    },
    vote: function (c, d) {
        var b = new Ajax.DBRequest("/help/" + c + "/vote/" + d);
        var a = new Effect.Fade("help-vote-cont");
        Notify.ServerSuccess(_("Thanks for your feedback!"))
    }
};
var DBCheckbox = {
    register_all: function () {
        var b = $$(".checkbox");
        for (var a = 0; a < b.length; a += 1) {
            DBCheckbox.register(b[a])
        }
    },
    register_browse: function () {
        var c = Browse.files;
        for (var b = 0, a = c.length; b < a; b += 1) {
            c[b].checkbox.selected = false
        }
    },
    register: function (a) {
        a.addClassName("s_checkbox sprite");
        a.selected = false;
        return a
    },
    toggle: function (a) {
        if (a.selected) {
            DBCheckbox.deselect(a)
        } else {
            DBCheckbox.select(a)
        }
    },
    select: function (a) {
        Sprite.replace(a, "checkbox", "checkbox_checked");
        a.selected = true
    },
    deselect: function (a) {
        Sprite.replace(a, "checkbox_checked", "checkbox");
        a.selected = false
    }
};
document.observe("dom:loaded", DBCheckbox.register_all);
var TabList = Class.create({
    initialize: function (a, b, c) {
        this.lists = a;
        this.initialize_lists(a);
        if (b) {
            this.tabs = b;
            this.tab_map = c;
            this.initialize_tabs()
        }
    },
    initialize_lists: function () {
        var e = this;
        for (var c = 0; c < this.lists.length; c += 1) {
            var d = $(this.lists[c]).select("a");
            for (var b = 0; b < d.length; b += 1) {
                var f = d[b];
                var a = (function (g) {
                    return function (i, h) {
                        g.list_click(g, i, h)
                    }
                }(e));
                f.db_observe("click", a)
            }
        }
    },
    initialize_tabs: function () {
        var b = this;
        for (var a = 0; a < this.tabs.length; a += 1) {
            var c = $(this.tabs[a]);
            if (!c) {
                continue
            }(function () {
                var d = a;
                c.db_observe("click", function (g, f) {
                    b.tab_click(b, g, f, d)
                })
            }())
        }
    },
    list_click: function (c, b, d) {
        for (var a = 0; a < c.lists.length; a += 1) {
            $(c.lists[a]).select("a").invoke("removeClassName", "selected")
        }
        d.addClassName("selected")
    },
    tab_click: function (e, d, f, a) {
        for (var c = 0; c < e.tabs.length; c += 1) {
            $(e.tabs[c]).removeClassName("selected")
        }
        f.addClassName("selected");
        for (var b = 0; b < e.lists.length; b += 1) {
            $(e.lists[b]).hide()
        }
        $(e.tab_map[a]).show()
    }
});
var SharedFolderInvites = {
    pages: {},
    contents: {},
    register_all: function () {
        $$(".expand-invite").each(function (a) {
            SharedFolderInvites.register(a)
        })
    },
    register: function (a) {
        a.db_observe("click", SharedFolderInvites.expand)
    },
    expand: function (g, f, b) {
        Event.stop(g);
        f = $(f);
        if (SharedFolderInvites.animating) {
            return
        }
        var c = f.up(".invite");
        var d = [];
        SharedFolderInvites.get_sf_contents(c, b);
        if (c.hasClassName("active")) {
            d.push(SharedFolderInvites.hide(c))
        } else {
            d.push(SharedFolderInvites.show(c))
        }
        $$("div.invite.active").each(function (e) {
            if (e != c) {
                d.push(SharedFolderInvites.hide(e))
            }
        });
        SharedFolderInvites.animating = true;
        var a = new Effect.Parallel(d, {
            duration: 0.5,
            afterFinish: function () {
                SharedFolderInvites.animating = false
            }
        })
    },
    show: function (b) {
        b.addClassName("active");
        var c = b.down(".invite-details");
        var a = b.down(".toggler");
        Sprite.replace(a, "plus", "minus");
        return new Effect.BlindDown(c, {
            sync: true,
            afterFinish: function () {
                c.style.height = "auto"
            }
        })
    },
    hide: function (b) {
        b.removeClassName("active");
        var c = b.down(".invite-details");
        var a = b.down(".toggler");
        Sprite.replace(a, "minus", "plus");
        return new Effect.BlindUp(c, {
            sync: true
        })
    },
    show_page: function (a) {
        Feed.hideLoading();
        $("invites-container").update(SharedFolderInvites.pages[a]);
        SharedFolderInvites.register_all()
    },
    get_page: function (b) {
        if (!SharedFolderInvites.pages[0] && b == 1) {
            SharedFolderInvites.pages[0] = $("invites-container").innerHTML
        }
        if (SharedFolderInvites.pages[b]) {
            SharedFolderInvites.show_page(b)
        } else {
            Feed.showLoading(false, $("invites-container"), false, true);
            var a = new Ajax.DBRequest("/share_ajax/invitation_page?page=" + b, {
                onSuccess: function (c) {
                    SharedFolderInvites.pages[b] = c.responseText;
                    SharedFolderInvites.show_page(b)
                }
            })
        }
        return false
    },
    get_sf_contents: function (c, b) {
        if (SharedFolderInvites.contents[b]) {
            SharedFolderInvites.show_sf_contents(c, b)
        } else {
            var a = new Ajax.DBRequest("/share_ajax/sf_contents?ns_id=" + b, {
                onSuccess: function (d) {
                    SharedFolderInvites.contents[b] = d.responseText;
                    SharedFolderInvites.show_sf_contents(c, b)
                }
            })
        }
    },
    show_sf_contents: function (b, a) {
        b.down(".folder-contents").update(SharedFolderInvites.contents[a])
    },
    mailto: function (b, a) {
        Event.stop(b);
        window.location = "mailto:" + a
    }
};
var AccountExtras = {
    prices: {},
    watch_id: 0,
    show_detail: function (a, d, b) {
        var c = _("What is %(feature_name)s?").format({
            feature_name: a
        });
        Modal.icon_show(b, c, $(d + "-modal"), {}, false);
        return false
    },
    register_price_watch: function (c, a, b) {
        AccountExtras.prices[c] = [a, b];
        if (!AccountExtras.watch_id) {
            AccountExtras.watch_id = setInterval(AccountExtras.update_prices, 200)
        }
    },
    update_prices: function () {
        var d = $("yearly").checked;
        var b = d ? 1 : 0;
        var a = d ? _("year") : _("month");
        for (var c in AccountExtras.prices) {
            $(c + "-price").update(AccountExtras.prices[c][b]);
            $(c + "-priceperiod").update(a)
        }
    }
};
var DowngradeReasons = {
    reasons: {},
    addReason: function (a, b) {
        DowngradeReasons.reasons[a] = b
    },
    change: function (d, b) {
        d = parseInt(d, 10);
        var a = $(b);
        assert(a, "Couldn't find container for DowngradeReason");
        if (DowngradeReasons.reasons[d]) {
            a.show();
            var c = Sprite.make("information", {});
            c.addClassName("text-img");
            a.update(c);
            a.insert(DowngradeReasons.reasons[d])
        } else {
            a.hide()
        }
    }
};
var Restore = {
    next: function (a, d) {
        d = $(d);
        var b = $$("ul.selected")[0];
        var c = b.next("ul");
        c.addClassName("selected");
        b.removeClassName("selected");
        if (c.next("ul")) {
            Restore.show_next_link()
        } else {
            Restore.hide_next_link()
        }
        Restore.show_prev_link();
        Restore.inc_page(1)
    },
    prev: function (a, d) {
        d = $(d);
        var b = $$("ul.selected")[0];
        var c = b.previous("ul");
        c.addClassName("selected");
        b.removeClassName("selected");
        if (c.previous("ul")) {
            Restore.show_prev_link()
        } else {
            Restore.hide_prev_link()
        }
        Restore.show_next_link();
        Restore.inc_page(-1)
    },
    inc_page: function (c) {
        var b = parseInt($("page-num").innerHTML, 10);
        var a = b + c;
        $("page-num").update(a)
    },
    hide_next_link: function () {
        $("next-page").update()
    },
    show_next_link: function () {
        var b = new Element("a", {
            href: "#",
            onclick: "Restore.next(event, this); return false;"
        });
        b.update(_("Next") + " &raquo;");
        $("next-page").update(b)
    },
    show_prev_link: function () {
        var b = new Element("a", {
            href: "#",
            onclick: "Restore.prev(event, this); return false;"
        });
        b.update("&laquo; " + _("Prev"));
        $("prev-page").update(b)
    },
    hide_prev_link: function () {
        $("prev-page").update()
    }
};
var Votebox = {
    page: "0",
    view: "popular",
    add_comment: function (b) {
        if (b) {
            Event.stop(b)
        }
        var a = $("comment_form");
        Forms.ajax_submit(a, false, function (c) {
            var d = $("feature-comments");
            d.innerHTML = c.responseText + d.innerHTML;
            $("comment").setValue("");
            d.scrollTo()
        }, false, b && b.target)
    },
    edit_comment: function (d, f, c) {
        Event.stop(d);
        f = $(f);
        var a = f.up().next(".feature-comment-text");
        if (a.down("textarea")) {
            return
        }
        a.old_comment = a.innerHTML;
        var b = '<p><textarea class="textarea act_as_block" id="comment_edit_#{comment_id}" rows="5" cols="4" >#{comment_content}</textarea></p><p style="text-align:right; margin-bottom:0;"><input type="button" id="comment_save_#{comment_id}" value="Save" class="button"/> <input type="button" id="comment_cancel_#{comment_id}" class="button grayed" value="Cancel"/></p>';
        b = b.interpolate({
            comment_id: c,
            comment_content: a.old_comment.strip().replace(/<br\/>|<br>/g, "\n")
        });
        a.update(b);
        $("comment_save_" + c).observe("click", function (g) {
            Votebox.save_comment(g, c)
        });
        $("comment_cancel_" + c).observe("click", function (g) {
            Votebox.cancel_comment(g, c)
        });
        ActAsBlock.register(a)
    },
    delete_comment: function (d, f, b) {
        Event.stop(d);
        f = $(f);
        var a = f.up(".feature-comment");
        var c = new Ajax.DBRequest("/votebox/delete_comment", {
            parameters: {
                comment_id: b
            }
        });
        a.remove()
    },
    cancel_comment: function (c, b) {
        Event.stop(c);
        var a = $("comment_edit_" + b).up(".feature-comment-text");
        a.update(a.old_comment)
    },
    save_comment: function (d, b) {
        Event.stop(d);
        var a = $("comment_edit_" + b).getValue();
        var c = new Ajax.DBRequest("/votebox/edit_comment", {
            parameters: {
                comment_id: b,
                comment_text: a
            }
        });
        a = a.escapeHTML().replace(/\n/g, "<br/>");
        $("comment_edit_" + b).up(".feature-comment-text").update(a)
    },
    submit_feature: function (b) {
        Event.stop(b);
        var a = $("add-feature-request");
        Forms.ajax_submit(a, false, function (c) {
            window.location = c.responseText
        }, false, b.target)
    },
    how_voting_works: function () {
        Modal.icon_show("comments", _("How Voting Works"), $("howvotingworks"))
    },
    votes_left: function () {
        return parseInt($("votes-left").innerHTML, 10)
    },
    vote: function (f, d) {
        if (d) {
            Event.stop(d)
        }
        f = $(f);
        var b = f.id.slice(4);
        var a = Votebox.votes_left();
        if (a <= 0) {
            Votebox.show_more_votes_modal();
            return
        }
        var c = new Ajax.DBRequest("/votebox/vote", {
            parameters: {
                feature_id: b
            },
            onSuccess: function () {
                if (a == 1) {
                    window.location.reload()
                }
            },
            onFailure: function (e) {
                Votebox.adjust_votes_left(1);
                Votebox.adjust_votes_total(f, -1);
                Votebox.adjust_votes_bubble(f, -1)
            }
        });
        Votebox.adjust_votes_left(-1);
        Votebox.adjust_votes_total(f, 1);
        Votebox.adjust_votes_bubble(f, 1)
    },
    tab_click: function (b, c, a) {
        Event.stop(b);
        Votebox.list_set_url({
            view: a
        });
        Votebox.tab(c)
    },
    tab: function (a) {
        a = $(a);
        a.up("ul").select(".selected").invoke("removeClassName", "selected");
        a.up().addClassName("selected")
    },
    list_set_url: function (b) {
        clearTimeout(Tabs.check_interval);
        var c = b.page || Votebox.page || 0;
        var a = b.view || Votebox.view || "popular";
        if (a != Votebox.view) {
            c = "0"
        }
        var d = ["votebox", a, c].join(":");
        window.location.href = "#" + d;
        Votebox.list_hash_update(a, c)
    },
    list_hash_update: function (a, b) {
        var c = a != Votebox.view || b != Votebox.page;
        if (!c) {
            return
        }
        a = a || "popular";
        b = b || 0;
        Votebox.view = a;
        Votebox.get_features(b);
        Votebox.tab($(a + "-tab").down())
    },
    comment_set_url: function (a) {
        var b = ["votebox", a].join(":");
        window.location.href = "#" + b;
        Votebox.comment_hash_update(a)
    },
    comment_hash_update: function (a) {
        if (a != Votebox.page) {
            a = a || 0;
            Votebox.get_comments(a)
        }
    },
    adjust_votes_left: function (b) {
        var a = Votebox.votes_left();
        a += b;
        $("votes-left").update(a)
    },
    adjust_votes_total: function (d, b) {
        var a = d.previous(".votecount").down("span");
        if (Util.isNumber(a.innerHTML)) {
            var c = parseInt(a.innerHTML, 10);
            a.update(c + b)
        }
    },
    adjust_votes_bubble: function (f, d) {
        var e = f.up(".votebox");
        var b = e.down(".ebubble");
        if (b) {
            var c = b.down(".c");
            var a = parseInt(c.innerHTML, 10);
            a += d;
            if (a === 0) {
                b.remove()
            } else {
                c.update("+" + a)
            }
        } else {
            e.insert(EventBubble.make("+1"))
        }
    },
    show_more_votes_modal: function () {
        Modal.icon_show("comments", _("Out of Votes"), $("outofvotes"))
    },
    features_cache: {},
    features_key: function (a) {
        return Votebox.view + "_" + Votebox.category + "_" + a
    },
    get_features: function (c) {
        var a = Votebox.features_key(c);
        Votebox.page = c;
        assert(Util.isNumber(c), "Feature page is not a number: " + c);
        if (Votebox.features_cache[a]) {
            Votebox.show_features(c)
        } else {
            var d = {};
            d.page = c;
            if (Votebox.view) {
                d.view = Votebox.view
            }
            if (Votebox.category) {
                d.category = Votebox.category
            }
            Feed.showLoading(false, $("features"));
            var b = new Ajax.DBRequest("/votebox/more_features", {
                parameters: d,
                onSuccess: function (e) {
                    Votebox.features_cache[a] = e.responseText;
                    Votebox.show_features(c)
                },
                onComplete: function () {
                    Feed.hideLoading()
                }
            })
        }
    },
    show_features: function (b) {
        var a = Votebox.features_key(b);
        $("features").update(Votebox.features_cache[a])
    },
    comments_cache: {},
    get_comments: function (b) {
        Votebox.page = b;
        assert(Util.isNumber(b), "Comment page is not a number" + b);
        if (Votebox.comments_cache[b]) {
            Votebox.show_comments(b)
        } else {
            Feed.showLoading(false, $("feature-comments"));
            var a = new Ajax.DBRequest("/votebox/more_comments", {
                parameters: {
                    feature_id: Votebox.feature_id,
                    page: b
                },
                onSuccess: function (c) {
                    Votebox.comments_cache[b] = c.responseText;
                    Votebox.show_comments(b)
                },
                onComplete: function () {
                    Feed.hideLoading()
                }
            })
        }
    },
    show_comments: function (a) {
        $("feature-comments").update(Votebox.comments_cache[a])
    },
    search: function (b) {
        Votebox.last_search = b;
        if ($("feature-search").defaulted || b === "") {
            if (b === "") {
                $("hideme").show();
                $("searchresults").hide();
                $("add-feature").hide()
            }
            return
        }
        var a = new Ajax.DBRequest("/votebox/search", {
            parameters: {
                search_string: b
            },
            onSuccess: function (c) {
                $("hideme").hide();
                $("searchresults").show();
                $("searchresults").update(c.responseText);
                $("add-feature").show();
                ActAsBlock.register(false, $("add-feature"))
            }
        })
    }
};
var Bubble = {
    make: function (o, z, q, m) {
        z = z || "left";
        if (["left", "right"].contains(z)) {
            q = q || "middle";
            assert(["top", "middle", "bottom"].contains(q), "expected tail position ['top', 'middle', 'bottom'], got %s".format(q))
        } else {
            if (["bottom"].contains(z)) {
                q = q || "center";
                assert(["left", "center", "right"].contains(q), "expected tail position ['left', 'center', 'right'], got %s".format(q))
            } else {
                assert(false, "unexpected tail positon, got %s".format(q))
            }
        }
        var p = new Element("table");
        p.addClassName("bubble");
        if (m) {
            p.style.width = m + "px"
        }
        var a = new Element("tbody");
        var y = new Element("tr");
        var i = new Element("td");
        i.addClassName("tl");
        var j = new Element("td");
        j.addClassName("t");
        var e = new Element("td");
        e.addClassName("tr");
        y.insert(i);
        y.insert(j);
        y.insert(e);
        a.insert(y);
        var w = new Element("tr");
        var n = new Element("td");
        n.addClassName("l");
        if (z == "left") {
            var g = new Element("img", {
                src: "images/bubble_arrow.png"
            });
            g.addClassName("arrow");
            n.insert(g);
            n.vAlign = q
        }
        var s = new Element("td");
        s.addClassName("c");
        s.update(o);
        var k = new Element("td");
        k.addClassName("r");
        if (z == "right") {
            var h = new Element("img", {
                src: "images/bubble_arrow_right.png"
            });
            h.addClassName("rarrow");
            k.insert(h);
            k.vAlign = q
        }
        w.insert(n);
        w.insert(s);
        w.insert(k);
        a.insert(w);
        var u = new Element("tr");
        var d = new Element("td");
        d.addClassName("bl");
        var v = new Element("td");
        v.addClassName("b");
        if (z == "bottom") {
            var f = new Element("img", {
                src: "images/bubble_arrow_bottom.png"
            });
            f.addClassName("barrow");
            v.insert(f);
            v.style.textAlign = q
        }
        var x = new Element("td");
        x.addClassName("br");
        u.insert(d);
        u.insert(v);
        u.insert(x);
        a.insert(u);
        p.insert(a);
        return p
    }
};
var Timezone = {
    check_timezone: function () {
        if (!Constants.uid) {
            return
        }
        var a = Timezone.get_current_timezone();
        if (Constants.auto_timezone_offset === undefined || Constants.auto_timezone_offset != a) {
            Timezone.update(a)
        }
    },
    get_current_timezone: function () {
        var c = new Date();
        c.setSeconds(0);
        c.setMilliseconds(0);
        var b = c.toGMTString();
        var d = new Date(b.substring(0, b.lastIndexOf(" ") - 1));
        var a = (c - d) / (1000 * 60 * 60);
        return a
    },
    update: function (b) {
        assert(typeof(b) == "number", "Timezone offset was not a number: " + b);
        var a = new Ajax.DBRequest("/set_timezone", {
            parameters: {
                offset: b
            },
            noAutonotify: true
        })
    },
    on_change: function () {
        var a = [];
        var b = [$("timezone_area"), $("timezone_location"), $("timezone_city")];
        b.each(function (c) {
            if (c) {
                a.push($F(c))
            }
        });
        Timezone.update_form(a)
    },
    update_form: function (l) {
        l = l || ["America"];
        assert(Timezone.tree, "Timezone tree missing...");
        $("tz").update();
        var a = ["timezone_area", "timezone_location", "timezone_city"];
        var e = Timezone.tree;
        var c = Math.max(l.length + 1, 2);
        for (var g = 0; g < c; g += 1) {
            var d = l[g];
            var n = Object.keys(e);
            if (!n.length) {
                break
            }
            var m = new Element("select", {
                id: a[g],
                name: a[g]
            });
            m.observe("change", Timezone.on_change);
            for (var f = 0, k = n.length; f < k; f += 1) {
                var b = n[f];
                var h = new Element("option");
                h.value = b;
                h.update(b);
                if (b == d) {
                    h.selected = true
                }
                m.appendChild(h)
            }
            $("tz").appendChild(m);
            e = e[d]
        }
        Util.syncHeight()
    },
    auto: function () {
        var a = $F("timezone_auto");
        if (a) {
            $("tz").update()
        } else {
            Timezone.update_form()
        }
    },
    build_tree: function (b) {
        var a = {};
        b.each(function (e) {
            var c = e.split("/");
            var d = a;
            c.each(function (f) {
                if (!d[f]) {
                    d[f] = {}
                }
                d = d[f]
            })
        });
        Timezone.tree = a
    }
};
document.observe("dom:loaded", Timezone.check_timezone);
var Profiler = {
    stack: [],
    start_time: new Hash(),
    total_time: new Hash(),
    start: function (a) {
        assert(a.indexOf("_") === -1, "Profiler label is not allowed to contain _");
        Profiler.stack.push(a);
        var b = Profiler.get_key();
        assert(Profiler.start_time.get(b) === undefined, "Profiler for " + a + " already started.");
        Profiler.start_time.set(b, new Date().getTime())
    },
    stop: function () {
        var a = Profiler.get_key();
        var d = Profiler.start_time.get(a);
        Profiler.start_time.set(a, undefined);
        var e = new Date().getTime() - d;
        var c = Profiler.total_time.get(a);
        if (c) {
            Profiler.total_time.set(a, c + e)
        } else {
            Profiler.total_time.set(a, e)
        }
        var b = Profiler.stack.pop();
        if (Profiler.stack.length === 0) {
            Profiler.print()
        }
    },
    get_key: function () {
        return Profiler.stack.join("_")
    },
    reset: function () {
        Profiler.start_time = new Hash();
        Profiler.total_time = new Hash()
    },
    print: function () {
        var b = Profiler.total_time.keys();
        b.sort(function (d, c) {
            var e = d.split("_").length;
            var f = c.split("_").length;
            if (e < f) {
                return -1
            } else {
                if (e === f) {
                    return 0
                } else {
                    return 1
                }
            }
        });
        var a = function (q, h) {
            var m = q.split("_");
            var p = m.last();
            var o = "&nbsp;";
            for (var g = 0; g < h; g += 1) {
                o += "&nbsp;&nbsp;"
            }
            var e = Profiler.total_time.get(q);
            Util.log(o, p, ":", e, "ms");
            for (var l = 0, c = b.length; l < c; l += 1) {
                var f = b[l];
                var n = f.split("_").length - 1;
                if (f.startsWith(q + "_") && n == h + 1) {
                    a(f, n)
                }
            }
        };
        Util.log("-------------");
        a(b[0], 0);
        Profiler.reset()
    }
};
var DBCalendar = Class.create({
    initialize: function (b, a) {
        this.options = a || {};
        this.container = $(b);
        assert(this.container, "Couldn't find the element");
        this.today = new Date();
        if (this.options.disable_future) {
            this.options.last_day = this.options.last_day || this.today
        }
        if (this.options.disable_past) {
            this.options.first_day = this.options.first_day || new Date(this.today.getFullYear(), this.today.getMonth(), this.today.getDate())
        }
        this.current_day = Util.start_of_day(this.options.selected_day || new Date(this.today.getFullYear(), this.today.getMonth(), 1));
        this.selected_day = Util.start_of_day(this.options.selected_day || new Date(this.today.getFullYear(), this.today.getMonth(), this.today.getDate()));
        this.render()
    },
    change_month: function (b, a) {
        Event.stop(b);
        this.current_day.setMonth(a);
        this.render();
        if (this.options.onMonthChange) {
            this.options.onMonthChange(this.current_day)
        }
    },
    change_day: function (b, a) {
        Event.stop(b);
        this.container.select(".selected").invoke("removeClassName", "selected");
        $(b.target).addClassName("selected");
        this.selected_day.setMonth(this.current_day.getMonth());
        this.selected_day.setYear(this.current_day.getFullYear());
        this.selected_day.setDate(a);
        if (this.options.onDateChange) {
            this.options.onDateChange(this.selected_day)
        }
    },
    render: function () {
        var e = this.render_days();
        this._next_month = (function (f) {
            this.change_month(f, this.current_day.getMonth() + 1)
        }).bind(this);
        this._prev_month = (function (f) {
            this.change_month(f, this.current_day.getMonth() - 1)
        }).bind(this);
        var b = new Element("a");
        b.addClassName("changemonth next");
        b.update(Sprite.make("arrowright", {}));
        Event.observe(b, "click", this._next_month);
        var c = new Element("a");
        c.addClassName("changemonth prev");
        c.update(Sprite.make("arrowleft", {}));
        Event.observe(c, "click", this._prev_month);
        var d = new Element("div");
        d.addClassName("calendar clearfix");
        var a = new Element("h5");
        a.update(_("%(month)s %(year)s").format({
            month: Util.months[this.current_day.getMonth()],
            year: this.current_day.getFullYear()
        }));
        d.insert(b);
        d.insert(c);
        d.insert(a);
        d.insert(e);
        this.container.update(d)
    },
    render_days: function () {
        var f = new Date(this.current_day.getFullYear(), this.current_day.getMonth(), 1);
        var e = f.getDay();
        var g = new Element("div");
        g.addClassName("days");
        for (var a = e; a > 0; a -= 1) {
            var d = new Date(f.getFullYear(), f.getMonth(), f.getDate());
            d.setDate(d.getDate() - a);
            g.insert(this.render_day(d, true))
        }
        var c = new Date(this.current_day.getFullYear(), this.current_day.getMonth(), 1);
        while (c.getMonth() == this.current_day.getMonth()) {
            g.insert(this.render_day(c));
            c = new Date(this.current_day.getFullYear(), this.current_day.getMonth(), c.getDate() + 1)
        }
        var b = new Date(this.current_day.getFullYear(), this.current_day.getMonth() + 1, 0);
        while (b.getDay() != 6) {
            b = new Date(b.getFullYear(), b.getMonth(), b.getDate() + 1);
            g.insert(this.render_day(b, true))
        }
        return g
    },
    render_day: function (c, d) {
        if (this.options.last_day) {
            d = d || c > this.options.last_day
        }
        if (this.options.first_day) {
            d = d || c < this.options.first_day
        }
        var b;
        if (d) {
            b = new Element("span")
        } else {
            b = new Element("a")
        }
        b.update(c.getDate());
        b.addClassName("date");
        if (this.selected_day.getDate() == c.getDate() && this.selected_day.getMonth() == c.getMonth() && this.selected_day.getFullYear() == c.getFullYear()) {
            b.addClassName("selected")
        }
        if (d) {
            b.addClassName("inactive")
        } else {
            this._change_day = (function (a) {
                this.change_day(a, c.getDate())
            }).bind(this);
            Event.observe(b, "click", this._change_day)
        }
        Util.disableSelection(b);
        return b
    }
});
var EventDatePicker = {
    show_calendar: function (a) {
        if (EventDatePicker.shown) {
            return
        }
        Event.stop(a);
        if (!EventDatePicker.calendar) {
            var b = new Element("div", {
                id: "cal_container"
            });
            b.observe("click", function (d) {
                Event.stop(d)
            });
            $(document.body).insert(b);
            EventDatePicker.calendar = new DBCalendar("cal_container", {
                onDateChange: function (e) {
                    EventDatePicker.change_date(e, 0)
                },
                disable_future: true,
                first_day: EventDatePicker.first_event
            });
            b.absolutize();
            var c = $("cal_date");
            b.clonePosition(c, {
                setWidth: false,
                setHeight: false,
                offsetTop: c.getHeight() - 1,
                offsetLeft: c.getWidth() - b.down().getWidth()
            })
        }
        $("cal_container").show();
        $(document.body).observe("click", EventDatePicker.hide_calendar);
        EventDatePicker.shown = true
    },
    hide_calendar: function (a) {
        Event.stop(a);
        $("cal_container").hide();
        $(document.body).stopObserving("click", EventDatePicker.hide_calendar);
        EventDatePicker.shown = false
    },
    change_date: function (a, b) {
        if (b !== undefined) {
            Feed.page_num = 0
        }
        var c = $("cur_date_text");
        c.update(a.localize());
        Feed.set_url({
            date: Util.niceDate(a)
        })
    }
};
var TextInputDatePicker = Class.create({
    initialize: function (c, b) {
        this.options = {
            include_seconds: true,
            choose_eod: false
        };
        Object.extend(this.options, b || {});
        this.input = $(c);
        assert(this.input, "Couldn't find the element " + c.toString());
        var a = new Date();
        var e = this.input.value ? Util.from_mysql_date(this.input.value) : false;
        var d = new Date(a.getUTCFullYear(), a.getUTCMonth(), a.getUTCDate());
        this.cal_icon = Sprite.make("calendar_view_month", {
            align: "absmiddle"
        });
        this.cal_container = new Element("div", {
            id: "cal_container_" + c,
            style: "display: none; position: absolute; z-index: 1"
        });
        this.calendar = new DBCalendar(this.cal_container, {
            onDateChange: this.onDateChange.bind(this),
            last_day: d,
            selected_day: e
        });
        this.input.insert({
            after: this.cal_icon
        });
        this.cal_icon.observe("click", this.toggle_cal.bindAsEventListener(this));
        this.cal_container.clonePosition(this.input, {
            setWidth: false,
            setHeight: false,
            offsetTop: this.input.getHeight()
        });
        this.cal_icon.insert({
            after: this.cal_container
        })
    },
    toggle_cal: function (a) {
        if (a) {
            Event.stop(a)
        }
        this.cal_container.toggle()
    },
    hide_cal: function (a) {
        if (a) {
            Event.stop(a)
        }
        this.cal_container.hide()
    },
    onDateChange: function (a) {
        if (this.options.choose_eod) {
            a.setTime(Util.start_of_day(a).getTime() + 86399999)
        }
        this.input.value = Util.to_mysql_date(a, true);
        this.hide_cal()
    }
});
var HashKeeper = {
    iframe: null,
    last_hash: null,
    check_hash: function () {
        if (HashKeeper.reloading) {
            return
        }
        if (!HashKeeper.iframe) {
            HashKeeper.iframe = $("hashkeeper")
        }
        var a = HashKeeper.get_iframe_hash();
        var b = Util.url_hash();
        if (a != HashKeeper.last_hash && (HashKeeper.last_hash || a)) {
            HashKeeper.last_hash = a;
            window.location = "#" + a;
            return
        }
        if (HashKeeper.last_hash != b) {
            HashKeeper.set_iframe_hash(b)
        }
    },
    get_iframe_hash: function () {
        var a = HashKeeper.iframe.contentWindow.location.href.split("#")[1];
        return a || ""
    },
    set_iframe_hash: function (a) {
        if (!a || a == "undefined") {
            return
        }
        HashKeeper.last_hash = a;
        HashKeeper.reloading = 1;
        HashKeeper.iframe.contentWindow.location.href = "/blank?t=" + new Date().getTime() + "#" + a
    }
};
var HashRouter = {
    watch_timer: null,
    callback_map: {},
    last_hash: "",
    last_prefix: "",
    init: function () {
        HashRouter.watch_timer = setInterval(HashRouter.check_hash, 300)
    },
    watch: function (a, b) {
        HashRouter.callback_map[a] = b;
        if (!HashRouter.watch_timer) {
            HashRouter.init()
        }
    },
    check_hash: function () {
        var d = Util.url_hash();
        if (HashRouter.last_hash == d) {
            return
        }
        HashRouter.last_hash = d;
        if (HashRouter.last_prefix && d === "") {
            d = HashRouter.last_prefix + ":"
        } else {
            if (!d) {
                return
            }
        }
        var a = d.split(":");
        var c = a.first();
        HashRouter.last_prefix = c;
        var b = HashRouter.callback_map[c];
        if (b) {
            b.apply(b, a.slice(1))
        }
        $(document).fire("db:hash_change", {
            hash: d
        })
    },
    set_hash: function () {
        var a = $A(arguments).map(Util.falsy_to_empty);
        var c = a.map(encodeURIComponent);
        var b = c.join(":");
        HashRouter._set_hash(b)
    },
    _set_hash: function (a) {
        if (a === "") {
            a = "/"
        }
        HashRouter.last_hash = a;
        window.location.href = "#" + a
    }
};
if (Util.ie) {
    document.observe("dom:loaded", function () {
        HashKeeper.hash_checker = setInterval(HashKeeper.check_hash, 300)
    })
}
var DBObserver = {
    watch: function (a, b) {
        setInterval(function () {
            var d = $(a);
            assert(d, "Couldn't find watch element");
            var c = d.getValue().strip();
            if (c != d.last_search && !d.defaulted) {
                d.last_search = c;
                b(c)
            }
        }, 300)
    }
};
var Team = {
    show_add_modal: function (a) {
        Sharing.reset_wizard();
        DomUtil.fillVal(_("Invite users to this team"), "invite-more-wizard-title");
        DomUtil.fillVal(_("Invite to team"), "invite-more-wizard-share-button");
        var b = _('Add team members to "%(team_name)s"').format({
            team_name: a.escapeHTML()
        });
        Modal.icon_show("folder_user_add", b, $("invite-more-wizard"), {
            action: Team.add_users
        })
    },
    add_users: function (b) {
        Event.stop(b);
        var a = $("invite-more-form");
        assert(a, "Couldn't find the invite more form.");
        Forms.ajax_submit(a, "/account/team/add_users", function (c) {
            Modal.hide();
            $("team-member-info").update(c.responseText)
        }, function () {
            Forms.enable(a.down("input[type='submit']"))
        }, b.target, {
            team_id: Constants.team_id
        })
    },
    show_remove_modal: function (c, d, a, b) {
        DomUtil.fillVal(b, "remove-user-email");
        DomUtil.fillVal(d, "remove-user-team");
        var e = _('Remove user from "%(team_name)s"').format({
            team_name: d.escapeHTML()
        });
        Modal.icon_show("delete", e, $("remove-user-modal"), {
            user_id: a,
            button: c
        })
    },
    remove_user: function (c) {
        Event.stop(c);
        var b = Modal.vars.user_id;
        var a = new Ajax.DBRequest("/account/team/remove_user", {
            parameters: {
                team_id: Constants.team_id,
                user_id: b
            },
            onSuccess: function (d) {
                var e = Modal.vars.button.up(".bs-row");
                if (e) {
                    e.hide()
                }
                Team.decrement_used_licenses();
                Notify.ServerSuccess(_("User removed."))
            },
            cleanUp: function () {
                Modal.hide()
            }
        })
    },
    show_reinvite_modal: function (c, d, a, b) {
        DomUtil.fillVal(b, "reinvite-user-email");
        DomUtil.fillVal(d, "reinvite-user-team");
        var e = _('Resend Invite to "%(email_address)s"').format({
            email_address: b.escapeHTML()
        });
        Modal.icon_show("email", e, $("reinvite-user-modal"), {
            user_id: a,
            button: c
        })
    },
    reinvite_user: function (c) {
        Event.stop(c);
        var b = Modal.vars.user_id;
        var a = new Ajax.DBRequest("/account/team/reinvite_user", {
            parameters: {
                team_id: Constants.team_id,
                user_id: b
            },
            onSuccess: function (d) {
                Notify.ServerSuccess(_("Invite sent."));
                $("team-member-info").update(d.responseText)
            },
            cleanUp: function () {
                Modal.hide()
            }
        })
    },
    show_reset_password_modal: function (c, d, a, b) {
        DomUtil.fillVal(b, "reset-password-email");
        var e = _('Reset password for "%(email_address)s"').format({
            email_address: b.escapeHTML()
        });
        Modal.icon_show("arrow_refresh", e, $("reset-password-modal"), {
            user_id: a,
            button: c
        })
    },
    reset_password: function (c) {
        Event.stop(c);
        var b = Modal.vars.user_id;
        var a = new Ajax.DBRequest("/account/team/reset_password", {
            parameters: {
                team_id: Constants.team_id,
                user_id: b
            },
            onSuccess: function (d) {
                Notify.ServerSuccess(_("User's password reset."))
            },
            cleanUp: function () {
                Modal.hide()
            }
        })
    },
    show_admin_status_modal: function (c, i, k, e, j, f) {
        var a = j.strip() || e;
        var d, b, h, g;
        if (f) {
            d = _('Are you sure you want to make %(person_name)s an admin of "%(team_name)s?"').format({
                person_name: a.escapeHTML(),
                team_name: i.escapeHTML()
            });
            b = _("Make Admin");
            h = _("Make %(person_name)s an Admin").format({
                person_name: a.escapeHTML()
            });
            g = "user_suit"
        } else {
            d = _("Are you sure you want to remove admin privileges for %(person_name)s?").format({
                person_name: a.escapeHTML()
            });
            b = _("Remove Admin Status");
            h = _("Remove Admin Status");
            g = "user_suit_minus"
        }
        DomUtil.fillVal(e, "admin-status-email");
        DomUtil.fillVal(d, "admin-status-action");
        DomUtil.fillVal(b, "admin-status-button-action");
        Modal.icon_show(g, h, $("admin-status-modal"), {
            user_id: k,
            button: c,
            admin_on: f
        })
    },
    set_admin_status: function (c) {
        Event.stop(c);
        var b = Modal.vars.user_id;
        var a = new Ajax.DBRequest("/account/team/set_admin_status", {
            parameters: {
                team_id: Constants.team_id,
                user_id: b,
                on: Modal.vars.admin_on ? "yes" : "no"
            },
            onSuccess: function (d) {
                var e = Modal.vars.admin_on ? _("User's admin status granted.") : _("User's admin status removed.");
                Notify.ServerSuccess(e);
                $("team-member-info").update(d.responseText)
            },
            cleanUp: function () {
                Modal.hide()
            }
        })
    },
    show_team_message_modal: function (a) {
        DomUtil.fillVal(a, "team-message-team");
        var b = _('Send email to members of "%(team_name)s"').format({
            team_name: a.escapeHTML()
        });
        $("team-message").value = "";
        Modal.icon_show("page_white_get", b, $("team-message-modal"));
        Util.focus.defer("team-message")
    },
    send_team_message: function (c) {
        Event.stop(c);
        var b = $F("team-message").strip();
        if (b) {
            var a = new Ajax.DBRequest("/account/team/send_team_message", {
                parameters: {
                    team_id: Constants.team_id,
                    message: b
                },
                onSuccess: function (d) {
                    Notify.ServerSuccess(_("Message successfully sent to team."));
                    Modal.hide()
                }
            })
        }
    },
    show_migrate_modal: function (c, d, a, b) {
        DomUtil.fillVal(b, "migrate-email");
        Modal.icon_show("user_go", _('Migrate user to "%(team_name)s"').format({
            team_name: d.escapeHTML()
        }), $("migrate-modal"), {
            user_id: a,
            button: c
        })
    },
    start_migration: function (c) {
        Event.stop(c);
        var b = Modal.vars.user_id;
        var a = new Ajax.DBRequest("/account/team/start_migration", {
            parameters: {
                team_id: Constants.team_id,
                user_id: b
            },
            onSuccess: function (d) {
                Notify.ServerSuccess(_("User migration initiated."));
                $("team-member-info").update(d.responseText)
            },
            cleanUp: function () {
                Modal.hide()
            }
        })
    },
    used_licenses: 0,
    total_licenses: 0,
    set_used_licenses: function (a, b) {
        Team.used_licenses = a;
        Team.total_licenses = b;
        $("team-used-licenses").update(a);
        $("team-avail-licenses").update(b - a)
    },
    decrement_used_licenses: function () {
        Team.set_used_licenses(Team.used_licenses - 1, Team.total_licenses)
    },
    show_migration_link: function (a, b) {
        $("migration-url").value = b;
        Modal.icon_show("link", _("Migration link for %(email)s").format({
            email: a.escapeHTML()
        }), $("migrate-url-modal"));
        $("migration-url").select()
    }
};
var TokenListView = {
    sort_by_filename: function (a) {
        return parseInt(a.down(".filename .hidden").innerHTML, 10)
    },
    sort_by_size: function (a) {
        return parseInt(a.down(".filesize .hidden").innerHTML, 10)
    },
    sort_by_modified: function (a) {
        return -1 * parseInt(a.down(".modified .hidden").innerHTML, 10)
    },
    sort: function (f) {
        Event.stop(f);
        var h = Util.resolve_target(f.target, "a");
        if (h.asc != -1) {
            h.asc = -1
        } else {
            h.asc = 1
        }
        var k = h.asc;
        var a = h.className;
        var j = {
            "sort-filename": TokenListView.sort_by_filename,
            "sort-filesize": TokenListView.sort_by_size,
            "sort-modified": TokenListView.sort_by_modified
        };
        var l = $$("#list-view .filerow");
        var g = l.sort_by_key(j[a], h.asc != 1);
        l.invoke("remove");
        var m = new Element("div");
        for (var c = 0, d = g.length; c < d; c += 1) {
            m.insert(g[c])
        }
        $("list-browser").insert(m.innerHTML);
        $$(".sort-tick").invoke("remove");
        var b = Sprite.make(h.asc === 1 ? "sort-downtick-on" : "sort-uptick-on");
        b.addClassName("sort-tick");
        h.insert(b)
    }
};
var MP3Player = {
    state: false,
    file: false,
    volume_percent: 100,
    meta: {},
    on_ready: false,
    init: function (b) {
        var e = {
            type: "sound",
            id: "mp3embed"
        };
        if (b) {
            e.file = encodeURI(encodeURI(encodeURI(b)))
        }
        var d = {
            allowScriptAccess: "always"
        };
        var a = {
            name: "mp3embed"
        };
        var f = new Element("div", {
            id: "mp3embed"
        });
        var c = document.body;
        if (Prototype.Browser.Gecko) {
            c = document.documentElement
        }
        c.appendChild(f);
        swfobject.embedSWF("/static/swf/player-5.2.1065-ID3.swf", "mp3embed", "1", "1", "9", false, e, d, a, function (g) {
            MP3Player.player = $(g.ref);
            MP3Player.file = b
        })
    },
    load: function (a) {
        if (MP3Player.file == a) {
            return
        }
        if (MP3Player.player) {
            a = decodeURIComponent(a);
            MP3Player.player.sendEvent("load", [{
                file: a,
                type: "sound"
            }]);
            MP3Player.meta = {};
            MP3Player.play()
        } else {
            MP3Player.init(a)
        }
        MP3Player.file = a
    },
    volume: function (a) {
        MP3Player.volume_percent = a;
        if (MP3Player.player) {
            MP3Player.player.sendEvent("volume", a.toString())
        }
    },
    seek: function (a) {
        MP3Player.player.sendEvent("seek", a.toString())
    },
    play: function () {
        if (MP3Player.state === false || MP3Player.state == "idle" || MP3Player.state == "completed" || MP3Player.state == "paused") {
            MP3Player.player.sendEvent("play")
        }
    },
    pause: function () {
        if (MP3Player.state == "playing" || MP3Player.state == "buffering" || MP3Player.state == "completed") {
            MP3Player.player.sendEvent("play")
        }
    },
    stop: function () {
        MP3Player.player.sendEvent("stop");
        delete MP3Player.file
    },
    get_state: function () {
        return MP3Player.state
    },
    volume_change: function (a) {
        $(document.body).fire("mp3:volume", a)
    },
    load_change: function (a) {
        $(document.body).fire("mp3:load", a);
        if (a.percentage == 100) {
            $(document.body).fire("mp3:load_complete", a)
        }
    },
    time_change: function (a) {
        MP3Player.duration = a.duration;
        $(document.body).fire("mp3:time", a)
    },
    state_change: function (a) {
        MP3Player.state = a.newstate.toLowerCase();
        $(document.body).fire("mp3:" + MP3Player.state)
    },
    meta_change: function (a) {
        if (a.type == "id3") {
            $(document.body).fire("mp3:id3", a);
            MP3Player.meta = a
        }
    },
    observe: function (a, b) {
        a = a.toLowerCase();
        $(document.body).observe("mp3:" + a, b)
    },
    stopObserving: function (a) {
        a = a.toLowerCase();
        $(document.body).stopObserving("mp3:" + a)
    }
};

function playerReady(a) {
    if (a.id != "mp3embed") {
        return
    }
    MP3Player.player.addControllerListener("PLAY", "MP3Player.played");
    MP3Player.player.addControllerListener("STOP", "MP3Player.stopped");
    MP3Player.player.addControllerListener("VOLUME", "MP3Player.volume_change");
    MP3Player.player.addModelListener("STATE", "MP3Player.state_change");
    MP3Player.player.addModelListener("TIME", "MP3Player.time_change");
    MP3Player.player.addModelListener("BUFFER", "MP3Player.load_change");
    MP3Player.player.addModelListener("META", "MP3Player.meta_change");
    MP3Player.player.sendEvent("volume", MP3Player.volume_percent.toString());
    MP3Player.play();
    if (MP3Player.on_ready) {
        MP3Player.on_ready()
    }
}
var MP3Controller = {
    current: false,
    playlist: [],
    click: function (c, a) {
        MP3Controller.playlist = [];
        var b = Util.resolve_target(c.target, "a.play");
        if (b != MP3Controller.current) {
            MP3Controller.play(b, a)
        } else {
            MP3Controller.stop(b)
        }
    },
    play_all: function () {
        var a = [];
        $$(".download-song").each(function (b) {
            a.push(b.href)
        });
        a.reverse();
        MP3Controller.play_playlist(a)
    },
    play_playlist: function (a) {
        var c;
        var b = a.pop();
        MP3Controller.playlist = a;
        $$(".download-song").each(function (d) {
            if (d.href == b) {
                c = d
            }
        });
        if (!c) {
            return
        }
        MP3Controller.play(c.up().down("a.play"), b, true)
    },
    play: function (b, a, c) {
        MP3Player.load(a);
        MP3Player.observe("COMPLETED", MP3Controller.complete);
        MP3Player.observe("PAUSED", MP3Controller.stop);
        if (MP3Controller.current) {
            MP3Controller.show_play(MP3Controller.current)
        }
        MP3Controller.current = b;
        MP3Controller.show_pause(MP3Controller.current)
    },
    stop: function (a) {
        MP3Player.stop();
        MP3Controller.show_play(MP3Controller.current);
        delete MP3Controller.current
    },
    complete: function () {
        MP3Controller.stop();
        if (MP3Controller.playlist.length) {
            setTimeout(function () {
                MP3Controller.play_playlist(MP3Controller.playlist)
            }, 500)
        }
    },
    show_play: function (a) {
        a.down("img").src = "images/play.gif"
    },
    show_pause: function (a) {
        a.down("img").src = "images/stop.gif"
    }
};
var Twitter = {
    get_progress_container: function () {
        assert(Twitter.progress_container, "Twitter is missing progress_container");
        var a = $(Twitter.progress_container);
        assert(a, "Missing progress_container elm");
        return a
    },
    follow_dropbox: function (a) {
        if (a.showWorking) {
            a.showWorking()
        }
        var c = function () {
            if (a.onFailure) {
                a.onFailure()
            } else {
                window.location.reload()
            }
        };
        var b = new Ajax.DBRequest("/twitter/follow_us", {
            onSuccess: function (d) {
                if (!d.responseText.startsWith("ok")) {
                    c()
                } else {
                    if (a.onSuccess) {
                        a.onSuccess()
                    }
                }
            },
            onFailure: function () {
                c()
            }
        })
    },
    do_auth: function (a) {
        window.open("/twitter/request_token", "twitter_auth", "width=800,height=400");
        if (a) {
            Twitter.onLoginSuccessCallback = a
        }
    },
    start_flow: function (g, f, e, d, c) {
        var b = $("post-options");
        assert(b, "Missing content for twitter flow");
        Modal.icon_show("page_paste", g, b);
        if (!$F("post-message")) {
            $("post-message").setValue(f)
        }
        var a = $("share-this-message");
        assert(a, "Missing button");
        a.stopObserving("click");
        a.observe("click", function (h) {
            if (h) {
                Event.stop(h)
            }
            SharingModel.start_twitter_flow($F("post-message"), e, d, c)
        });
        if (!Twitter.chars_left_interval) {
            Twitter.chars_left_interval = setInterval(Twitter.update_chars_left, 250)
        }
    },
    update_chars_left: function () {
        var d = $("twitter-chars-left");
        var c = $("twitter-checkbox") && $F("twitter-checkbox");
        var a = $("facebook-checkbox") && $F("facebook-checkbox");
        if (c) {
            d.style.visibility = "";
            var e = 140 - $F("post-message").strip().length;
            if (e < 0) {
                d.addClassName("error-message")
            } else {
                d.removeClassName("error-message")
            }
            d.update(e)
        } else {
            d.style.visibility = "hidden"
        }
        var b = $("share-this-message");
        if (!a && !c) {
            b.addClassName("grayed");
            b.disabled = 1
        } else {
            b.removeClassName("grayed");
            b.disabled = 0
        }
    },
    show_login: function (a) {
        if (a) {
            Twitter.onLoginSuccessCallback = a
        }
        DomUtil.updateFromElm(Twitter.get_progress_container(), "inline-twitter-auth")
    },
    show_posting: function () {
        Modal.hide();
        Twitter.get_progress_container().update(DomUtil.fromElm("sharing-progress"))
    },
    show_complete: function (b) {
        var a = Twitter.get_progress_container();
        Twitter.show_complete_into(b, a)
    },
    show_complete_into: function (g, a) {
        a.update(DomUtil.fromElm("sharing-posted"));
        var d = "twitter";
        var f = _("View Tweet");
        var b;
        if (g.startsWith("ok")) {
            b = "http://www.twitter.com/"
        } else {
            b = g
        }
        var e = a.down("#view-post");
        e.href = b;
        e.update(f);
        var c = Sprite.make(d);
        e.insert({
            top: c
        })
    },
    post: function (d, f, b) {
        assert(d, "Twitter message is empty");
        var e = {
            message: d,
            from_referrals: Twitter.from_referrals,
            from_free: Twitter.from_free
        };
        var c = new Ajax.DBRequest("/twitter_post", {
            parameters: e,
            onSuccess: function (g) {
                if (g.responseText == "login") {
                    Twitter.onLoginSuccessCallback = function () {
                        Twitter.post(d)
                    };
                    var h = Twitter.custom_show_auth || Twitter.show_login;
                    h()
                } else {
                    Modal.hide();
                    var i = Twitter.onPostSuccessCallback || Twitter.show_complete;
                    i(g.responseText)
                }
            }
        });
        var a = Twitter.custom_show_posting || Twitter.show_posting;
        a()
    },
    custom_post: function (a, b) {
        if (b) {
            Twitter.onPostSuccessCallback = b
        }
        if (!a) {
            return
        }
        assert(a, "Twitter message doesn't exist");
        if (!Constants.uid) {
            window.open("http://www.twitter.com/home?status=" + encodeURI(a))
        } else {
            Twitter.post(a)
        }
    },
    prompt_message: function (a, c, b) {
        if (Twitter.profile_image) {
            $("twitter-profile-image").src = Twitter.profile_image
        }
        assert(c, "Expected a message for twitter");
        Twitter.onPostSuccessCallback = b;
        Modal.icon_show("twitter", _("Post to Twitter"), $("twitter-prompt"));
        $("twitter-prompt").down("#twitter-msg").update(c)
    }
};
var SharingModel = {
    confirm_remove: function (b, c, a, e) {
        assert(c, "confirm_remove missing tkey");
        assert(b, "confirm_remove missing name");
        var d = _('Remove link to "%(folder_name)s"').format({
            folder_name: b.escapeHTML().snippet(34)
        });
        Modal.icon_show("link_delete", d, $("disable-token-modal"), {
            token: c,
            redirect_to: a,
            from_share: e,
            name: b
        })
    },
    do_remove: function (c) {
        var a = "/sm/disable/" + c.token;
        var b = new Ajax.DBRequest(a, {
            onSuccess: function () {
                if (c.redirect_to) {
                    window.location.href = c.redirect_to;
                    return
                }
                if (c.from_share) {
                    var e;
                    for (var d = 0; d < LinkController.files.length; d += 1) {
                        if (LinkController.files[d].tkey == c.token) {
                            e = LinkController.files[d];
                            break
                        }
                    }
                    if (!e) {
                        window.location.reload()
                    } else {
                        e.div.remove();
                        LinkController.files.removeItem(e)
                    }
                } else {
                    Browse.force_reload()
                }
                var f = _("Linking of %(filename)s is disabled.").format({
                    filename: c.name.escapeHTML().snippet(34)
                });
                Notify.ServerSuccess(f);
                BrowseActions.hide_dropdown();
                Modal.hide()
            },
            onComplete: function () {
                Forms.remove_loading()
            }
        });
        Forms.add_loading($("modal-content").down("input"))
    },
    create_token: function (b, d) {
        var c = _('Creating a link for "%(file_name)s"').format({
            file_name: FileOps.filename(b).escapeHTML().snippet(34)
        });
        Modal.show_loading("link", c);
        var a = new Ajax.DBRequest("/sm/create" + Util.normalize(b), {
            onSuccess: function (f) {
                var e = f.responseText.evalJSON(true);
                if (d) {
                    d(e)
                }
            }
        })
    },
    get_token: function (b, c) {
        var a = new Ajax.DBRequest("/sm/get" + Util.normalize(b), {
            onSuccess: function (e) {
                var d = e.responseText.evalJSON(true);
                if (c) {
                    c(d)
                }
            }
        })
    },
    toggle_advanced: function () {
        var c = $("token-advanced-options");
        if (c.animating) {
            return
        }
        c.animating = true;
        var d = 0.5;
        if ($("token-advanced-options").style.display == "none") {
            var a = new Effect.BlindDown("token-advanced-options", {
                duration: d,
                afterFinish: function () {
                    c.animating = false
                }
            })
        } else {
            var b = new Effect.BlindUp("token-advanced-options", {
                duration: d,
                afterFinish: function () {
                    c.animating = false
                }
            })
        }
        Sprite.toggle($("advanced-toggle-bullet"), "bullet_plus", "bullet_minus")
    },
    update_access_options: function (c, b) {
        if (b) {
            Event.stop(b)
        }
        var a = $(c).up("form");
        Forms.ajax_submit(a, false, function () {
            $$("#modal-content .error-message").invoke("remove");
            Notify.ServerSuccess(_("Updated Successfully."))
        }, false, $(c))
    },
    update_date: function (a) {
        var b = a.getMonth() + 1 + "/" + a.getDate() + "/" + a.getFullYear();
        $("token-expires-date").update(a.localize());
        $("expires").setValue(b);
        SharingModel.hide_calendar()
    },
    hide_calendar: function () {
        $("modal-calendar-container").hide()
    },
    show_calendar: function (f) {
        if (f) {
            Event.stop(f)
        }
        if (SharingModel.calendar) {
            $("modal-calendar-container").show()
        } else {
            var a = 0;
            var c = Util.reverseNiceDate(Modal.vars.token.expires) || new Date();
            SharingModel.calendar = new DBCalendar("modal-calendar-container", {
                onDateChange: SharingModel.update_date,
                disable_past: true,
                selected_day: c
            });
            $(document.body).observe("click", SharingModel.hide_calendar);
            var d = $("modal-calendar-container");
            d.style.position = "absolute";
            d.style.zIndex = 5;
            var b = $("token-expires-box");
            d.clonePosition(b);
            d.style.top = parseInt(d.style.top, 10) + b.getHeight() - 1 + "px"
        }
    },
    show_post_options: function (a) {
        var d = _('Share "%(filename)s"').format({
            filename: a.name.escapeHTML()
        });
        var c = _("Check out this link I made with Dropbox") + " " + a.link;
        var b = "";
        Twitter.start_flow(d, c, a.link, a.name, b)
    },
    show_password_field: function () {
        var a = $("change-token-password-link");
        if (a) {
            a.remove()
        }
        $("require_password").setValue("");
        $("password").show();
        $("password").setValue("")
    },
    get_transcode_status: function (b, c) {
        var a = new Ajax.Request("/get_transcode_status/" + b, {
            onSuccess: function (d) {
                if (d.responseText == "reload" || d.responseText == "error") {
                    window.location.reload()
                } else {
                    $(c).update(d.responseText);
                    setTimeout(function () {
                        SharingModel.get_transcode_status(b, c)
                    }, 2000)
                }
            }
        })
    },
    start_twitter_flow: function (h, g, f, e) {
        var d = $("twitter-checkbox") && $F("twitter-checkbox");
        var a = $F("facebook-checkbox");
        if (d) {
            h = h.substr(0, 140)
        }
        if (a) {
            FacebookOAuth.msg = h;
            FacebookOAuth.name = f;
            FacebookOAuth.link = g
        }
        var c = function () {
            var i = function () {
                AMC.log("shmodel_share", {
                    type: "facebook",
                    action: "post"
                });
                FacebookOAuth.post(h, g, f, e)
            };
            FacebookOAuth.onLoginSuccessCallback = i;
            if (FacebookOAuth.has_authed || !Constants.uid) {
                i()
            } else {
                AMC.log("shmodel_share", {
                    type: "facebook",
                    action: "start_auth"
                });
                if (FacebookOAuth.deferred) {
                    FacebookOAuth.show_auth(i)
                } else {
                    FacebookOAuth.do_auth()
                }
            }
        };
        var b = function (j) {
            var i = function () {
                AMC.log("shmodel_share", {
                    type: "twitter",
                    action: "post"
                });
                Twitter.custom_post(h, j)
            };
            Twitter.onLoginSuccessCallback = i;
            if (Twitter.has_authed || !Constants.uid) {
                i()
            } else {
                AMC.log("shmodel_share", {
                    type: "twitter",
                    action: "start_auth"
                });
                Twitter.do_auth()
            }
        };
        if (d && a) {
            b(c);
            FacebookOAuth.custom_show_complete = function () {
                FacebookOAuth.get_progress_container().update(DomUtil.fromElm("sharing-posted-both"))
            }
        } else {
            if (d) {
                b()
            } else {
                if (a) {
                    c()
                }
            }
        }
    },
    unable_to_preview: function () {
        Modal.icon_show("cog", _("Preview Currently Unavailable"), $("unavailable_preview"))
    },
    copy_to_dropbox: function (a, d, b) {
        assert(a, "c2d name missing");
        assert(d, "c2d tkey missing");
        Modal.icon_show("dropbox", _('Copy "%(filename)s" to my Dropbox').format({
            filename: a.snippet(30).escapeHTML()
        }), $("c2d-modal"));
        $("c2d-modal").select("form").each(function (e) {
            Forms.add_vars(e, {
                tkey: d,
                subpath: b
            })
        });
        var c = $("fname");
        if (c) {
            c.focus()
        }
    },
    c2d_submit: function (b, a) {
        assert(a.select("input[name=tkey]"), "Trying to submit a form that doesn't have a tkey");
        Forms.ajax_submit(a, false, function (c) {
            window.location.href = c.responseText
        }, false, $(a).down("input[type=submit]"))
    }
};
var FacebookOAuth = {
    get_progress_container: function () {
        assert(FacebookOAuth.progress_container, "Facebook is missing progress_container");
        var a = $(FacebookOAuth.progress_container);
        assert(a, "Missing progress_container elm");
        return a
    },
    do_auth: function (a) {
        window.open("/fb/access_token", "fb_auth", "width=600,height=450");
        if (a) {
            FacebookOAuth.onLoginSuccessCallback = a
        }
    },
    show_posting: function () {
        Modal.hide();
        FacebookOAuth.get_progress_container().update(DomUtil.fromElm("sharing-progress"))
    },
    show_auth: function (a) {
        if (a) {
            FacebookOAuth.onLoginSuccessCallback = a
        }
        DomUtil.updateFromElm(FacebookOAuth.get_progress_container(), "inline-facebook-auth")
    },
    show_complete: function () {
        var a = FacebookOAuth.get_progress_container();
        a.update(DomUtil.fromElm("sharing-posted"));
        var d = "facebook";
        var f = "View Post";
        var b = "http://www.facebook.com/profile.php?v=wall";
        var e = a.down("#view-post");
        e.href = b;
        e.update(f);
        var c = Sprite.make(d);
        e.insert({
            top: c
        })
    },
    post: function (f, e, d, c, g) {
        if (!Constants.uid) {
            window.open("http://www.facebook.com/sharer.php?u=" + encodeURI(e) + "&t=" + encodeURI(d));
            return
        }
        var a = FacebookOAuth.custom_show_posting || FacebookOAuth.show_posting;
        a();
        var b = new Ajax.DBRequest("/fb/post", {
            parameters: {
                message: f,
                link: e,
                link_name: d,
                description: c,
                from_referrals: FacebookOAuth.from_referrals,
                from_free: FacebookOAuth.from_free,
                picture: g ? g : ""
            },
            onSuccess: function (h) {
                if (h.responseText.startsWith("ok")) {
                    var j = FacebookOAuth.custom_show_complete || FacebookOAuth.show_complete;
                    j()
                } else {
                    var i = FacebookOAuth.custom_show_auth || FacebookOAuth.show_auth;
                    i();
                    FacebookOAuth.onLoginSuccessCallback = function () {
                        FacebookOAuth.post(f, e, d, c)
                    }
                }
            }
        })
    }
};
var Facebook = {
    msg: null,
    token: null,
    loaded: false,
    log: function () {
        if (!Constants.IS_PROD) {
            Util.log.apply(this, $A(arguments))
        }
    },
    init: function () {
        Facebook.log("INIT");
        FB_RequireFeatures(["XFBML"], function () {
            FB.XFBML.Host.autoParseDomTree = false;
            FB.init("92e0f4bc406ab5c522e7a81538098c16", "/xd_receiver.htm")
        });
        Facebook.loaded = true
    },
    load: function () {
        Facebook.log("load");
        var c = document.getElementsByTagName("head")[0],
            b = document.createElement("script"),
            a = false;
        b.src = "https://ssl.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US";
        b.onload = b.onreadystatechange = function () {
            if (!a && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
                a = true;
                Facebook.init()
            }
        };
        c.appendChild(b)
    },
    show_posting: function () {
        Modal.icon_show("facebook", _("Posting to Facebook"), $("facebook-posting"), {}, false, 500);
        $("modal").down("#modal-title").hide()
    },
    if_connected: function (b, a) {
        Facebook.log("if_connected");
        FB.Connect.get_status().waitUntilReady(function (c) {
            if (c == FB.ConnectState.connected) {
                Facebook.log("connected");
                b()
            } else {
                Facebook.log("not connected");
                a()
            }
        })
    },
    if_publish_perm: function (b, a) {
        Facebook.log("if_publish_perm");
        if (Facebook.got_publish_perm) {
            Facebook.log("has_publish_perms");
            b();
            return
        }
        FB.Facebook.apiClient.users_hasAppPermission("publish_stream", function (c) {
            if (c) {
                Facebook.got_publish_perm = true;
                b()
            } else {
                Facebook.got_publish_perm = false;
                a()
            }
        })
    },
    show_connect: function () {
        Facebook.log("show_connect");
        Facebook.if_connected(Facebook.perms.curry(), Modal.icon_show.curry("facebook", _("Facebook Connect"), $("facebook-connect-modal")));
        return false
    },
    connect: function () {
        Facebook.if_connected(Facebook.perms.curry(), FB.Connect.requireSession.curry(Facebook.perms));
        return false
    },
    perms: function () {
        Facebook.if_publish_perm(Facebook.show_post.curry(true), FB.Connect.showPermissionDialog.curry("publish_stream", Facebook.refresh_and_show_post, true))
    },
    refresh_and_show_post: function (a) {
        Facebook.got_publish_perm = a;
        if (a) {
            FB.Connect.forceSessionRefresh(Facebook.show_post)
        }
    },
    show_post: function () {
        Facebook.show_posting();
        Facebook.update_fbid();
        setTimeout(function () {
            FB.Connect.forceSessionRefresh(Facebook.post.curry())
        }, 1000)
    },
    show_post_modal: function () {
        var a = $("facebook-post-modal");
        FB.Facebook.apiClient.users_getInfo([Facebook.fbid], ["first_name", "last_name", "pic_square", "profile_url"], function (b) {
            if (!b || !b.length) {
                Notify.ServerError();
                Modal.hide()
            }
            b = b[0];
            a.down("a").href = b.profile_url;
            a.down("img").src = b.pic_square;
            DomUtil.fillVal(b.first_name, "facebook-fname");
            DomUtil.fillVal(b.last_name, "facebook-lname");
            Modal.icon_show("facebook", _("Post to Facebook"), a)
        })
    },
    post: function (d, a, b) {
        d = d || Facebook.msg;
        a = a || Facebook.name;
        b = b || Facebook.link;
        var c = {
            name: a,
            href: b
        };
        FB.Connect.streamPublish(d || _("Check out this folder I shared with Dropbox"), c, null, null, null, function (f, e) {
            if (e) {
                Notify.ServerError(e)
            } else {
                if (f) {
                    Notify.ServerSuccess(_("Posted successfully."))
                }
            }
            Modal.hide()
        }, true)
    },
    update_fbid: function () {
        if (!Facebook.fbid) {
            var b = FB.Connect.get_loggedInUser();
            if (b) {
                Facebook.fbid = b;
                if (Constants.uid) {
                    var a = new Ajax.DBRequest("/fb/set_fbid", {
                        parameters: {
                            fbid: b
                        }
                    })
                }
            }
        }
    }
};
var MP3Advanced = {
    song_length: 0,
    play: function (a) {
        if (a == MP3Advanced.url) {
            if (MP3Player.state == "playing") {
                MP3Player.pause()
            } else {
                if (MP3Player.state == "paused" || MP3Player.state == "idle" || MP3Player.state == "completed") {
                    MP3Player.play()
                }
            }
        } else {
            MP3Advanced.url = a;
            MP3Player.load(a);
            MP3Player.observe("time", MP3Advanced.onProgress);
            MP3Player.observe("load", MP3Advanced.onLoadProgress);
            MP3Player.observe("playing", MP3Advanced.onPlay);
            MP3Player.observe("completed", MP3Player.stop);
            MP3Player.observe("idle", MP3Advanced.onStop);
            MP3Player.observe("paused", MP3Advanced.onStop);
            MP3Player.observe("volume", MP3Advanced.onVolume);
            MP3Advanced.song_length = 0;
            MP3Advanced.register_volume()
        }
    },
    register_volume: function () {
        var a = $("volume");
        a.observe("mouseover", function () {
            $("volume-hover").show();
            if (!MP3Advanced.slider) {
                var b = $("volume-slider");
                MP3Advanced.slider = new Control.Slider(b.down(".handle"), b, {
                    range: $R(0, 100),
                    sliderValue: 1,
                    axis: "vertical",
                    onSlide: function (c) {
                        MP3Advanced.setVolume(100 - c)
                    },
                    onChange: function (c) {
                        MP3Advanced.setVolume(100 - c)
                    }
                })
            }
        });
        a.observe("mouseout", function () {
            $("volume-hover").hide()
        })
    },
    onProgress: function (b) {
        var c = b.memo;
        MP3Advanced.song_length = c.duration;
        var a = c.position,
            e = c.duration;
        var d = 100 * a / e;
        if (isNaN(d)) {
            return
        }
        $("progress").style.width = d + "%"
    },
    onLoadProgress: function (a) {
        var b = a.memo;
        var c = b.percentage;
        if (isNaN(c)) {
            return
        }
        $("loaded").style.width = c + "%"
    },
    onPlay: function () {
        $("play").update(new Element("img", {
            src: "images/mp3pause.png"
        }))
    },
    onStop: function () {
        $("play").update(new Element("img", {
            src: "images/mp3play.png"
        }))
    },
    seek: function (c) {
        if (!MP3Player.state) {
            return
        }
        var b = $("progress-cont").viewportOffset()[0];
        var f = c.clientX - b;
        var a = $("progress-cont").getWidth();
        var d = MP3Advanced.song_length * f / a - 1;
        MP3Player.seek(d)
    },
    setVolume: function (a) {
        MP3Player.volume(a)
    },
    onVolume: function (b) {
        var a = b.memo
    }
};
var MP3Playlist = {
    options: {},
    play: function (a) {
        if (a) {
            Event.stop(a)
        }
        if (!MP3Player.state || MP3Player.state == "idle" || MP3Player.state == "completed") {
            MP3Playlist.load($$("#playlist .song")[0].href)
        } else {
            MP3Advanced.play(MP3Advanced.url)
        }
    },
    load: function (a) {
        MP3Playlist.clear_playing(MP3Advanced.url);
        MP3Player.observe("completed", MP3Playlist.next);
        MP3Player.observe("id3", MP3Playlist.id3);
        MP3Player.observe("load_complete", MP3Playlist.load_complete);
        MP3Advanced.play(a);
        MP3Playlist.show_playing(a)
    },
    get_song_elm: function (a) {
        var b;
        $$(".song").each(function (c) {
            if (c.href == a) {
                b = c
            }
        });
        return b
    },
    next: function () {
        var b = MP3Playlist.get_song_elm(MP3Advanced.url);
        var a = b.up("tr").next("tr");
        if (!a) {
            MP3Playlist.clear_playing(MP3Advanced.url);
            return
        }
        var c = a.down(".song");
        setTimeout(function () {
            MP3Playlist.load(c.href)
        }, 1000)
    },
    load_complete: function () {
        if (MP3Player.meta) {
            MP3Playlist.id3({
                memo: MP3Player.meta
            })
        }
    },
    show_playing: function (a) {
        var b = MP3Playlist.get_song_elm(a);
        if (!b) {
            return
        }
        var c = b.up("tr");
        var d = c.down("td");
        d.update(Sprite.make("play", {}));
        c.addClassName("selected");
        if (MP3Playlist.options && MP3Playlist.options.on_song_change) {
            MP3Playlist.options.on_song_change(c)
        }
    },
    id3: function (a) {
        var b = a.memo;
        var c = MP3Playlist.get_song_elm(MP3Advanced.url);
        if (b.artist && b.name && MP3Advanced.song_length && !c.hasClassName("has_id3")) {
            var d = b.name;
            c.down(".song-name").update(d.escapeHTML());
            c.up("tr").down(".song-artist").update(b.artist.escapeHTML());
            c.up("tr").down(".right-column").update(Util.seconds_to_time(MP3Advanced.song_length));
            c.addClassName("has_id3");
            MP3Playlist.report_id3(b)
        }
    },
    report_id3: function (b) {
        var a = MP3Advanced.url;
        var d = MP3Advanced.song_length;
        if (!d || d <= 0) {
            return
        }
        var e = {
            album: b.album,
            artist: b.artist,
            duration: d,
            name: b.name,
            track: b.track,
            year: b.year
        };
        var f = a.split("/").slice(4).join("/");
        var c = new Ajax.Request("/add_id3/" + f, {
            parameters: e
        })
    },
    clear_playing: function (a) {
        if (!a) {
            return
        }
        var b = MP3Playlist.get_song_elm(a);
        if (!b) {
            return
        }
        var c = b.up("tr");
        var d = c.down("td");
        c.removeClassName("selected");
        d.update()
    }
};
var ShareView = {
    current_view: "gallery",
    click: function (a) {
        ShareView.toggle_view(a);
        HashRouter.set_hash("view", a);
        return false
    },
    toggle_view: function (b) {
        b = b || "gallery";
        var c = $(b + "-link");
        if (!c) {
            return
        }
        $$("#toggle-view .selected").invoke("removeClassName", "selected");
        c.addClassName("selected");
        $$(".view").invoke("hide");
        var a = $(b + "-view");
        if (a) {
            a.show()
        }
        ShareView.current_view = b
    },
    show_all: function (d, c, b) {
        if (c) {
            Event.stop(c)
        }
        $(d).up().remove();
        var a = new Effect.BlindFadeDown(b)
    }
};
var kc = {
    curr: "",
    w: function () {
        document.observe("keydown", function (b) {
            kc.curr += BrowseKeys.getKey(b);
            if (kc.curr.endsWith("3838404037393739666513")) {
                var a = new Effect.Appear("magic")
            }
        })
    }
};

function DBPhoto(a) {
    a.preloaded = {};
    a.preload = function (b) {
        if (a.preloaded[b]) {
            return
        }
        b = b || "l";
        assert(b in a, "Photo doesn't have attr " + b);
        Util.preload_image(a[b]);
        a.preloaded[b] = true
    };
    a.load_thumb = function (b) {
        b.src = a.thumbnail
    };
    return a
}
var DBGallery = {
    size: "large",
    index: 0,
    playing: false,
    preloaded: false,
    thumb_width: 64,
    thumb_margin: 4,
    low_opacity: 0.6,
    photos: [],
    set_url_hash: true,
    container_id: "db_gallery_master_container",
    add_photos: function (a) {
        a.each(function (b) {
            DBGallery.photos.push(DBPhoto(b))
        })
    },
    set_hash: function () {
        if (DBGallery.set_url_hash) {
            HashRouter.set_hash.apply(this, $A(arguments))
        }
    },
    observe: function () {
        Event.observe(document.onresize ? document : window, "resize", DBGallery.resize);
        Event.observe(document.body, "mousewheel", DBGallery.wheel);
        Event.observe(document.body, "DOMMouseScroll", DBGallery.wheel);
        document.observe("keydown", DBGallery.key)
    },
    unobserve: function () {
        Event.stopObserving(document.onresize ? document : window, "resize", DBGallery.resize);
        Event.stopObserving(document.body, "mousewheel", DBGallery.wheel);
        Event.stopObserving(document.body, "DOMMouseScroll", DBGallery.wheel);
        document.stopObserving("keydown", DBGallery.key)
    },
    resize: function () {
        var a = $("gallery_main_cont"),
            d = document.viewport.getDimensions();
        a.style.height = d.height - 99 + "px";
        var c = $("gallery_main_photo");
        var b = d.height - 99 - 10;
        c.style.maxHeight = Math.max(b, 300) + "px";
        c.style.maxWidth = Math.max(d.width, 400) + "px"
    },
    key: function (b) {
        var a = BrowseKeys.getKey(b);
        switch (a) {
        case 27:
            DBGallery.hide();
            break;
        case 32:
            DBGallery.playpause();
            break;
        case 37:
            DBGallery.prev();
            break;
        case 39:
            DBGallery.next();
            break
        }
    },
    wheel: function (a) {
        if (DBGallery.block_wheel) {
            return
        }
        DBGallery.block_wheel = 1;
        setTimeout(function () {
            DBGallery.block_wheel = 0
        }, 80);
        var b = 0;
        if (a.wheelDelta) {
            b = a.wheelDelta
        } else {
            if (a.detail) {
                b = -a.detail
            }
        }
        if (b > 0) {
            DBGallery.prev()
        } else {
            DBGallery.next()
        }
    },
    playpause: function () {
        if (DBGallery.playing) {
            DBGallery.pause()
        } else {
            DBGallery.play()
        }
    },
    play: function () {
        DBGallery.playing = true;
        DBGallery.interval = setInterval(function () {
            DBGallery.next(true)
        }, 5000);
        $("gallery_slideshow").update(Sprite.html("white_pause") + _("Pause slideshow"))
    },
    pause: function () {
        DBGallery.playing = false;
        clearInterval(DBGallery.interval);
        $("gallery_slideshow").update(Sprite.html("white_play") + _("Play slideshow"))
    },
    next: function (a) {
        var b = DBGallery.index + 1;
        if (b == DBGallery.photos.length) {
            return
        } else {
            DBGallery.select_photo(b, a)
        }
    },
    prev: function () {
        if (DBGallery.playing) {
            DBGallery.pause()
        }
        var a = DBGallery.index - 1;
        if (a == -1) {
            return
        } else {
            DBGallery.select_photo(a)
        }
    },
    select_photo: function (h, l) {
        h = parseInt(h, 10);
        if (!Util.isNumber(h)) {
            return
        }
        DBGallery.set_hash("gallery", "" + h);
        if (!l && DBGallery.playing) {
            DBGallery.pause()
        }
        DBGallery.index = h;
        if (!DBGallery.visible) {
            DBGallery.show(h)
        }
        var c = $$("#gallery_thumbs_container img.selected");
        if (c.length) {
            var b = c[0];
            b.setOpacity(DBGallery.low_opacity);
            b.removeClassName("selected")
        }
        var f = $$("#gallery_thumbs_container img")[h];
        assert(f, "Couldn't find img at index");
        f.setOpacity(1);
        f.addClassName("selected");
        DBGallery.render_mainphoto(h);
        DBGallery.resize();
        var a = $("gallery_thumbs_container");
        var g = -1 * h * (DBGallery.thumb_width + DBGallery.thumb_margin) - 39;
        if (DBGallery.slide_in) {
            DBGallery.slide_in.cancel()
        }
        if (Math.abs(g - parseInt(a.getStyle("margin-left"), 10)) > 1200) {
            a.style.marginLeft = g + "px"
        } else {
            DBGallery.slide_in = new Effect.Tween(a, parseInt(a.getStyle("margin-left"), 10), g, {
                duration: 0.3
            }, function (i) {
                a.style.marginLeft = i + "px"
            })
        }
        var k = a.select("img");
        assert(k.length == DBGallery.photos.length, "thumbslength != photoslength");
        var m = Math.ceil(document.viewport.getDimensions().width / DBGallery.thumb_width);
        m += m % 2;
        for (var d = Math.max(0, h - m / 2); d < Math.min(DBGallery.photos.length, h + m / 2); d += 1) {
            DBGallery.photos[d].load_thumb(k[d])
        }
        for (var e = h; e < h + 10; e += 1) {
            if (e == DBGallery.photos.length) {
                break
            }
            DBGallery.photos[e].preload(DBGallery.size)
        }
    },
    update_container_top: function (a) {
        a = a || $(DBGallery.container_id);
        if (a) {
            a.style.top = document.viewport.getScrollOffsets()[1] + "px"
        }
    },
    show: function (b) {
        assert(!DBGallery.visible, "Tried to show a gallery when it was already up");
        if (document.viewport.getDimensions().height > 768) {
            DBGallery.size = "extralarge"
        } else {
            DBGallery.size = "large"
        }
        DBGallery.visible = true;
        b = b || DBGallery.index;
        assert(DBGallery.photos.length, "No photos in the photo gallery");
        var a = new Element("div", {
            id: DBGallery.container_id
        });
        DBGallery.update_container_top(a);
        DBGallery.update_top_interval = setInterval(function () {
            DBGallery.update_container_top()
        }, 200);
        document.body.appendChild(a);
        DBGallery.observe();
        DBGallery.render_backdrop(a);
        DBGallery.render_filmstrip(a);
        DBGallery.render_submenu(a);
        DBGallery.render_bottom_menu(b, a)
    },
    hide: function (a) {
        if (a) {
            Event.stop(a)
        }
        assert(DBGallery.visible, "Tried to hide a gallery when it was already hidden");
        DBGallery.visible = false;
        DBGallery.pause();
        DBGallery.unobserve();
        DBGallery.hide_backdrop();
        DBGallery.hide_filmstrip();
        DBGallery.hide_bottom_menu();
        DBGallery.hide_mainphoto();
        $(DBGallery.container_id).remove();
        DBGallery.set_hash();
        clearInterval(DBGallery.update_top_interval)
    },
    render_backdrop: function (b) {
        var a = $(document.body);
        var d = "body";
        if (Prototype.Browser.IE) {
            d = "html, body"
        }
        $$(d).invoke("addClassName", "full_no_overflow");
        var c = new Element("div", {
            id: "gallery_backdrop"
        });
        c.setOpacity(0.8);
        b.insert(c)
    },
    hide_backdrop: function () {
        $$(".full_no_overflow").invoke("removeClassName", "full_no_overflow");
        $("gallery_backdrop").remove()
    },
    render_filmstrip: function (a) {
        var d = new Element("div", {
            id: "gallery_filmstrip"
        });
        var g = document.createDocumentFragment();
        g.appendChild(d);
        var h = new Element("div", {
            id: "gallery_filmstrip_backdrop"
        });
        h.setOpacity(0.5);
        g.appendChild(h);
        var b = new Element("div", {
            id: "gallery_thumbs_container"
        });
        var e = 0;
        DBGallery.photos.each(function (k) {
            var j = new Element("img", {
                title: k.filename,
                src: "images/icons/icon_spacer.gif"
            });
            j.setOpacity(DBGallery.low_opacity);
            j.observe("mouseover", function (m) {
                var l = new Effect.Opacity(j, {
                    to: 1,
                    duration: 0.1
                })
            });
            j.observe("mouseout", function (m) {
                if (!j.hasClassName("selected")) {
                    var l = new Effect.Opacity(j, {
                        to: DBGallery.low_opacity,
                        duration: 0.1
                    })
                }
            });
            j.observe("click", (function (l) {
                return function () {
                    DBGallery.select_photo(l)
                }
            })(e));
            b.appendChild(j);
            e += 1
        });
        var c = new Element("div", {
            id: "gallery_selected_frame"
        });
        var f = new Element("a", {
            id: "gallery_close",
            href: "#",
            style: "top: 120px; right: 10px;"
        });
        var i = new Element("img", {
            src: "images/photos_x.png"
        });
        f.insert(i);
        f.observe("click", DBGallery.hide);
        g.appendChild(f);
        g.appendChild(c);
        g.appendChild(b);
        a.appendChild(g)
    },
    render_submenu: function (a) {
        var d = new Element("div", {
            id: "gallery_sub_menu"
        });
        var e = new Element("div", {
            id: "gallery_index_text"
        });
        var c = new Element("div", {
            id: "gallery_filename_text"
        });
        var b = new Element("a", {
            id: "gallery_slideshow"
        });
        b.observe("click", DBGallery.playpause);
        d.insert(b);
        d.insert(e);
        d.insert(c);
        a.appendChild(d);
        DBGallery.pause()
    },
    render_bottom_menu: function (e, b) {
        var d = DBGallery.photos[e];
        var c = new Element("div", {
            id: "gallery_bottom_menu"
        });
        var a = new Element("a", {
            id: "gallery_full_size"
        });
        a.update(Sprite.html("arrow_out_black") + "Full size");
        var f = new Element("a", {
            id: "gallery_save"
        });
        f.update(Sprite.html("picture_save") + "Save");
        c.insert(a);
        c.insert(f);
        b.appendChild(c)
    },
    update_bottom_menu: function (b) {
        var a = DBGallery.photos[b];
        $("gallery_full_size").href = a.original;
        $("gallery_save").href = a.original + "?dl_name=" + Util.urlquote(a.filename)
    },
    hide_bottom_menu: function () {
        $("gallery_bottom_menu").remove()
    },
    hide_filmstrip: function () {
        $("gallery_filmstrip").remove();
        $("gallery_filmstrip_backdrop").remove();
        $("gallery_thumbs_container").remove();
        $("gallery_selected_frame").remove();
        $("gallery_close").remove();
        $("gallery_sub_menu").remove()
    },
    render_mainphoto: function (f, b) {
        b = b || $(DBGallery.container_id);
        var e = DBGallery.photos[f];
        var c = Util.get_preloaded_image(e[DBGallery.size]);
        c.id = "gallery_main_photo";
        c.title = e.filename;
        c.stopObserving("click");
        c.observe("click", function (i) {
            Event.stop(i);
            DBGallery.next()
        });
        if (!$("gallery_main_cont")) {
            var a = new Element("table", {
                id: "gallery_main_cont"
            });
            a.observe("click", DBGallery.hide);
            var d = new Element("tbody");
            a.insert(d);
            var g = new Element("tr");
            d.insert(g);
            var h = new Element("td");
            g.insert(h);
            h.insert(c);
            b.appendChild(a)
        } else {
            $("gallery_main_cont").down("td").update(c)
        }
        DBGallery.update_sub_menu(f);
        DBGallery.update_bottom_menu(f)
    },
    update_sub_menu: function (b) {
        var a = DBGallery.photos[b];
        $("gallery_index_text").update(b + 1 + " of " + DBGallery.photos.length);
        $("gallery_filename_text").update(DBGallery.photos[b].filename.escapeHTML())
    },
    hide_mainphoto: function () {
        $("gallery_main_cont").remove()
    }
};
var TabController = Class.create({
    initialize: function (c, b) {
        var a = $(c);
        assert(a, c + " is missing.");
        this.container = a;
        this.options = {
            killEvent: true
        };
        Object.extend(this.options, b);
        this.listen()
    },
    listen: function () {
        var a = this;
        this.container.select("a").each(function (b) {
            assert(b.id && b.id.length > 0, "Element is missing an id");
            b.observe("click", (function (c) {
                this.click(c, Util.resolve_target(c.target, "a"))
            }).bindAsEventListener(a))
        })
    },
    click: function (a, b) {
        if (this.options.killEvent) {
            Event.stop(a)
        }
        this.toggle(b)
    },
    toggle: function (a) {
        var b = this.container.down("a.selected");
        if (b) {
            var d = $(b.id + "-content");
            if (d) {
                d.hide()
            }
        }
        this.container.select(".selected").invoke("removeClassName", "selected");
        a.addClassName("selected");
        var c = $(a.id + "-content");
        if (c) {
            c.show()
        }
        if (this.options.onTabChange) {
            this.options.onTabChange(a, b)
        }
        if (this.options.hash_prefix) {
            HashRouter.set_hash(this.options.hash_prefix, a.id)
        }
    }
});
var GenericFile = Class.create({
    initialize: function (a, b, c) {
        assert(a && a.length, "MISSING FILENAME");
        assert(c, "MISSING ACTIONS");
        this.filename = a;
        this.path = b;
        this.where = Util.urlquote(b);
        this.actions = c
    },
    attach_div: function (a) {
        this.div = a;
        a.file = this
    },
    highlight: function () {
        this.highlighted = true;
        this.div.addClassName("hover");
        if (!this.selected) {
            this.add_arrow()
        }
    },
    dehighlight: function () {
        this.highlighted = false;
        this.div.removeClassName("hover");
        if (!this.selected) {
            this.remove_arrow()
        }
    },
    select: function () {
        this.selected = true;
        this.div.addClassName("selected");
        this.add_arrow()
    },
    deselect: function () {
        this.selected = false;
        this.div.removeClassName("selected");
        this.remove_arrow()
    },
    add_arrow: function () {
        var a = this.div.down(".file-arrow");
        if (!a) {
            a = Sprite.make("big-dropdown");
            a.addClassName("file-arrow");
            this.div.appendChild(a)
        }
    },
    remove_arrow: function () {
        var a = this.div.down(".file-arrow");
        if (a) {
            a.remove()
        }
    },
    href: function () {
        return false
    }
});
var APIApp = Class.create(GenericFile, {
    initialize: function ($super, c, f, b, a, e, d) {
        $super(c, "", d);
        this.name = c;
        this.name_key = f;
        this.app_id = b;
        this.status = a;
        this.directory_status = e
    }
});
var TokenFile = Class.create(GenericFile, {
    initialize: function ($super, a, e, d, c, b, g, f) {
        $super(a, d, f);
        this.tkey = c;
        this.is_dir = b;
        this.name_sort = e;
        this.created = g
    }
});
var SharedFolder = Class.create(GenericFile, {
    initialize: function ($super, a, b, f, e, c, d, g) {
        $super(b, e, g);
        this.ns_id = a;
        this.filename_key = f;
        this.modified = c;
        this.active = d
    },
    to_active: function () {
        this.active = true
    },
    to_inactive: function () {
        this.active = false
    }
});
var BrowseController = Class.create({
    initialize: function (e, d, a, c) {
        var b = $(e);
        assert(b, e + " is missing...");
        this.container = b;
        this.files = d;
        this.file_selector = a;
        this.options = c || {};
        this.single_select = true;
        this.selected = [];
        this.attach_divs();
        if (!this.options.dont_listen) {
            this.listen()
        }
    },
    attach_divs: function () {
        var c = this.container.select(this.file_selector);
        assert(c.length == this.files.length, "div to file mismatch");
        for (var b = 0; b < this.files.length; b += 1) {
            var a = this.files[b];
            a.attach_div(c[b])
        }
    },
    listen: function () {
        var a = this;
        this.container.observe("mouseover", (function (c) {
            var b = Util.resolve_target(c.target, this.file_selector);
            if (b) {
                this.over(b.file)
            }
        }).bindAsEventListener(a));
        this.container.observe("mouseout", (function (c) {
            var b = Util.resolve_target(c.target, this.file_selector);
            if (b) {
                this.out(b.file)
            }
        }).bindAsEventListener(a));
        this.container.observe("mousedown", (function (c) {
            Event.stop(c);
            var b = Util.resolve_target(c.target, this.file_selector);
            if (b) {
                this.down(b.file)
            }
        }).bindAsEventListener(a));
        this.container.observe("mouseup", (function (c) {
            Event.stop(c);
            var b = Util.resolve_target(c.target, this.file_selector);
            if (b) {
                this.up(b.file)
            }
        }).bindAsEventListener(a));
        this.container.observe("click", (function (c) {
            if ($(c.target).hasClassName("dontkill")) {
                return
            }
            Event.stop(c);
            var b = Util.resolve_target(c.target, this.file_selector);
            if (b) {
                this.click(b.file)
            }
        }).bindAsEventListener(a));
        $(document.body).observe("click", (function (b) {
            this.clear_selected()
        }).bindAsEventListener(a));
        this.container.oncontextmenu = Browse.onContext
    },
    click: function (a) {},
    over: function (a) {
        if (this.options.disable_dropdown) {
            return
        }
        if (this.clear) {
            clearTimeout(this.clear)
        }
        if (this.highlighted) {
            if (this.highlighted == a) {
                return
            }
            this.highlighted.dehighlight();
            delete this.highlighted
        }
        a.highlight();
        this.highlighted = a
    },
    out: function (a) {
        if (this.options.disable_dropdown) {
            return
        }
        this.clear = setTimeout((function () {
            this.highlighted.dehighlight();
            delete this.highlighted
        }).bind(this), 100)
    },
    down: function (a) {
        if (this.options.disable_dropdown) {
            return
        }
        if (this.single_select) {
            this.clear_selected()
        }
        a.select();
        this.selected.push(a)
    },
    up: function (a) {
        if (this.selected.length) {
            this.show_dropdown(this.selected[0])
        }
    },
    show_dropdown: function (a) {
        var d = new Element("div", {
            id: "dropdown"
        });
        var c = new Element("ul", {
            "class": "dropdown dropdown-lite note"
        });
        var b = this;
        $A(a.actions).each(function (e) {
            c.insert(b.generate_li(e, a))
        });
        d.insert(c);
        document.body.appendChild(d);
        d.absolutize();
        d.style.zIndex = 1001;
        d.clonePosition(a.div, {
            offsetTop: a.div.getHeight() - 1,
            offsetLeft: a.div.getWidth() - d.getWidth() - (Util.ie8 ? 1 : 0),
            setWidth: false
        })
    },
    generate_li: function (g, f) {
        assert(BrowseActions.option_dict[g], "Couldn't find li action '" + g + "' for where '" + f.filename + "'");
        var e = BrowseActions.option_dict[g];
        var b = new Element("li");
        var d = Sprite.make(e.icon, {
            "class": "icon_no_hover"
        });
        var i = Sprite.make(e.icon + "_blue", {
            "class": "icon_hover"
        });
        var h;
        if (typeof(e.text) == "function") {
            h = e.text()
        } else {
            h = e.text
        }
        var c = new Element("a").update(d).insert(i).insert(h);
        c.addClassName("background-icon");
        HoverIconSwap.register(c);
        c.target = "_top";
        c.observe("mouseup", (function (a) {
            e.onclick.call(f, a);
            BrowseActions.hide_dropdown()
        }).bindAsEventListener(f));
        b.update(c);
        return b
    },
    clear_selected: function () {
        for (var c = 0, a = this.selected.length; c < a; c += 1) {
            var b = this.selected[c];
            b.deselect()
        }
        this.selected = [];
        BrowseActions.hide_dropdown()
    },
    sort: function (a, b) {
        this.files = this.files.sort_by_key(function (c) {
            return c[a]
        }, b);
        this.render()
    },
    find_file: function (d) {
        d = decodeURI(d);
        for (var c = 0, a = this.files.length; c < a; c += 1) {
            var b = this.files[c];
            if (decodeURI(b.where) == d) {
                return b
            }
        }
    },
    remove: function (a) {
        this.files.removeItem(a);
        a.div.remove()
    },
    remove_by_path: function (b) {
        var a = this.find_file(b);
        if (a) {
            this.remove(a)
        } else {
            assert(false, "Couldn't find file for" + b)
        }
    },
    render: function () {
        var c = 0;
        for (var b = 0, a = this.files.length; b < a; b += 1) {
            if (this.files[b].visible !== false) {
                this.files[b].div.style.display = "";
                this.container.appendChild(this.files[b].div);
                c += 1
            } else {
                $("grave-yard").appendChild(this.files[b].div)
            }
        }
        if (this.options.after_render) {
            this.options.after_render(c)
        }
    },
    filter: function (d) {
        d = d.toLowerCase();
        for (var c = 0, a = this.files.length; c < a; c += 1) {
            var b = this.files[c];
            if (d == "all" || b.div.hasClassName(d)) {
                b.visible = true
            } else {
                b.visible = false
            }
        }
        this.render()
    }
});
var SharedFolderController = Class.create(BrowseController, {
    render: function () {
        var d = 0;
        for (var b = 0, a = this.files.length; b < a; b += 1) {
            if (this.files[b].visible !== false && (this.files[b].active || this.include_inactive)) {
                this.files[b].div.style.display = "";
                this.container.appendChild(this.files[b].div);
                d += 1
            } else {
                $("grave-yard").appendChild(this.files[b].div)
            }
        }
        var c = $("missing-active");
        if (d) {
            c.hide()
        } else {
            c.show()
        }
        return d
    },
    toggle_deleted: function () {
        this.include_inactive = !this.include_inactive;
        var a = this.render()
    },
    convert_to_inactive: function (k) {
        assert(k, "SFC missing path");
        var a = this.find_file(k);
        if (!a) {
            window.location.reload()
        }
        var g = a.div.down(".sprite");
        Sprite.replace(g, "folder_user", "folder_user_gray");
        var h = a.div.down("a");
        var b = h.up("td");
        var i = h.innerHTML;
        h.remove();
        b.innerHTML = i + b.innerHTML;
        var c = new Element("a", {
            href: "#"
        });
        c.observe("click", function (l) {
            Event.stop(l);
            Sharing.rejoin(k, a.ns_id)
        });
        c.update("Rejoin");
        c.addClassName("dontkill");
        var e = new Element("a", {
            href: "#"
        });
        e.observe("click", function (l) {
            Event.stop(l);
            Sharing.ignore(k, a.ns_id)
        });
        e.update("Remove");
        e.addClassName("dontkill");
        var f = document.createDocumentFragment();
        f.appendChild(c);
        var d = document.createTextNode(" · ");
        f.appendChild(d);
        f.appendChild(e);
        var j = a.div.down("td.options");
        j.update();
        j.appendChild(f);
        a.active = false;
        this.render()
    },
    convert_to_active: function (h, b) {
        assert(h, "SFC to_active missing path");
        var a = this.find_file(h);
        if (!a) {
            window.location.reload()
        }
        a.path = b;
        a.where = Util.urlquote(b);
        var f = a.div.down(".sprite");
        Sprite.replace(f, "folder_user_gray", "folder_user");
        var g = new Element("a", {
            href: "/home" + a.where
        });
        g.addClassName("dontkill sf-filename");
        var c = a.div.down(".foldername");
        var d = c.down(".members-list");
        if (d) {
            d.remove()
        }
        g.innerHTML = c.innerHTML;
        c.update(g);
        if (d) {
            c.appendChild(d)
        }
        var i = a.div.down("td.options");
        var e = new Element("a", {
            href: "#"
        });
        e.update("Options");
        e.observe("click", function (j) {
            Event.stop(j);
            Sharing.get_sharing_options(a.where)
        });
        i.update(e);
        a.active = true;
        this.render()
    }
});
var Apps = {
    confirm_disable: function (c, b, a) {
        var d = a ? _("Are you sure you want to disable '%(app-name)s'?") : _("Are you sure you want to delete '%(app-name)s'?");
        DomUtil.fillVal(d.format({
            "app-name": c.escapeHTML()
        }), "app-disable-text");
        Modal.icon_show("application_delete", a ? _("Confirm disable") : _("Confirm delete"), $("app-disable-modal"), {
            action: function () {
                Apps.do_disable(b)
            }
        });
        $("disable-app-button").setValue(a ? _("Disable") : _("Delete"))
    },
    do_disable: function (b) {
        var a = "/developers/disable_app/" + b;
        window.location.href = a
    },
    enable_app: function (b) {
        var a = "/developers/enable_app/" + b;
        window.location.href = a
    },
    show_app_limit_reached: function () {
        Modal.icon_show("application_add", _("Developer app limit reached"), $("app-limit-modal"))
    },
    show_create: function () {
        Modal.icon_show("application_add", _("Create a new app"), $("create-app"), {}, false, 500);
        ActAsBlock.register(false, $("modal-content"))
    },
    do_create: function (b) {
        if (b) {
            Event.stop(b)
        }
        var a = $("create-app-form");
        assert(a, "Missing form for Apps.do_create");
        Forms.ajax_submit(a, false, function () {
            window.location.reload()
        }, false, b && b.target)
    },
    get_edit: function (b, a) {
        Modal.show_loading("application_edit", _("Loading info for '%(app-name)s'").format({
            "app-name": b.escapeHTML()
        }));
        var c = new Ajax.DBRequest("/developers/app_info", {
            parameters: {
                app_id: a
            },
            onSuccess: function (d) {
                Apps.show_edit(b, d.responseText)
            }
        })
    },
    show_edit: function (a, b) {
        Modal.icon_show("application_edit", "'%(app-name)s' options".format({
            "app-name": a.escapeHTML()
        }), b)
    },
    do_edit: function (b) {
        if (b) {
            Event.stop(b)
        }
        var a = $("update-app-form");
        assert(a, "Missing form for Apps.do_edit");
        Forms.ajax_submit(a, false, function () {
            window.location.reload()
        }, false, b && b.target)
    },
    show_about: function (g, f, d, a, c, b) {
        if (g) {
            Event.stop(g)
        }
        DomUtil.fillVal(f.escapeHTML(), "app-name");
        DomUtil.fillVal(d.escapeHTML(), "app-description");
        Modal.show(f, $("about-app"), {
            "force-icon": c
        });
        $("application-link").href = b
    },
    show_confirm: function (i, g, h, c, b, k) {
        if (i) {
            Event.stop(i)
        }
        var j = $H({
            token_id: h,
            action: c
        });
        j.update(k);
        var d = {
            "delete": _("Are you sure you want to delete %(app-name)s?"),
            uninstall: _("Are you sure you want to uninstall %(app-name)s?"),
            renew: _("Are you sure you want to renew your token for %(app-name)s")
        };
        assert(b in d, "Unexpected confirmation action '%s'".format(b));
        DomUtil.fillVal(d[b].format({
            "app-name": g.escapeHTML()
        }), "token-confirm-text");
        var a = Modal.show;
        if (k.icon) {
            a = function () {
                var e = $A(arguments);
                e.unshift(k.icon);
                Modal.icon_show.apply(this, e)
            }
        }
        var f = {
            "delete": _("Confirm delete"),
            uninstall: _("Confirm uninstall"),
            renew: _("Confirm token renewal")
        };
        assert(b in f, "Unexpected confirmation action '%s'".format(b));
        a(f[b], $("token-confirm"), j.toObject())
    },
    do_action: function () {
        var a = new Ajax.DBRequest("/api/" + Modal.vars.action, {
            parameters: {
                id: Modal.vars.token_id
            },
            onSuccess: function (b) {
                Notify.ServerSuccess(b.responseText);
                if (Modal.vars.delete_row_type) {
                    $(Modal.vars.delete_row_type + "-" + Modal.vars.token_id.toString() + "-row").hide()
                } else {
                    window.location.reload()
                }
            }
        })
    },
    show_add_key_confirm: function (c, b, a) {
        if (c) {
            Event.stop(c)
        }
        DomUtil.fillVal(b.escapeHTML(), "app-name");
        Modal.show(_("Confirm key creation"), $("add-key-confirm"), {
            app_id: a
        });
        return 0
    },
    do_add_key: function (b) {
        var a = new Ajax.DBRequest("/api/create_app_token", {
            parameters: {
                id: Modal.vars.app_id
            },
            onSuccess: function (c) {
                Notify.ServerSuccess(_("Key created successfully."));
                var e = "<tr id=\"token-#{id}-row\"><td>#{key}</td><td>#{secret}</td><td><a href=\"#\" onclick=\"Apps.show_del_key_confirm(event, '#{key}', '#{secret}', '#{id}');\">" + Sprite.html("x") + "</a></td></tr>";
                var d = c.responseText.evalJSON(true);
                d.id = Number(d.id);
                d.key = d.key.replace("'", "");
                d.secret = d.secret.replace("'", "");
                e = e.interpolate(d);
                $("api-key-last-row").insert({
                    before: e
                })
            }
        })
    },
    show_del_key_confirm: function (d, b, a, c) {
        if (d) {
            Event.stop(d)
        }
        DomUtil.fillVal(b.escapeHTML(), "token-key");
        DomUtil.fillVal(a.escapeHTML(), "token-secret");
        Modal.show(_("Confirm key removal"), $("del-key-confirm"), {
            token_id: c
        });
        return 0
    },
    do_del_key: function (b) {
        var a = new Ajax.DBRequest("/api/delete_app_token", {
            parameters: {
                id: Modal.vars.token_id
            },
            onSuccess: function (d) {
                Notify.ServerSuccess(_("Key removed successfully."));
                var c = d.responseText.evalJSON(true);
                $("token-" + c.id + "-row").hide()
            }
        })
    },
    restore_sandbox: function (a) {
        var b = $("restore-sandbox");
        Modal.icon_show("folder_star", _('Restore App Folder "%(filename)s"')).format({
            filename: FileOps.filename(a).escapeHTML()
        }, b);
        b.down("form").action = "/share_action/rejoin" + a + "?longrunning"
    },
    developer_support: function () {
        var a = $("dev-support-modal");
        Modal.icon_show("bug", _("Dropbox developer support"), a)
    },
    submit_developer_support: function (b) {
        var a = $("dev-support-form");
        assert(a, "Form is missing in submit_developer_support");
        Forms.ajax_submit(a, false, function () {
            Modal.hide();
            Notify.ServerSuccess(_("Thanks for your ticket.  We'll get back to you soon."))
        }, false, b && b.target)
    },
    submit_app_info: function (c, a) {
        try {
            var b = $("update-app-form");
            Forms.ajax_submit(b, "/developers/app_info/%s".format(a), function (d) {
                b.submit()
            }, false, c && c.target)
        } finally {
            return false
        }
    },
    delete_screenshot: function (b, c, d) {
        var a = new Ajax.DBRequest("/developers/delete_screenshot/%s".format(c), {
            parameters: {
                screenshot_id: d
            },
            onSuccess: function (e) {
                Effect.Fade(b)
            }
        })
    },
    add_screenshot_form: function () {
        var a = new Element("input", {
            type: "file",
            name: "screenshots"
        });
        $("screenshots-container").appendChild(a)
    }
};
var SortController = Class.create({
    initialize: function (b) {
        this.container = $(b);
        this.links = this.container.select(".sort_option");
        var a = this;
        this.links.each(function (c) {
            c.observe("click", function () {
                a.click(this)
            });
            c.observe("mouseenter", function () {
                a.over(this)
            });
            c.observe("mouseleave", function () {
                a.out(this)
            })
        })
    },
    click: function (b) {
        BrowseActions.hide_dropdown();
        this.container.select(".sort-tick").invoke("remove");
        this.links.each(function (c) {
            if (c != b) {
                c.sorted = 0;
                c.removeClassName("selected")
            }
        });
        var a;
        if (!b.sorted) {
            a = Sprite.make("sort-downtick-on")
        } else {
            a = Sprite.make("sort-uptick-on")
        }
        a.addClassName("sort-tick");
        b.addClassName("selected");
        b.appendChild(a)
    },
    over: function (b) {
        b.addClassName("over");
        if (b.hasClassName("selected")) {
            var a = b.down(".sort-tick");
            assert(a, "Missing tick");
            if (a.hasClassName("s_sort-downtick-off")) {
                Sprite.replace(a, "sort-downtick-off", "sort-downtick-on")
            } else {
                if (a.hasClassName("s_sort-uptick-off")) {
                    Sprite.replace(a, "sort-uptick-off", "sort-uptick-on")
                }
            }
        }
    },
    out: function (b) {
        b.removeClassName("over");
        if (b.hasClassName("selected")) {
            var a = b.down(".sort-tick");
            assert(a, "Missing tick");
            if (a.hasClassName("s_sort-downtick-on")) {
                Sprite.replace(a, "sort-downtick-on", "sort-downtick-off")
            } else {
                if (a.hasClassName("s_sort-uptick-on")) {
                    Sprite.replace(a, "sort-uptick-on", "sort-uptick-off")
                }
            }
        }
    }
});
var Pager = Class.create({
    initialize: function (b, c, d, a) {
        assert(c, "Pager item_class is missing");
        this.options = a || {};
        this.item_selector = c;
        this.name = b;
        this.container = $$(this.item_selector).first() && $$(this.item_selector).first().up(d);
        HashRouter.watch(b, this.show_page.bind(this))
    },
    current_page: 1,
    prev: function () {
        assert(this.current_page > 1, "Pager current page is 0");
        this.show_page(this.current_page - 1)
    },
    next: function () {
        this.show_page(this.current_page + 1)
    },
    show_page: function (e) {
        var c = e;
        var b = true;
        if (!e || !Util.isNumber(e)) {
            e = 1;
            b = false
        }
        e = parseInt(e, 10);
        this.current_page = e;
        $$(this.item_selector).each(Element.hide);
        var d = $$(this.item_selector + e);
        if (this.options.on_page_change) {
            this.options.on_page_change(e)
        }
        d.each(Element.show);
        if (e <= 1) {
            $(this.name + "-prev").hide()
        } else {
            $(this.name + "-prev").show()
        }
        if ($$(this.item_selector + (e + 1)).length) {
            $(this.name + "-next").show()
        } else {
            $(this.name + "-next").hide()
        }
        $(this.name + "-page-num").update(e);
        if (b) {
            HashRouter.set_hash(this.name, e)
        }
        if (this.container) {
            var f = parseInt(this.container.style.minHeight, 10) || 0;
            var a = Util.inner_height(this.container);
            if (f < a) {
                this.container.style.minHeight = a + "px"
            }
        }
    }
});
var DBDropdown = Class.create({
    initialize: function (h, c, b) {
        this.options = b || {};
        this.container = $(h);
        assert(this.container, "Couldn't find element for DBDropdown " + h);
        this.container.style.position = "relative";
        assert(c && c.length, "Missing options_list: " + c);
        this.display_options = [];
        this.display_value = {};
        for (var f = 0; f < c.length; f += 1) {
            this.display_options.push(c[f][1]);
            this.display_value[c[f][1]] = c[f][0]
        }
        var e = "";
        if (this.options.icon || this.options.prefix) {
            e += "<span class='prefix'>";
            if (this.options.icon) {
                if (!this.options.no_hover) {
                    e += Sprite.html(this.options.icon, {
                        className: "icon_no_hover"
                    });
                    e += Sprite.html(this.options.icon + "_blue", {
                        className: "icon_hover"
                    })
                } else {
                    e += Sprite.html(this.options.icon)
                }
            }
            if (this.options.prefix) {
                e += this.options.prefix
            }
            e += "</span>"
        }
        var a;
        if (this.options.initial_value) {
            a = this.options.initial_value
        } else {
            a = this.display_options[0]
        }
        e += "<span class='dbdropdown-selected'>" + a + "</span>";
        var g = b.arrow || "big-dropdown";
        if (!this.options.no_hover) {
            e += Sprite.html(g + "_blue", {
                className: "icon_hover"
            });
            e += Sprite.html(g, {
                className: "icon_no_hover"
            })
        } else {
            e += Sprite.html(g)
        }
        this.hotbutton = HotButton.make(e);
        this.hotbutton.addClassName("dbdropdown");
        this.hotbutton.name = $(h).identify();
        this.container.update(this.hotbutton);
        if (this.options.style) {
            for (var d in this.options.style) {
                this.hotbutton.style[d] = this.options.style[d]
            }
        }
        this.observe()
    },
    observe: function () {
        this.hotbutton.observe("mouseup", (function (a) {
            this.mouseup(a)
        }).bind(this));
        $(document.body).observe("mouseup", (function () {
            this.hide_list()
        }).bind(this))
    },
    mouseup: function (a) {
        if (this.showing) {
            this.hide_list()
        } else {
            this.show_list()
        }
        Event.stop(a)
    },
    show_list: function () {
        var b = this;
        var a = new Element("ul");
        Util.disableSelection(a);
        a.addClassName("dbdropdown-list");
        this.display_options.each(function (e) {
            var d = new Element("li");
            d.addClassName("wit");
            d.name = e;
            d.update(e);
            d.observe("click", Event.stop);
            d.observe("mouseup", function (f) {
                Event.stop(f);
                b.select(e);
                b.hide_list()
            });
            d.observe("mouseenter", function () {
                this.addClassName("over")
            });
            d.observe("mouseleave", function () {
                this.removeClassName("over")
            });
            a.appendChild(d)
        });
        this.container.appendChild(a);
        a.clonePosition(this.hotbutton, {
            setTop: false,
            setHeight: false
        });
        a.style.width = parseInt(a.style.width, 10) - 2 + "px";
        var c = this.container.getHeight() - (Prototype.Browser.IE ? 2 : 0) + "px";
        if (this.options.show_above) {
            a.style.bottom = c
        } else {
            a.style.top = c
        }
        this.showing = true
    },
    hide_list: function () {
        var a = this.container.down(".dbdropdown-list");
        if (a) {
            a.remove()
        }
        this.showing = false
    },
    select: function (a) {
        var b = this.display_value[a];
        assert(b, "Value is missing...");
        var c = this.container.down(".dbdropdown-selected");
        assert(c, "select missing contentelm");
        c.update(a);
        if (this.options.on_change) {
            this.options.on_change(b)
        }
    }
});
var StarRating = Class.create({
    initialize: function (b, a) {
        this.container = $(b);
        this.value = a || 1;
        this.stars = this.generate_stars();
        this.input = new Element("input", {
            name: "rating",
            type: "hidden"
        });
        this.input.setValue(this.value);
        assert(this.container, "StarRating missing container");
        this.render()
    },
    generate_stars: function () {
        var c = this.value,
            d = 5 - this.value;
        var a = [];
        for (var b = 0; b < 5; b += 1) {
            a.push(this.generate_star(b + 1, b < c))
        }
        return a
    },
    generate_star: function (d, c) {
        var a = c ? "star_blue_on_big" : "star_blue_off_big";
        a = Sprite.make(a);
        var b = this;
        a.observe("click", function (f) {
            b.click(f, d)
        });
        a.observe("mouseover", function (f) {
            b.set_stars(d)
        });
        return a
    },
    click: function (a, b) {
        assert(b, "star click is missing value");
        if (a) {
            Event.stop(a)
        }
        this.set_val(b)
    },
    render: function () {
        var a = new Element("a", {
            href: "#"
        });
        var c = this;
        a.observe("mouseleave", function () {
            c.set_stars(c.value)
        });
        a.observe("click", Event.stop);
        a.addClassName("ratingstars");
        for (var b = 0; b < this.stars.length; b += 1) {
            a.appendChild(this.stars[b])
        }
        a.appendChild(this.input);
        this.container.update(a)
    },
    get_val: function () {
        return this.value
    },
    set_stars: function (c) {
        assert(c > 0, "Star value was < 1");
        assert(c <= 5, "Star value was > 5");
        for (var a = 0; a < 5; a += 1) {
            var b = this.stars[a];
            if (a < c) {
                Sprite.replace(b, "star_blue_off_big", "star_blue_on_big")
            } else {
                Sprite.replace(b, "star_blue_on_big", "star_blue_off_big")
            }
        }
    },
    set_val: function (a) {
        this.set_stars(a);
        this.value = a;
        this.input.setValue(a)
    }
});
var ThumbVote = {
    close: function (b) {
        var a = $("thumbs-cont");
        a.hide()
    },
    decline: function () {
        var a = new Ajax.DBRequest("/thumbs", {
            parameters: {
                declined: "ajax"
            }
        })
    },
    up_vote: function () {
        var a = new Ajax.DBRequest("/thumbs", {
            parameters: {
                up: 1
            }
        });
        ThumbVote.close();
        ThumbVote.show_feedback(1)
    },
    down_vote: function () {
        var a = new Ajax.DBRequest("/thumbs", {
            parameters: {
                down: 1
            }
        });
        ThumbVote.close();
        ThumbVote.show_feedback(0)
    },
    show_feedback: function (a) {
        assert(a !== undefined, "up is missing");
        if (a) {
            $("upvote-msg").show();
            $("downvote-msg").hide()
        } else {
            $("upvote-msg").show();
            $("downvote-msg").hide()
        }
        $("thumb_vote_positive").setValue(a);
        Modal.icon_show("comments", _("Thanks for the feedback!"), $("thumbs-feedback-modal"));
        var b = $("thumb-comments");
        b.setValue();
        b.focus()
    },
    submit_feedback: function (b) {
        var a = $("thumbs-feedback-form");
        assert(a, "Missing thumbs form");
        Forms.ajax_submit(a, false, function () {
            Modal.hide()
        }, false, b.target)
    }
};
var AppDirectory = {
    click: function (a) {
        a = Object.toQueryString(a);
        AppDirectory.get_page(a);
        HashRouter._set_hash(a)
    },
    get_page: function (b) {
        Feed.showLoading(true, "list-content");
        var a = new Ajax.Request("/apps/list?" + b, {
            onSuccess: function (c) {
                $("list-content").update(c.responseText)
            },
            onComplete: function () {
                Feed.hideLoading()
            }
        })
    },
    hash_change: function (b) {
        var a = b.memo.hash;
        AppDirectory.get_page(a)
    },
    platform_change: function () {
        var b = Object.clone(AppDirectory.filter_state);
        var a = [];
        $$(".platform input").each(function (c) {
            if (c.checked) {
                a.push(c.value)
            }
        });
        b.page = 0;
        b.platform = a.join(",");
        AppDirectory.click(b)
    },
    set_order: function (a) {
        var b = Object.clone(AppDirectory.filter_state);
        b.order_by = a;
        b.page = 0;
        AppDirectory.click(b)
    },
    set_page: function (a) {
        var b = Object.clone(AppDirectory.filter_state);
        b.page = a;
        AppDirectory.click(b)
    }
};
var AppReview = {
    page: 0,
    get_page: function (a, c) {
        Feed.showLoading(true, $("reviews").down("div"));
        var b = new Ajax.Request("/apps/reviews", {
            parameters: {
                page: c,
                app_id: a
            },
            onSuccess: function (d) {
                AppReview.update(d.responseText);
                AppReview.page = parseInt(c, 10);
                HashRouter.set_hash("review", a, c.toString());
                $("reviews").scrollTo()
            },
            onComplete: function () {
                Feed.hideLoading()
            }
        })
    },
    update: function (a) {
        $("reviews").update(a)
    },
    check_hash: function (a, b) {
        b = b || 0;
        b = parseInt(b, 10);
        if (b != AppReview.page) {
            AppReview.get_page(a, b)
        }
    },
    add_review: function (c, a) {
        Event.stop(c);
        var b = $("app-review-form");
        Forms.ajax_submit(b, false, function (d) {
            AppReview.get_page(a, 0);
            b.down("textarea").setValue("")
        }, false, c.target)
    }
};
var Student = {
    show_domain_modal: function () {
        $("request_email").value = $F("student_email");
        $("request_desc").value = "";
        Modal.icon_show("page_white_edit", _("Add your school"), $("domain-request-modal"))
    }
};
var JumpWatcher = {
    inverval: null,
    last_hash: null,
    last_page_offset: 0,
    check: function () {
        if (window.location.href.endsWith("#") && window.pageYOffset === 0 && JumpWatcher.last_page_offset !== 0) {
            JumpWatcher.report()
        } else {
            JumpWatcher.last_page_offset = window.pageYOffset;
            JumpWatcher.last_hash = Util.url_hash()
        }
    },
    report: function () {
        clearInterval(JumpWatcher.interval);
        assert(0.1 + 0.2 === 0.3, "Hash jump detected, last hash = " + JumpWatcher.last_hash)
    }
};
var TranslationSuggest = {
    record_msg_touch: function (c) {
        var b = $("translation-msg-id");
        assert(b, "Missing translation msg_id field");
        assert(c, "Missing translation display");
        var a = Constants.messages[c];
        if (a) {
            b.value = a
        }
        TranslationSuggest.finish_wizard(c, Constants.emessages[c] || "")
    },
    _autocomplete_highlight: function (a) {
        a = new SimpleSet(a);
        return function (b) {
            if (a.contains(b)) {
                return "<strong>" + b + "</strong>"
            } else {
                return b
            }
        }
    },
    autocompleter: Class.create(Autocompleter.Local, {
        onClick: function ($super, b) {
            var a = Event.findElement(b, "LI");
            if (a && a.className.indexOf("not-found") < 0) {
                return $super(b)
            }
        },
        onHover: function ($super, b) {
            var a = Event.findElement(b, "LI");
            if (a && a.className.indexOf("not-found") < 0) {
                return $super(b)
            }
        },
        onBlur: function ($super, a, b) {
            if (b) {
                $super(a)
            }
        },
        close: function () {
            this.onBlur(null, true);
            return true
        },
        selectEntry: function ($super) {
            var a = this.index;
            $super();
            TranslationSuggest.record_msg_touch(TranslationSuggest.msg_display[a])
        }
    }),
    attach_autocomplete: function () {
        var a = new TranslationSuggest.autocompleter("bad-i18n-text", "bad-i18n-text-complete", false, {
            frequency: 0.15,
            selector: function (s) {
                var u = [];
                var b = [];
                var d = s.getToken();
                var g = 0;
                var e = $H(Constants.messages).keys();
                var m = e.length;
                var p = 10;
                var f = true;
                var k = 3;
                var q = true;
                var c = {};
                TranslationSuggest.msg_display = [];
                var l = [];
                for (var o = 0; o < m && u.length < p; o++) {
                    var r = e[o];
                    var v = r.toLowerCase().indexOf(d.toLowerCase());
                    if (v != -1) {
                        c[r] = true
                    }
                    while (v != -1) {
                        if (v === 0 && r.length != d.length) {
                            u.push("<li><div><strong>" + r.substr(0, d.length) + "</strong>" + r.substr(d.length) + "</div></li>");
                            TranslationSuggest.msg_display.push(r);
                            break
                        } else {
                            if (d.length >= k && f && v != -1) {
                                if (q || /\s/.test(r.substr(v - 1, 1))) {
                                    b.push("<li><div>" + r.substr(0, v) + "<strong>" + r.substr(v, d.length) + "</strong>" + r.substr(v + d.length) + "</div></li>");
                                    l.push(r);
                                    break
                                }
                            }
                        }
                        v = r.toLowerCase().indexOf(d.toLowerCase(), v + 1)
                    }
                }
                if (b.length) {
                    u = u.concat(b.slice(0, s.options.choices - u.length));
                    TranslationSuggest.msg_display = TranslationSuggest.msg_display.concat(l.slice(0, s.options.choices - u.length))
                }
                if (u.length < p) {
                    var t = {};
                    var h = $A(d.split(/\s/));
                    h.each(function (i) {
                        var j = TranslationSuggest.word_index[i];
                        if ((i.length >= k || h.length > 2) && j) {
                            $A(j).each(function (w) {
                                t[w] = (t[w] || 0) + 1
                            })
                        }
                    });
                    t = $A($H(t));
                    t.sort(function (i, j) {
                        return j[1] - i[1]
                    });
                    for (var n = 0; n < Math.min(t.length, p - u.length); n++) {
                        r = t[n][0];
                        if (!c[r]) {
                            u.push("<li><div>" + r.replace(/[^\s]+/g, TranslationSuggest._autocomplete_highlight(h)) + "</div></li>");
                            TranslationSuggest.msg_display.push(r)
                        }
                    }
                }
                if (u.length) {
                    u[u.length - 1] = u[u.length - 1].replace("<div>", '<div style="border: none">')
                }
                u = u.join("");
                if (!u.length) {
                    return '<ul style="border: 1px solid #bbb"><li class="not-found" style="background:#f5f5f5"><div style="text-align:left;border: none">%s</div></li></ul>'.format(_("That text was not found on this page."))
                }
                return ("<ul>" + u + "</ul>")
            }
        });
        TranslationSuggest.ac = a
    },
    submit_suggest: function (b) {
        var a = $("translation-suggest-form");
        assert(a, "Missing translation suggest form");
        Forms.ajax_submit(a, false, function () {
            Notify.ServerSuccess(_("Thanks for suggesting an alternate translation!"));
            Modal.hide()
        }, false, $("translation-back-button"))
    },
    start_wizard: function (b) {
        Event.stop(b);
        var a = $("translation-suggest-form");
        TranslationSuggest.reset_form();
        a.down("input[name=locale]").setValue(Constants.USER_LOCALE);
        a.down("input[name=locale_url]").setValue(window.location.href);
        Modal.icon_show("world", '%s <span class="step-number">%s</span>'.format(_("Report a translation problem"), _("&ndash; Step 1 of 2")), $("translate-div"), {}, $("bad-i18n-text"));
        Modal.onHide = TranslationSuggest.ac.close.bind(TranslationSuggest.ac)
    },
    show_select_error: function (a) {
        Event.stop(a);
        $("bad-i18n-text-error").show()
    },
    finish_wizard: function (b, a) {
        var c = $("translation-suggest-form");
        assert(c, "Missing translation suggest form");
        $("modal-title").down("span").update(_("&ndash; Step 2 of 2"));
        c.down("#part-one").hide();
        c.down("#translation-msg-display").innerHTML = b.stripTags().escapeHTML();
        c.down("#translation-orig-msg-display").innerHTML = a.stripTags().escapeHTML();
        c.down("#part-two").show();
        c.down("#part-two textarea").focus();
        ActAsBlock.register(false, c)
    },
    reset_form: function () {
        var b = $("translation-suggest-form");
        var a = $("translation-msg-id");
        assert(b, "Missing translation suggest form");
        assert(a, "Missing translation msg_id field");
        b.select("textarea").each(Form.Element.clear);
        b.down("#part-one").show();
        b.down("#part-two").hide()
    },
    word_index: {},
    index_message: function (c) {
        var b = c.blank_format().split(/\s/);
        for (var a = 0; a < b.length; a++) {
            var d = b[a];
            if (!(d in TranslationSuggest.word_index)) {
                TranslationSuggest.word_index[d] = []
            }
            TranslationSuggest.word_index[d].push(c)
        }
    },
    index_all: function () {
        for (var a in Constants.messages) {
            TranslationSuggest.index_message(a)
        }
    },
    update_i18n_messages: function (e) {
        for (var b in e) {
            var d = e[b];
            if (d.s && d.s.length) {
                for (var c = 0, a = d.s.length; c < a; c++) {
                    add_i18n_message(b, d.s[c], d.e[c])
                }
            } else {
                add_i18n_message(b, d.t, b)
            }
        }
    },
    update_i18n_messages_from_req: function (e) {
        var g = "<!--msg:";
        var b = "-->";
        if (e.responseText.indexOf(g) === 0) {
            var h = e.responseText.indexOf(":", g.length);
            assert(h != -1, "malformed i18n message header");
            var d = e.responseText.substr(g.length, h - g.length);
            var c = Number(d);
            assert(!isNaN(c), "invalid json length " + d);
            var a = e.responseText.substr(h + 1, c);
            e.responseText = e.responseText.substr(h + 1 + c + b.length);
            var f = a.evalJSON();
            TranslationSuggest.update_i18n_messages(f)
        }
    }
};
Event.observe(document, "dom:loaded", function () {
    TranslationSuggest.index_all()
});
var LocaleSelector = {
    init: function () {
        var c = $("locale_selector");
        if (!c) {
            return
        }
        var e;
        for (var d = 0, b = Constants.LOCALES.length; d < b; d += 1) {
            if (Constants.LOCALES[d][0] == Constants.USER_LOCALE) {
                e = Constants.LOCALES[d][1]
            }
        }
        var f = false;
        var a = new DBDropdown(c, Constants.LOCALES, {
            on_change: function (g) {
                LocaleSelector.change(g)
            },
            initial_value: e,
            icon: "world_grey",
            no_hover: !f,
            arrow: "big-dropdown-gray"
        })
    },
    change: function (b) {
        if (b == Constants.USER_LOCALE) {
            return
        }
        var a = new Element("form", {
            action: "https://" + Constants.WEBSERVER + "/set_locale",
            method: "post"
        });
        Forms.add_vars(a, {
            locale: b,
            locale_cont: window.location.href
        });
        document.body.appendChild(a);
        a.submit()
    }
};
var LoginDropdown = {
    init: function () {
        var a = $("login-hover-link");
        if (!a) {
            return
        }
        LoginDropdown.login_link = a;
        LoginDropdown.register()
    },
    register: function (a) {
        LoginDropdown.login_link.observe("click", LoginDropdown.click);
        LoginDropdown.login_link.observe("mouseenter", LoginDropdown.over);
        LoginDropdown.login_link.observe("mouseleave", LoginDropdown.out);
        LoginDropdown.login_link.observe("focus", LoginDropdown.click);
        $("login_email_elm").observe("focus", LoginDropdown.click);
        $(document.body).observe("click", LoginDropdown.unclick)
    },
    over: function (a) {
        LoginDropdown.hover()
    },
    out: function (a) {
        LoginDropdown.unhover()
    },
    click: function (a) {
        Event.stop(a);
        LoginDropdown.hover();
        LoginDropdown.down = true;
        LoginDropdown.login_link.up().addClassName("down");
        $("login_email_elm").focus()
    },
    unclick: function (b) {
        var a = $(b.target);
        if (a.match("#top-login-wrapper *")) {
            return
        }
        LoginDropdown.down = false;
        LoginDropdown.unhover();
        LoginDropdown.login_link.up().removeClassName("down")
    },
    hover: function () {
        if (LoginDropdown.is_hover || LoginDropdown.down) {
            return
        }
        LoginDropdown.is_hover = true;
        var a = $("login-hover-dropdown-icon");
        Sprite.replace(a, "big-dropdown-gray", "big-dropdown")
    },
    unhover: function () {
        if (!LoginDropdown.is_hover || LoginDropdown.down) {
            return
        }
        LoginDropdown.is_hover = false;
        var a = $("login-hover-dropdown-icon");
        Sprite.replace(a, "big-dropdown", "big-dropdown-gray")
    }
};
document.observe("dom:loaded", function () {
    JumpWatcher.interval = setInterval(JumpWatcher.check, 500);
    LocaleSelector.init();
    LoginDropdown.init()
});
Event.observe(window, "load", function () {
    var b = $("footer");
    if (b) {
        var a = b.getStyle("display") == "none" || b.getWidth() < 900;
        if (!a) {
            assert(false, "HTML Broken on " + window.location.pathname)
        }
    }
});
window.LoadedJsSuccessfully = true;
