Application.boxURL = "/box/";
Application.modal = new SimpleModalMessage({
    closeLink: false,
    width: 450,
    padding: 0,
    margin: 0,
    formatMessage: function () {
        return '<div class="lightbox-v2"><div class="lightbox-v2_inner"><a href="#" onclick="DefaultDialogs.close(); return;"><img src="' + CFG.imgBaseURL + '/shim.gif" alt="Close" class="lightbox-close" /></a><div style="margin-bottom:10px;">' + this.messages.join("<br />") + '</div><div style="text-align:center;"><div class="btn-standard btn-on-white"><div class="inner-container"><a href="#" id="facebookInInterstitialButton" onclick="DefaultDialogs.close(); return;">OK</a></div></div></div></div></div>'
    }
});
Application.ajaxAuthenticationRequired = function (a) {
    (new DefaultDialog({
        padding: 0,
        margin: 75,
        ajax: {
            url: CFG.baseURL + "/user/?_action=authenticationModal"
        },
        close: {
            link: false,
            overlay: false,
            esc: true
        },
        afterOpen: function () {
            DefaultDialogs.elm("container").stopObserving();
            DefaultDialogs.elm("container").observe("application:loginStatusChanged", function (b) {
                DefaultDialogs.close();
                if (a && typeof(a) == "function") {
                    a();
                    return
                }
                window.location.reload(true)
            });
            if (DefaultDialogs.instance) {
                DefaultDialogs.instance.setDimensions()
            }
        },
        afterClose: function () {
            DefaultDialogs.elm("container").stopObserving()
        }
    })).open()
};
var tinyMCEDefaultInit = {
    mode: "none",
    theme: "imedia",
    remove_linebreaks: false,
    relative_urls: false,
    entity_encoding: "raw",
    extended_valid_elements: "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],style",
    plugins: "table,advimage,advlink,preview,contextmenu,fullscreen,noneditable,paste",
    content_css: CFG.cssBaseURL + "/style_tinymce.css",
    strict_loading_mode: true,
    theme_imedia_buttons1_add: "|,table,pasteword,code",
    theme_imedia_toolbar_location: "top",
    theme_imedia_toolbar_align: "left",
    theme_imedia_path_location: "bottom",
    theme_imedia_resize_horizontal: true,
    theme_imedia_resizing: true,
    convert_urls: false
};

function header_dropdown_init(c, f) {
    var g = null;
    var e = $(c);

    function d() {
        var j = $(f).getDimensions();
        var k = $(f).positionedOffset();
        var i = k.top + j.height;
        var h = k.top + j.height;
        e.setStyle({
            top: (k.top + j.height) + "px",
            left: k.left + "px",
            display: "block"
        })
    }
    function a() {
        e.hide()
    }
    var b = (function (h) {
        return function () {
            h = clearTimeout(h)
        }
    })(g);
    $(f).observe("mouseover", function (h) {
        var j = h.fromElement || h.relatedTarget;
        while (j && j != e) {
            try {
                j = j.parentNode
            } catch (i) {
                j = element
            }
        }
        if (j == e) {
            return false
        }
        b();
        return true
    });
    $(f).observe("click", function (h) {
        h.stop();
        b();
        d()
    });
    $(f).hoverIntent(function (h) {
        b();
        d()
    }, function (h) {
        b();
        g = a.delay(0.1)
    }, {
        timeout: 100
    });
    e.observe("mouseover", function (h) {
        var j = h.fromElement || h.relatedTarget;
        while (j && j != e) {
            try {
                j = j.parentNode
            } catch (i) {
                j = e
            }
        }
        if (j == e) {
            return false
        }
        $(f).hoverTimer = clearTimeout($(f).hoverTimer);
        $(f).isHovering = false;
        clearTimeout(g);
        return true
    });
    e.observe("mouseout", function (h) {
        var j = h.toElement || h.relatedTarget;
        while (j && j != e) {
            try {
                j = j.parentNode
            } catch (i) {
                j = e
            }
        }
        if (j == e) {
            return false
        }
        b();
        g = a.delay(0.15);
        return true
    })
}
function header_search_init(h, f, a, g, c, e) {
    $(h).observe("submit", function (i) {
        if ($F(f) == "" || $F(f) == a) {
            i.stop();
            return false
        }
    });
    var d = $(f);
    if (e) {
        d.value = e
    } else {
        d.addClassName("intput_hint");
        d.value = a;
        d.observe("focus", function (i) {
            if (d.hasClassName("intput_hint")) {
                d.removeClassName("intput_hint");
                d.value = ""
            }
            d.select()
        })
    }
    var b = new Autocompleter.Ajax(d, c, g, {
        paramName: "q",
        minChars: 1,
        select: "select_title",
        buildList: function () {
            var i = [];
            this.results.each(function (j) {
                i.push('<li id="autocomplete_' + j.parent_type + "_" + j.parent_id + '"><div class="info"><img src="' + j.image_url + '"/><span class="select_title">' + j.title_1 + "</span>" + (parseInt(j.year, 10) > 0 ? ' <span class="year">(' + j.year + ")</span>" : "") + (j.title_2 ? "<br/><em>" + j.title_2 + "</em>" : "") + "</div></li>")
            });
            this.updateChoices("<ul>" + i.join("") + "</ul>")
        },
        afterUpdateElement: function (j, i) {
            var k = i.id.split("_");
            b.results.each(function (l) {
                if (l.parent_type == k[1] && l.parent_id == k[2]) {
                    b.hide();
                    window.location = l.url;
                    if (b.observer) {
                        clearTimeout(b.observer)
                    }
                    b.observer = null;
                    b.hasFocus = false;
                    b.active = false;
                    return false
                }
            })
        },
        onShow: function (i, j) {
            if (!j.style.position || j.style.position == "absolute") {
                j.style.position = "absolute"
            }
            j.show()
        }
    })
};
