﻿namespace('nnet');
var NNet = null;

nnet.NNet = $j.klass({
    initialize: function(startupApp) {
        try {
            document.body.style.cursor = 'wait';
            this.SiteLatitude = sVars.SiteLatitude;
            this.SiteLongitude = sVars.SiteLongitude;
            this.SiteMapZoom = sVars.SiteMapZoom;
            this.ProcessID = null;
            fixedContentLayout();
            adjustLayout();

            if (sVars.CURRENT_APP == "DIRECTORY") {
                if (sVars.TREE_DATA == undefined) SD = new nnet.sd.Directory(null, sVars.INITIAL_DATA);
                else SD = new nnet.sd.Directory(sVars.TREE_DATA, sVars.INITIAL_DATA); // ******
                this.CurrentApp = SD;
            } else if (sVars.CURRENT_APP == "ADMIN") {
                AD = new nnet.admin.Admin(sVars.TREE_DATA);
                this.CurrentApp = AD;
            }
            // Variables
            this.Page = new nnet.Page();
            this.PageHistory = new nnet.PageHistory();
            this.HeaderToolBar = new nnet.HeaderToolBar();
            this.FooterToolBar = new nnet.FooterToolBar();
            
            this.Security = new nnet.Security();
            this.CurrentUser = new nnet.User();
            this.CurrentUser.LoggedIn = sVars.UserLoggedIn;
            if (sVars.UserLoggedIn) onLogIn.fire({ IsAdmin: sVars.IsAdminUser, IsStartUp: true })
            else onLogOut.fire({ IsAdmin: false, IsStartUp: true })

            onLogOut.subscribe(function(type, args) { this.CurrentUser.LoggedIn = false; });
            onLogIn.subscribe(function(type, args) { this.CurrentUser.LoggedIn = true; });

            this.Help = new nnet.Help();

            nnet.onPageReady.subscribe(this.PageHistory.startup);
            nnet.onPageReady.subscribe(this.startup);

            $j('.footer-toolbar').attach(FooterToolBar, { IsUserLoggedIn: sVars.UserLoggedIn, IsUserAdmin: sVars.IsAdminUser, UserHasShoppingCart: sVars.UserHasShoppingCart });
            $j('.footer-toolbar .button').attach(FooterButton);


        } catch (e) { logE("NNet.initialize", e); }
    },

    startup: function() {
        try {
            NNet.ProcessID = $j('#__PROCESSID').val();

            //fixedContentLayout();
            //adjustLayout();
            YAHOO.util.Event.addListener(window, 'resize', ResizePage);
            YAHOO.util.Event.addListener('splitter', 'click', spliterEvent);

            NNet.CurrentApp.startup();
            if (sVars.IsAdminSite) InitAdmin();
            else InitServiceDirectory();

            //            if (sVars.UserLoggedIn) onLogIn.fire()
            //            else onLogOut.fire()
            // Causing problems on startup


            document.body.style.cursor = 'default';
        } catch (e) { logE("NNet.startup", e); }

    },

    // switch to an application fro
    switchApp: function(toApp) {
        if (toApp != CurrentApp) {
        }
    }
});


NNet = new nnet.NNet();

