(function () {
    /**
     * @module Allthat
     * core module of application
     * provide core functionality
     */
    var A = Allthat = {
        /**
         * Returns the namespace specified and creates it if it doesn't exist
         * <pre>
         * AllThat.namespace("property.package");
         * AllThat.namespace("MooTools.property.package");
         * </pre>
         * Either of the above would create MooTools.property, then
         * MooTools.Project.property.package
         *
         * Be careful when naming packages. Reserved words may work in some browsers
         * and not others. For instance, the following will fail in Safari:
         * <pre>
         * MooTools.namespace("really.long.nested.namespace");
         * </pre>
         * This fails because "long" is a future reserved word in ECMAScript
         *
         * @method namespace
         * @param  {string*} arguments 1-n namespaces to create
         * @return {object}  A reference to the last namespace object created
         */
        namespace : function() {
            var a=arguments, o=null, i, j, d;
            for (i=0; i<a.length; i=i+1) {
                d = a[i].split(".");

                o = window;
                for (j = 0; j < d.length; j = j + 1) {
                    o[d[j]] = o[d[j]] || {};
                    o = o[d[j]];
                }
            }
            return o;
        },
        
        generateUUID : function () {
            return (new Date()).valueOf() + '_' + Math.floor(Math.random() * 1000);
        },
        /** 
         * Usefull for different browser-related quirks, you know, here and there
         */        
        isIE7 : function () {
            return Browser.Engine.name === 'trident';
        }(),

        isWebKit : function () {
            return Browser.Engine.name === 'webkit';
        }(),
        
        getParams : function () {
            var temp = decodeURIComponent(location.search.substr(1)).split('&'),
                params = {},
                regex = /^([^=]+)=([^&]*)$/,
                result;
            
            temp.each(function (el) {
                result = regex.exec(el);
                if (result) {
                    params[result[1]] = result[2].split(';');
                }
            }, this);
            
            this.params = params;
        },
        
        isMainPage : function () { // ugly solution
            var mainPageRegex = /main/i;
            return location.pathname == '/' || mainPageRegex.test(location.pathname);
        },
        
        start : function () {
            this.getParams();
            
            var authorizationStatus = {
                authorized : Allthat.authorized,
                logged_in : Allthat.logged_in
            };
            
            this.GUI.initialize(authorizationStatus);
            
            if (this.isMainPage()) {
                this.Entity.Query = new this.Entity.QueryClass(authorizationStatus);
                this.Entity.Item = new this.Entity.ItemClass();
                this.Entity.Wishlist = new this.Entity.WishlistClass(authorizationStatus);
            }
            
 //           $(document).addEvent('keypress', this.Entity.Wishlist.focusInput);
//              var title = window.document.getElementById('query_' + qid);
        },
        
        showUserEdText : function() {
          $('user_education').setStyle('display','block');
          $('wishlist').setStyle('display','none');
        },
        
        hideUserEdText : function() {
          $('user_education').setStyle('display','none');
          $('wishlist').setStyle('display','block');
        }
    };
})();