/// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            // skip transitions at reload but use them later
            new WithTransitionStyle().Content.WaitFor(Native.window.requestAnimationFrameAsync).AttachToHead();



            FlashTitle();


            page.Enter.WhenClicked(
                async delegate
                {
                    // we are in the click handler
                    // the layout was loaded in default state

                    //    _06000002_field_state:
                    //_06000002_field_reason:

                    // jsc why cannot this be null?
                    this.state = new ApplicationState { title = "???" };

                    var newstate = await this.DoEnter();

                    // ready to transition to a new 
                    Native.window.history.pushState(
                        newstate.state,
                        async scope =>
                        {
                            Console.WriteLine("at DoEnter " + new { scope.state });

                            // now what?
                            // we get here either by a click or a reload

                            #region do
                            // we need a copy of childnodes!
                            var oldpagenodes = Native.document.body.childNodes.ToArray();

                            var foopage = new Foo();

                            Native.document.body.Clear();
                            Native.document.body.appendChild(
                                 foopage.body.childNodes.ToArray()
                            );
                            #endregion

                            // should we automate this somehow?
                            var fooapp = new FooApplication(foopage, scope);

                            await scope;

                            #region undo
                            Native.document.body.Clear();
                            Native.document.body.appendChild(
                                 oldpagenodes
                            );

                            // http://connect.microsoft.com/VisualStudio/feedback/details/534869/arrow-keys-stop-working-in-editor
                            // are we sure the state has been restored?

                            // show our intent to reload
                            IStyleSheet.Default["title"].style.color = "red";

                            // wait for any animation, sound to complete, then wipe
                            // what if we move in time during the delay?
                            await Task.Delay(500);

                            Native.document.location.reload();
                            #endregion

                        }
                    );

                }
            );
        }
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            // skip transitions at reload but use them later
            new WithTransitionStyle().Content.WaitFor(Native.window.requestAnimationFrameAsync).AttachToHead();



            FlashTitle();


            page.Enter.WhenClicked(
                async delegate
            {
                // we are in the click handler
                // the layout was loaded in default state

                //    _06000002_field_state:
                //_06000002_field_reason:

                // jsc why cannot this be null?
                this.state = new ApplicationState {
                    title = "???"
                };

                var newstate = await this.DoEnter();

                // ready to transition to a new
                Native.window.history.pushState(
                    newstate.state,
                    async scope =>
                {
                    Console.WriteLine("at DoEnter " + new { scope.state });

                    // now what?
                    // we get here either by a click or a reload

                    #region do
                    // we need a copy of childnodes!
                    var oldpagenodes = Native.document.body.childNodes.ToArray();

                    var foopage = new Foo();

                    Native.document.body.Clear();
                    Native.document.body.appendChild(
                        foopage.body.childNodes.ToArray()
                        );
                    #endregion

                    // should we automate this somehow?
                    var fooapp = new FooApplication(foopage, scope);

                    await scope;

                    #region undo
                    Native.document.body.Clear();
                    Native.document.body.appendChild(
                        oldpagenodes
                        );

                    // http://connect.microsoft.com/VisualStudio/feedback/details/534869/arrow-keys-stop-working-in-editor
                    // are we sure the state has been restored?

                    // show our intent to reload
                    IStyleSheet.Default["title"].style.color = "red";

                    // wait for any animation, sound to complete, then wipe
                    // what if we move in time during the delay?
                    await Task.Delay(500);

                    Native.document.location.reload();
                    #endregion
                }
                    );
            }
                );
        }