/**
 * Contains core methods, allowed portlets collaboration (in the one page bounds).
 * @author Maxim Larichev
 */

/**
 *  Locale constants
 */
Language = {
    EN : "EN",
    RU : "RU",
    DEFAULT : "EN"
};



DocumentContext = {
    location : document.location,
    language : Language.DEFAULT,
    theme : null,

    /**
     * Allows dynamically load any scripts, if they not loaded already.
     * @param type - contains language type. default is "text/javascript";
     */
    loadScript : function(url, type) {
        type = type || "text/javascript";
        if (self.document._scripts[url])
            return;
        self.document._scripts[url] = true;
        document.write("<script type=\"" + type + "\" src=\"" + url +"\"></script>");
    },

    /**
     * Translates relative paths into absolute.
     */
    getResourceUrl : function(url) {
        if (!url)
            return null;

        var protocol = url.substr(0, url.indexOf(":"));
        if (protocol == "theme") {
            url = (url.charAt(6)=="/") ? url.substr(6) : "/" + url.substr(6);
            return this.theme + url;
        } else
        if (protocol == "http" || protocol == "https" || protocol == "ftp") {
            return url;
        } else {
            if (url.charAt(0)!="/")
                url = "/" + url;
            return this.location + url;
        }
    }
};
self.document._scripts = [];



var agent = navigator.userAgent.toLowerCase();
Browser = {
    gecko : agent.indexOf("gecko")>=0 && agent.indexOf("khtml")<0,
    ie : agent.indexOf("msie")>=0 && agent.indexOf("opera")<0,
    ie5 : agent.indexOf("msie 5")>=0 && agent.indexOf("opera")<0,
    ie55 : agent.indexOf("msie 5.5")>=0 && agent.indexOf("opera")<0,
    ie6 : agent.indexOf("msie 6")>=0 && agent.indexOf("opera")<0,
    opera : agent.indexOf("opera")>=0,
    platform : navigator.platform.toLowerCase()
};
delete agent;
