/**
 * Array.prototype.contains
 *
 * Returns whether an array contains a given element or not.
 *
 * @author  Steffen Eckardt
 * @param   mixed  mObj     Usually a string representing the array element to search for.
 * @param   mixed  mSubKey  If the searched array element is to be found in an array element itself.
 * @since   2006-11-08
 * @version 1.0
 * @return  boolean
 */
if (typeof Array.prototype.contains === 'undefined') {
    Array.prototype.contains = function(mObj, mSubKey) {
        for (var i in this) {
            if (typeof this[i] != 'function' && this[i] != null && ((mSubKey == null && this[i] == mObj) || (mSubKey != null && this[i][mSubKey] && this[i][mSubKey] == mObj))) {
                return true;
            }
        }
        return false;
    };
}


/**
 * Array.prototype.containsKey
 *
 * Returns whether an array contains a given key or not.
 *
 * @author  Steffen Eckardt
 * @param   mixed  mObj  Usually a string representing the array element to search for.
 * @since   2006-11-24
 * @version 1.0
 * @return  boolean
 */
if (typeof Array.prototype.containsKey === 'undefined') {
    Array.prototype.containsKey = function(mObj) {
        for (var i in this) {
            if (typeof this[i] != 'function' && this[i] != null && i == mObj) {
                return true;
            }
        }
        return false;
    };
}


/**
 * Class Config
 *
 * This class is used to have a unique configuration point for globally used variables in
 * all JavaScript files.
 *
 * @author  Steffen Eckardt
 * @since   2006-08-23
 * @version 1.0
 */
if (typeof Config == 'undefined') {
    var Config = {
        init: function() {
            this.archives = 'wbc.jar,sac.jar';
            this.mimeTypesSwfAudio = new Array('audio/mpeg', 'audio/x-mpeg');
            this.mimeTypesSwfVideo = new Array('video/flv', 'video/x-flv');
            this.useCourseSearch   = false;
            this.path              = null;
        },

        isCourse: function() {
            return (this.archives.indexOf('course.jar') != -1);
        },

        getArchives: function() {
            return this.archives;
        },

        getCodebaseDefault: function() {
            return (this.isCourse() ? '../../../' : '../');
        },

        getCodebaseContent: function() {
            return (this.isCourse() ? '../../../../' : '../../');
        },

        getMimeTypesSwfAudio: function() {
            return this.mimeTypesSwfAudio;
        },

        getMimeTypesSwfVideo: function() {
            return this.mimeTypesSwfVideo;
        },

        getPath: function() {
            if (typeof this.path == 'undefined' || this.path == null) {
                var a     = document.location.toString().split('?', 2);
                this.path = a[0].substring(0, a[0].lastIndexOf('/html/') + 1);
            }
            return this.path;
        },

        getPathCode: function() {
            return this.getPath() + 'code/';
        },

        getPathCodeJs: function() {
            return this.getPathCode() + 'javascr/';
        },

        getPathContent: function() {
            return this.getPath() + 'content/';
        },

        getPathHtml: function() {
            return this.getPath() + 'html/';
        },

        getPathHtmlContent: function() {
            return this.getPathHtml() + 'content/';
        },

        getPathHtmlContentObjects: function() {
            return this.getPathHtmlContent() + 'objects/';
        },

        getPathImages: function() {
            return this.getPath() + 'images/';
        },

        getPathProp: function() {
            return this.getPathCode() + 'prop/';
        },

        getPathRes: function() {
            return this.getPathCode() + 'res/';
        },

        getPathSwf: function() {
            return this.getPath() + 'swf/';
        },

        getPathTemplates: function(sId) {
            return this.getPath() + 'templates/' + (typeof sId === 'string' && sId.length > 0 ? sId + '/' : '');
        },

        getPathXml: function() {
            return this.getPathCode() + 'xml/';
        },

        getPathXmlSearch: function() {
            return (this.useCourseSearch ? 'code/xml/' : this.getPathXml());
        },

        isMimeTypeSwfAudio: function(sType) {
            return (typeof sType == 'string' ? this.mimeTypesSwfAudio.contains(sType) : false);
        },

        isMimeTypeSwfVideo: function(sType) {
            return (typeof sType == 'string' ? this.mimeTypesSwfVideo.contains(sType) : false);
        }
    };

    Config.init();
}
