Widgit.Configuration = (function() {

	function createDefaultConfig() {
		return {
            symgate: {
                symgateUrl: "symgateproxy.php",
                requestTimeOut: 30000,
                displayHtmlVersion: 2,
                displayHtmlUseSpans: false,
                displayHtmlHttpsImages: false,
                useFlashProxy: false,
                flashProxyUrl: "/insite_3pane/example/insiteproxy.swf",
                flashMinimumVersion: "9.0.0"
            },
            editor: {
                baseUrl: "",

                cmlHiddenInputId: "insiteCml",
                readOnlyCmlHiddenInputId: "insiteReadOnlyCml",
                cmlElementInfosHiddenInputId: "insiteCmlElementInfos",
                displayHtmlHiddenInputId: "insiteDisplayHtml",
                textHiddenInputId: "insiteText",
                editorContentHiddenInputId: "insiteContent",
                linkUrlHiddenInputId: "insiteLinkUrl",
                contentIdHiddenInputId: "insiteContentId",
                allowExistingHiddenInputs: false,

                saveCml: true,
                saveReadOnlyCml: true,
                saveCmlElementInfos: true,
                saveLinkUrl: true,
                saveContentId: true,
                saveHtml: true,
                saveText: true,

                textAreaHeight: 100,
                editPaneWidth: 500,
                editPaneHeight: 300,
                chooserPaneWidth: 160,

                defaultCultureCode: "en-GB",
                preventEditorCssCaching: true,
                maxConceptsPerParagraph: 8,
                swallowErrors: false,
                displayErrorDetail: false,
                doSpellCheck: false,
                saveToWidgitServer: false,

                siteWideSymbolsSpecificToUser: true,
                editPaneHttpsImages: false,
                honourSpaces: true,
                typingSymbolisationDelay: 500,
                extraEditPaneCssFile: null,

                tools: {
                    save: true,
                    retext: true,
                    bold: true,
                    italic: true,
                    link: true,
                    settings: true,
                    symbolSize: true,
                    textSize: true,
                    symbolColour: true,
                    plurals: true,
                    tenses: true,
                    superlatives: true
                }
            }
        };
	}

    // There are issues with this when dealing across frames since different
    // frames have different Array constructors, but we're OK in Insite
    // since all serious code runs in the main document
    function isArray(obj) {
        return (obj instanceof Array);
    }

	// An approximation for Object.prototype.hasOwnProperty for browsers
	// in which it's absent (principally Safari prior to 2.0.2 and IE 5).
	// http://dev.rubyonrails.org/ticket/9700 has an interesting discussion
	// around this
	var objectHasOwnProperty = Object.prototype.hasOwnProperty ?
		function(obj, prop) {
			return obj.hasOwnProperty(prop);
		} :

		function(obj, prop) {
			return typeof obj[prop] != "undefined" && obj.constructor.prototype[prop] !== obj[prop];
		};

	function each(obj, callback) {
		if (obj) {
			for (var i in obj) {
				if ( objectHasOwnProperty(obj, i) ) {
					callback(i, obj);
				}
			}
		}
	}

	function extend(obj, props, deep) {
		var o, p;
		if (props) {
			for (var i in props) {
				if (objectHasOwnProperty(props, i)) {
					o = obj[i];
					p = props[i];
					if (deep && (typeof p == "object") && !isArray(p) && (typeof o == "object") && !isArray(o)) {
						extend(o, p, true);
					} else {
						obj[i] = p;
					}
				}
			}
			// Account for special case of toString in IE
			/*@cc_on
			if (objectHasOwnProperty(props, "toString")) {
				obj.toString = props.toString;
			}
			@*/
		}
		return obj;
	}

	function createConfig(config) {
		var baseConfig = createDefaultConfig();
		if (config) {
			extend(baseConfig, config, true);
		}
		return baseConfig;
	}

    Widgit.Config = createDefaultConfig();

	return {
		createConfig: createConfig
	};
})();
