Ext.define("IceCap.Application", {

    extend: "Ext.app.Application",

    name: "IceCap",

    paths: {
        "IceCap": "/icecap/app"
    },

    appFolder: "/icecap/app",

    mixins: [
		"Ext.mixin.Mashup"
	],

    requires: [
        "IceCap.view.Emulator"
    ],

    launch: function () {

        Ext.get(window.document).on("contextmenu", function (e) {
            e.preventDefault();
            return false;
        });

        Ext.USE_NATIVE_JSON = false;

		var i_sessionProvider = Ext.widget("icecap-state-session-provider", {});
		Ext.state.Manager.setProvider(i_sessionProvider);

		var o_objects = Ext.Object.fromQueryString(window.location.search);

		Ext.Object.each(o_objects, function(s_key, value) {

			o_objects[s_key] = Ext.decode(value, true) || value;
        });

        var i_viewport = Ext.widget("panel", {
            plugins: "viewport",
            layout: "fit"
        });

		var o_config = Ext.apply({
			closable: false,
			theme: o_objects.theme || "",
			scale: 14
        }, o_objects);

        var i_emulator = Ext.create("IceCap.view.Emulator", o_config);

        i_viewport.add(i_emulator);

        IceCap.app.fireEvent("stateReady");
    }
});
