private void AddEvents(IHTMLElement htext)
        {
            var content = new IHTMLDiv().AttachTo(DocumentBody);
            content.Hide();

            var IsCamelCaseNames = "Use CamelCase on event names ".ToCheckBox().AttachToWithLabel(content);

            IHTMLInput NamePrefix = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.text);

            new IHTMLDiv(
                new IHTMLLabel("Event name prefix: ", NamePrefix), NamePrefix
                ).AttachTo(content);

            var update = default(Action);

            // var a = new IHTMLTextArea().AttachTo(content);
            IHTMLButton.Create(
                "Example code",
                delegate
                {
                    a.value =
@"added
	Dispatched when a display object is added to the display list.	
addedToStage
	Dispatched when a display object is added to the on stage display list, either directly or through the addition of a sub tree in which the display object is contained.	
enterFrame
	Dispatched when the playhead is entering a new frame.	
removed
	Dispatched when a display object is about to be removed from the display list.	
removedFromStage
	Dispatched when a display object is about to be removed from the display list, either directly or through the removal of a sub tree in which the display object is contained.	
render
	Dispatched when the display list is about to be updated and rendered.";

                    update();
                }
            ).AttachTo(content);

            // too big
            // var cookie = new Cookie("ExampleEvents").BindTo(a);


            var z = new IHTMLTable().AttachTo(content);
            var zb = z.AddBody();

            var b = new IHTMLTextArea().AttachTo(content);

            htext.onclick +=
                delegate
                {
                    content.ToggleVisible();
                };

            a.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            a.style.width = "100%";
            a.style.height = "20em";


            b.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            b.style.width = "100%";
            b.style.height = "20em";

            b.readOnly = true;

            var dict = new
            {
                EventType = new Dictionary<string, string>(),
                EventCodeName = new Dictionary<string, string>(),
            };

            Action<Action<string>> update_output =
                handler =>
                {
                    var w = new StringBuilder();
                    var w2 = new StringBuilder();

                    var lines = a.Lines.ToArray();

                    w.AppendLine("#region Events");

                    w2.AppendLine("#region Implementation for methods marked with [Script(NotImplementedHere = true)]");

                    var DeclaringTypeName = DeclaringType.value;

                    for (int i = 0; i < lines.Length; i += 2)
                    {
                        if ((i + 1) < lines.Length)
                        {
                            var Summary = lines[i + 1].Trim();
                            var EventName = lines[i].Trim();

                            if (EventName.IndexOf(":") > -1)
                                EventName = EventName.Substring(0, EventName.IndexOf(":")).Trim();

                            if (EventName.ContainsAny("(", "#"))
                                throw new Exception("Invalid Event Name");

                            if (!EventName.Contains("AIR-only"))
                            {
                                //var ReadOnly = "[read-only]";

                                w.AppendLine("/// <summary>");
                                w.AppendLine("/// " + Summary);
                                w.AppendLine("/// </summary>");



                                if (handler != null)
                                    handler(EventName);


                                var EventType = dict.EventType[EventName];
                                var EventCodeName = dict.EventCodeName[EventName];

                                var FriendlyEventName = EventName;

                                if (IsCamelCaseNames.@checked)
                                    FriendlyEventName = FriendlyEventName.ToCamelCase();

                                if (!string.IsNullOrEmpty(NamePrefix.value))
                                    FriendlyEventName = NamePrefix.value + FriendlyEventName;

                                if (FriendlyEventName == "")
                                    throw new Exception("Friendly name is empty.");

                                w.AppendLine("[method: Script(NotImplementedHere = true)]");
                                w.AppendLine("public event Action<" + EventType + "> " + FriendlyEventName + ";");

                                w.AppendLine();



                                w2.AppendLine("#region " + FriendlyEventName);
                                w2.AppendLine("public static void add_" + FriendlyEventName + "(" + DeclaringTypeName + " that, Action<" + EventType + "> value)");
                                w2.AppendLine("{");
                                w2.AppendLine(" CommonExtensions.CombineDelegate(that, value, " + EventType + "." + EventCodeName + ");");
                                w2.AppendLine("}");
                                w2.AppendLine();
                                w2.AppendLine("public static void remove_" + FriendlyEventName + "(" + DeclaringTypeName + " that, Action<" + EventType + "> value)");
                                w2.AppendLine("{");
                                w2.AppendLine(" CommonExtensions.RemoveDelegate(that, value, " + EventType + "." + EventCodeName + ");");
                                w2.AppendLine("}");
                                w2.AppendLine("#endregion");
                                w2.AppendLine();
                            }

                        }
                    }

                    w.AppendLine("#endregion");
                    w2.AppendLine("#endregion");

                    w.AppendLine();

                    w.Append(w2.ToString());

                    b.value = w.ToString();
                };


            update =
                delegate
                {
                    try
                    {
                        zb.removeChildren();

                        // propagate new values to next buttons


                        var PChange = new List<Func<string, string, string, bool>>();

                        update_output(
                            EventName =>
                            {
                                var row = zb.AddRow();

                                row.AddColumn(EventName);

                                var EventType = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.text);

                                if (!dict.EventType.ContainsKey(EventName))
                                    dict.EventType[EventName] = "Event";

                                var EventTypeOld = dict.EventType[EventName];
                                EventType.value = dict.EventType[EventName];

                                var CPChangeOffset = PChange.Count;

                                Action<string, string, string> CPChange =
                                    (_EventName, _Old, _New) =>
                                    {
                                        for (int i = CPChangeOffset + 1; i < PChange.Count; i++)
                                        {
                                            if (!PChange[i](_EventName, _Old, _New))
                                                break;
                                        }
                                    };

                                PChange.Add(
                                    (_Event, _Old, _New) =>
                                    {
                                        // Console.WriteLine(EventName + " detected a change from " + _Event);

                                        if (EventType.value == _Old)
                                        {
                                            EventType.value = _New;
                                            dict.EventType[EventName] = EventType.value;
                                            return true;
                                        }

                                        return false;
                                    }
                                );

                                EventType.onchange +=
                                    delegate
                                    {
                                        if (CPChange != null)
                                            CPChange(EventName, dict.EventType[EventName], EventType.value);

                                        dict.EventType[EventName] = EventType.value;
                                        update_output(null);

                                    };

                                row.AddColumn(EventType);

                                var EventCodeName = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.text);

                                if (!dict.EventCodeName.ContainsKey(EventName))
                                    dict.EventCodeName[EventName] = EventName.ToCamelCaseUpper();

                                EventCodeName.value = dict.EventCodeName[EventName];

                                EventCodeName.onchange +=
                                    delegate
                                    {
                                        dict.EventCodeName[EventName] = EventCodeName.value;
                                        update_output(null);
                                    };

                                row.AddColumn(EventCodeName);
                            }
                        );

                        htext.style.color = Color.Blue;
                    }
                    catch (Exception ex)
                    {
                        htext.style.color = Color.Red;
                        b.value = "error: " + ex.Message;
                    }
                };


            DeclaringType.onchange +=
               delegate
               {
                   update_output(null);
               };

            NamePrefix.onchange += delegate { update(); };
            IsCamelCaseNames.onchange += delegate { update(); };
            a.onchange += delegate { update(); };
        }
        /// <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)
        {
            content.AttachControlToDocument();


          

            var ss = new DataGridView
                {
                    DataSource = Book1.GetDataSet(),
                    DataMember = "Assets"
                };
            content.Controls.Add(ss);

            var x = new IHTMLDiv();

            x.style.backgroundColor = "rgba(255,255,255,1.0)";
            x.style.position = IStyle.PositionEnum.absolute;
            x.style.height = "auto";
            x.style.width = "100%";
            x.style.top = "100%";
            x.style.zIndex = 999;
            var temp = ss.Rows[1];
            var sss = temp.Cells[0].AsHTMLElementContainer();
            sss.style.backgroundColor = "red";
            new TheOtherOption { }.With(
               o =>
               {
                   o.BackColor = Color.White;

                   o.GetHTMLTarget().With(
                       div =>
                       {
                           div.AttachTo(x);


                           div.style.position = IStyle.PositionEnum.absolute;
                       }
                   );

               }
           );


            x.AttachTo(sss.parentNode);
            x.Hide();

            sss.onmouseover += delegate
            {
                x.Show();
            };

            sss.onmouseout += delegate
            {
                x.Hide();
            };



            //that.GotFocus += delegate
            //{
            //    x.Show();
            //};

            //that.Leave += delegate
            //{
            //    x.Hide();
            //};

           
            
        }
        private void AddProperties(IHTMLElement htext)
        {
            //  todo: interface properties

            var content = new IHTMLDiv().AttachTo(DocumentBody);
            content.Hide();

            var IsField = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.checkbox);
            new IHTMLDiv(
                new IHTMLLabel("as fields instead of properties: ", IsField), IsField
            ).AttachTo(content);

            // var a = new IHTMLTextArea().AttachTo(content);
            var b = new IHTMLTextArea().AttachTo(content);


            htext.onclick +=
                delegate
                {
                    content.ToggleVisible();
                };

            a.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            a.style.width = "100%";
            a.style.height = "20em";


            b.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            b.style.width = "100%";
            b.style.height = "20em";

            b.readOnly = true;




            Action update =
                delegate
                {
                    try
                    {
                        //c.removeChildren();

                        var w = new StringBuilder();
                        var lines = a.Lines.ToArray();

                        if (IsField.@checked)
                            w.AppendLine("#region Fields");
                        else
                            w.AppendLine("#region Properties");

                        for (int i = 0; i < lines.Length; i += 2)
                        {
                            if ((i + 1) < lines.Length)
                            {
                                var Summary = lines[i + 1].Trim();

                                if (!lines[i].Contains("AIR-only"))
                                {
                                    var ReadOnly = "[read-only]";

                                    w.AppendLine("/// <summary>");
                                    w.AppendLine("/// " + Summary);
                                    w.AppendLine("/// </summary>");


                                    var x0 = lines[i].Split(':');
                                    var x1 = x0[1].Trim().Split('=');

                                    var DefaultValue = "";

                                    if (x1.Length == 2)
                                        DefaultValue = x1[1].Trim();

                                    var TypeName = FixTypeName(x1[0].Trim());

                                    var FieldName = x0[0].Trim();

                                    /*
                                    var Image = (IHTMLImage)img.cloneNode(false);

                                    Image.style.verticalAlign = "middle";

                                    new IHTMLDiv(
                                        Image,
                                        new IHTMLCode(TypeName + " " + FieldName)
                                        ).AttachTo(c);
                                    */

                                    var StaticModifier = Summary.Contains("[static]") ? "static " : "";

                                    if (IsField.@checked)
                                    {
                                        var ReadonlyModifier = Summary.Contains(ReadOnly) ? "readonly " : "";

                                        var DefaultValueExpression = string.IsNullOrEmpty(DefaultValue) ? "" : " = " + DefaultValue;

                                        w.AppendLine("public " + StaticModifier + ReadonlyModifier + TypeName + " " + FieldName + DefaultValueExpression + ";");
                                    }
                                    else
                                    {
                                        if (Summary.Contains(ReadOnly))
                                            w.AppendLine("public " + StaticModifier + TypeName + " " + FieldName + " { get; private set; }");
                                        else
                                            w.AppendLine("public " + StaticModifier + TypeName + " " + FieldName + " { get; set; }");
                                    }

                                    w.AppendLine();
                                }
                            }
                        }

                        w.AppendLine("#endregion");

                        b.value = w.ToString();
                        htext.style.color = Color.Blue;
                    }
                    catch (Exception ex)
                    {
                        htext.style.color = Color.Red;
                        b.value = "error: " + ex.Message;
                    }
                };

            a.onchange += delegate { update(); };
            IsField.onchange += delegate { update(); };
        }
        private void AddMethods(IHTMLElement htext)
        {
            var content = new IHTMLDiv().AttachTo(DocumentBody);
            content.Hide();

            var IsInterface = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.checkbox);
            new IHTMLDiv(
                new IHTMLLabel("is an interface: ", IsInterface), IsInterface
            ).AttachTo(content);

            var DelegatesParams = new IHTMLInput(ScriptCoreLib.Shared.HTMLInputTypeEnum.checkbox);
            new IHTMLDiv(
                new IHTMLLabel("delegates parameters to base constructor: ", DelegatesParams), DelegatesParams
            ).AttachTo(content);

            var update = default(Action);

            // var a = new IHTMLTextArea().AttachTo(content);

            IHTMLButton.Create(
                "Example code",
                delegate
                {
                    a.value =
@"addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
";

                    update();
                }
            ).AttachTo(content);



            var b = new IHTMLTextArea().AttachTo(content);

            htext.onclick +=
                delegate
                {
                    content.ToggleVisible();
                };

            a.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            a.style.width = "100%";
            a.style.height = "20em";


            b.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            b.style.width = "100%";
            b.style.height = "20em";

            b.readOnly = true;



            Action update_output =
                delegate
                {
                    var w = new StringBuilder();
                    var w2 = new StringBuilder();

                    var lines = a.Lines.ToArray();

                    w.AppendLine("#region Methods");
                    w2.AppendLine("#region Constructors");

                    for (int i = 0; i < lines.Length; i += 3)
                    {
                        if ((i + 1) < lines.Length)
                        {
                            var StaticKeyword = "[static]";

                            var Summary = lines[i + 1].Trim();
                            var MethodSig = lines[i].Trim();


                            if (!MethodSig.Contains("AIR-only"))
                            {
                                var q0 = MethodSig.Split(')');
                                var q1 = q0[0].Split('(');

                                var MethodName = FixVariableName(q1[0].Trim());
                                var MethodParameters = new MethodParametersInfo(q1[1].Trim());

                                var MethodReturnType = "";

                                if (q0[1].StartsWith(":"))
                                    MethodReturnType = FixTypeName(q0[1].Substring(1).Trim());



                                var IsConstructor = string.IsNullOrEmpty(MethodReturnType);

                                foreach (var v in MethodParameters.Variations)
                                {
                                    if (IsConstructor)
                                    {
                                        w2.AppendLine("/// <summary>");
                                        w2.AppendLine("/// " + Summary);
                                        w2.AppendLine("/// </summary>");

                                        if (DelegatesParams.@checked)
                                            w2.AppendLine("public " + MethodName + "(" + v + ") : base(" + v.NamesToString() + ")");
                                        else
                                            w2.AppendLine("public " + MethodName + "(" + v + ")");

                                        w2.AppendLine("{");
                                        w2.AppendLine("}");
                                        w2.AppendLine();
                                    }
                                    else
                                    {
                                        if (v.Parameters.Length == 0 && MethodName == "toString")
                                        {

                                        }
                                        else
                                        {
                                            w.AppendLine("/// <summary>");
                                            w.AppendLine("/// " + Summary);
                                            w.AppendLine("/// </summary>");

                                            var StaticModifier = Summary.Contains(StaticKeyword) ? "static " : "";

                                            if (IsInterface.@checked)
                                            {
                                                w.AppendLine(MethodReturnType + " " + MethodName + "(" + v + ");");

                                            }
                                            else
                                            {
                                                w.AppendLine("public " + StaticModifier + MethodReturnType + " " + MethodName + "(" + v + ")");
                                                w.AppendLine("{");

                                                if (MethodReturnType != "void")
                                                    w.AppendLine("  return default(" + MethodReturnType + ");");

                                                w.AppendLine("}");
                                            }
                                            w.AppendLine();

                                        }
                                    }
                                }




                            }


                        }
                    }

                    w.AppendLine("#endregion");
                    w2.AppendLine("#endregion");

                    if (!IsInterface.@checked)
                    {
                        w.AppendLine();
                        w.Append(w2.ToString());
                    }

                    b.value = w.ToString();
                };

            update =
                delegate
                {


                    try
                    {

                        update_output();
                        htext.style.color = Color.Blue;
                    }
                    catch (Exception ex)
                    {
                        htext.style.color = Color.Red;
                        b.value = "error: " + ex.Message;
                    }
                };

            IsInterface.onchange += delegate { update(); };
            DelegatesParams.onchange += delegate { update(); };

            a.onchange +=
                delegate
                {
                    update();
                };
        }
		private static void AddSection11(Action<string, IHTMLDiv> AddSection)
		{
			var ToolbarHeight = "24px";

			var Content = new IHTMLDiv().With(
				k =>
				{
					k.style.border = "1px solid gray";
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.relative;
					k.style.width = "100%";
					k.style.height = "20em";
				}
			);

            //global::ScriptCoreLib.Ultra.Components.HTML
            // reload the project to make visual studio happy!
			new TwentyTenWorkspace().ToBackground(Content.style, true);

			var ToolbarContainerBackground = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = "0px";
					k.style.height = ToolbarHeight;

					k.style.backgroundColor = Color.White;
					k.style.Opacity = 0.5;
				}
			).AttachTo(Content);

			var ToolbarContainer = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = "0px";
					k.style.height = ToolbarHeight;


				}
			).AttachTo(Content);

			var PreviewContainer = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = ToolbarHeight;
					k.style.bottom = "0px";
				}
			).AttachTo(Content);


			var PreviewFrame = new IHTMLIFrame { src = "about:blank" };

			PreviewFrame.style.width = "100%";
			PreviewFrame.style.height = "100%";
			PreviewFrame.style.border = "0";
			PreviewFrame.style.margin = "0";
			PreviewFrame.style.padding = "0";
			PreviewFrame.frameBorder = "0";
			PreviewFrame.border = "0";

			PreviewFrame.AttachTo(PreviewContainer);

			PreviewContainer.Hide();

			var EditorContainer = new IHTMLDiv().With(
				k =>
				{
					k.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
					k.style.left = "0px";
					k.style.right = "0px";
					k.style.top = ToolbarHeight;
					k.style.bottom = "0px";
				}
			).AttachTo(Content);

			var EditorFrame = VisualStudioView.CreateEditor().AttachTo(EditorContainer);

			PreviewFrame.allowTransparency = true;
			EditorFrame.allowTransparency = true;

			EditorFrame.WhenContentReady(
				body =>
				{
					body.style.backgroundColor = Color.Transparent;

					new IHTMLDiv
					{
						"Hello world :)"
					}.With(
						div =>
						{
							div.style.backgroundColor = Color.White;
							div.style.borderColor = Color.Gray;
							div.style.borderStyle = "solid";
							div.style.borderWidth = "1px";

							div.style.margin = "2em";
							div.style.padding = "2em";
						}
					).AttachTo(body);

				}
			);

			var ToolbarContent = new IHTMLDiv().AttachTo(ToolbarContainer);

			ToolbarContent.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.relative;

			Action<IHTMLElement> ApplyToolbarButtonStyle =
				k =>
				{
					k.style.verticalAlign = "top";

					k.style.padding = "0";
					k.style.margin = "0";
					k.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;
					k.style.SetSize(24, 24);

					VisualStudioView.ApplyMouseHoverStyle(k, Color.Transparent);
				};

			Func<IHTMLImage, IHTMLButton> AddButtonDummy =
				(img) =>
				{
					return new IHTMLButton { img.WithinContainer() }.With(k => ApplyToolbarButtonStyle(k)).AttachTo(ToolbarContent);
				};

			Func<IHTMLImage, Action, IHTMLButton> AddButtonAction =
				(img, command) =>
				{
					return AddButtonDummy(img).With(
						k =>
						{
							k.onclick +=
								delegate
								{
									command();
								};

						}
					);
				};

			Func<IHTMLImage, string, IHTMLButton> AddButton =
				(img, command) =>
				{
					return AddButtonAction(img, () =>
						EditorFrame.contentWindow.document.execCommand(
							command, false, null
						)
					);
				};


			//AddButtonDummy(new RTA_save());

			var SaveContainer = new IHTMLDiv().With(k => ApplyToolbarButtonStyle(k)).AttachTo(ToolbarContent);


			SaveContainer.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.inline_block;

			//var Save = new InternalSaveActionSprite();

			//Save.ToTransparentSprite();
			//Save.AttachSpriteTo(SaveContainer);


			var s = new { VisualStudioTemplates.VisualCSharpProject };

			EditorFrame.WhenContentReady(
				body =>
				{
					var t = (IHTMLTextArea)EditorFrame.contentWindow.document.createElement("textarea");

					t.AttachTo(body);

					t.value = s.ToString();

				}
			);

			//Save.WhenReady(
			//    i =>
			//    {
			//        i.FileName = "Project1.zip";


			//        i.Add("Project1.txt", "x");
			//        i.Add("Project1.csproj", s.VisualCSharpProject);
			//    }
			//);

			ToolbarContent.Add(new RTA_separator_horizontal());

			var RTAButtons = new Dictionary<string, IHTMLImage>
			{
				// http://trac.symfony-project.org/browser/plugins/dmCkEditorPlugin/web/js/ckeditor/_source/plugins?rev=27455

				{"Bold", new RTA_bold()},
				{"Underline", new RTA_underline()},
				{"Strikethrough", new RTA_strikethrough()},
				{"Italic", new RTA_italic()},
				{"JustifyLeft", new RTA_justifyleft()},
				{"JustifyCenter", new RTA_justifycenter()},
				{"JustifyRight", new RTA_justifyright()},
				{"JustifyFull", new RTA_justifyfull()},
				{"Indent", new RTA_indent()},
				{"Outdent", new RTA_outdent()},
				{"Superscript", new RTA_superscript()},
				{"Subscript", new RTA_sub()},
				{"Removeformat", new RTA_removeformat()},
				{"InsertOrderedList", new RTA_numberedlist()},
				{"InsertUnorderedList", new RTA_numberedlist()},
				{"undo", new RTA_undo()},
				{"redo", new RTA_redo()},
			}.ToDictionary(
				k => k.Key,
				k => AddButton(k.Value, k.Key)
			);




			var ButtonDesign = default(IHTMLButton);
			var ButtonHTML = default(IHTMLButton);

			ButtonDesign = AddButtonAction(new RTA_mode_design(),
				delegate
				{
					ButtonDesign.Hide();
					ButtonHTML.Show();

					EditorContainer.Show();
					PreviewContainer.Hide();
				}
			);

			ButtonHTML = AddButtonAction(new RTA_mode_html(),
				delegate
				{
					ButtonHTML.Hide();


					PreviewFrame.WithContent(
						body =>
						{
							body.style.backgroundColor = Color.Transparent;
							body.innerHTML = EditorFrame.contentWindow.document.body.innerHTML;

							EditorContainer.Hide();
							PreviewContainer.Show();
							ButtonDesign.Show();
						}
					);
				}
			);

			ButtonDesign.Hide();

			AddSection(
				"Editor with toolbar with background and preview",
				Content
			);
		}
        private void AddConstants(IHTMLElement htext)
        {
            var content = new IHTMLDiv().AttachTo(DocumentBody);
            content.Hide();

            var IsEnum = "Declare constants as enums ".ToCheckBox().AttachToWithLabel(content);


            var update = default(Action);


            // var a = new IHTMLTextArea().AttachTo(content);
            IHTMLButton.Create(
                "Example code",
                delegate
                {
                    a.value =
@"ACTIVATE : String = ""activate""
[static] The Event.ACTIVATE constant defines the value of the type property of an activate event object.
	ADDED : String = ""added""
[static] The Event.ADDED constant defines the value of the type property of an added event object.
	ADDED_TO_STAGE : String = ""addedToStage""
[static] The Event.ADDED_TO_STAGE constant defines the value of the type property of an addedToStage event object.
	CANCEL : String = ""cancel""
[static] The Event.CANCEL constant defines the value of the type property of a cancel event object.
	CHANGE : String = ""change""
[static] The Event.CHANGE constant defines the value of the type property of a change event object.
	CLOSE : String = ""close""
[static] The Event.CLOSE constant defines the value of the type property of a close event object.
	AIR-only CLOSING : String = ""closing""
[static] The Event.CLOSING constant defines the value of the type property of a closing event object.
	COMPLETE : String = ""complete""
[static] The Event.COMPLETE constant defines the value of the type property of a complete event object.
	CONNECT : String = ""connect""
[static] The Event.CONNECT constant defines the value of the type property of a connect event object.
	DEACTIVATE : String = ""deactivate""
[static] The Event.DEACTIVATE constant defines the value of the type property of a deactivate event object.
	AIR-only DISPLAYING : String = ""displaying""
[static] Defines the value of the type property of a displaying event object.
	ENTER_FRAME : String = ""enterFrame""
[static] The Event.ENTER_FRAME constant defines the value of the type property of an enterFrame event object.
	AIR-only EXITING : String = ""exiting""
[static] The Event.EXITING constant defines the value of the type property of an exiting event object.
	FULLSCREEN : String = ""fullScreen""
[static] The Event.FULL_SCREEN constant defines the value of the type property of a fullScreen event object.
	AIR-only HTML_BOUNDS_CHANGE : String = ""htmlBoundsChange""
[static] The Event.HTML_BOUNDS_CHANGE constant defines the value of the type property of an htmlBoundsChange event object.
	AIR-only HTML_DOM_INITIALIZE : String = ""htmlDOMInitialize""
[static] The Event.HTML_DOM_INITIALIZE constant defines the value of the type property of an htmlDOMInitialize event object.
	AIR-only HTML_RENDER : String = ""htmlRender""
[static] The Event.HTML_RENDER constant defines the value of the type property of an htmlRender event object.
	ID3 : String = ""id3""
[static] The Event.ID3 constant defines the value of the type property of an id3 event object.
	INIT : String = ""init""
[static] The Event.INIT constant defines the value of the type property of an init event object.
	AIR-only LOCATION_CHANGE : String = ""locationChange""
[static] The Event.LOCATION_CHANGE constant defines the value of the type property of a locationChange event object.
	MOUSE_LEAVE : String = ""mouseLeave""
[static] The Event.MOUSE_LEAVE constant defines the value of the type property of a mouseLeave event object.
	AIR-only NETWORK_CHANGE : String = ""networkChange""
[static] The Event.NETWORK_CHANGE constant defines the value of the type property of a networkChange event object.
	OPEN : String = ""open""
[static] The Event.OPEN constant defines the value of the type property of an open event object.
	REMOVED : String = ""removed""
[static] The Event.REMOVED constant defines the value of the type property of a removed event object.
	REMOVED_FROM_STAGE : String = ""removedFromStage""
[static] The Event.REMOVED_FROM_STAGE constant defines the value of the type property of a removedFromStage event object.
	RENDER : String = ""render""
[static] The Event.RENDER constant defines the value of the type property of a render event object.
	RESIZE : String = ""resize""
[static] The Event.RESIZE constant defines the value of the type property of a resize event object.
	SCROLL : String = ""scroll""
[static] The Event.SCROLL constant defines the value of the type property of a scroll event object.
	SELECT : String = ""select""
[static] The Event.SELECT constant defines the value of the type property of a select event object.
	SOUND_COMPLETE : String = ""soundComplete""
[static] The Event.SOUND_COMPLETE constant defines the value of the type property of a soundComplete event object.
	TAB_CHILDREN_CHANGE : String = ""tabChildrenChange""
[static] The Event.TAB_CHILDREN_CHANGE constant defines the value of the type property of a tabChildrenChange event object.
	TAB_ENABLED_CHANGE : String = ""tabEnabledChange""
[static] The Event.TAB_ENABLED_CHANGE constant defines the value of the type property of a tabEnabledChange event object.
	TAB_INDEX_CHANGE : String = ""tabIndexChange""
[static] The Event.TAB_INDEX_CHANGE constant defines the value of the type property of a tabIndexChange event object.
	UNLOAD : String = ""unload""
[static] The Event.UNLOAD constant defines the value of the type property of an unload event object.
	AIR-only USER_IDLE : String = ""userIdle""
[static] The Event.USER_IDLE constant defines the value of the type property of a userIdle event object.
	AIR-only USER_PRESENT : String = ""userPresent""
[static] The Event.USER_PRESENT constant defines the value of the type property of a userPresent event object.
";

                    update();
                }
            ).AttachTo(content);


            var z = new IHTMLTable().AttachTo(content);
            var zb = z.AddBody();

            var b = new IHTMLTextArea().AttachTo(content);

            htext.onclick +=
                delegate
                {
                    content.ToggleVisible();
                };

            a.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            a.style.width = "100%";
            a.style.height = "20em";


            b.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.block;
            b.style.width = "100%";
            b.style.height = "20em";

            b.readOnly = true;



            Action<Action<string>> update_output =
                handler =>
                {
                    var w = new StringBuilder();
                    var w2 = new StringBuilder();

                    var lines = a.Lines.ToArray();

                    if (IsEnum.@checked)
                    {
                        w.AppendLine("public enum " + DeclaringType.value);
                        w.AppendLine("{");
                    }
                    else
                        w.AppendLine("#region Constants");

                    for (int i = 0; i < lines.Length; i += 2)
                    {
                        if ((i + 1) < lines.Length)
                        {
                            var Summary = lines[i + 1].Trim();

                            var x = lines[i].Split(':');


                            var ConstantName = x[0].Trim();

                            if (ConstantName.Contains("("))
                                throw new Exception("Invalid Constant Name");


                            var y = x[1].Trim().Split('=');

                            var ConstantType = FixTypeName(y[0].Trim());
                            var ConstantValue = y[1].Trim();


                            if (!ConstantName.Contains("AIR-only"))
                            {



                                w.AppendLine("/// <summary>");
                                w.AppendLine("/// " + Summary);
                                w.AppendLine("/// </summary>");




                                if (handler != null)
                                    handler(ConstantName);

                                if (IsEnum.@checked)
                                {
                                    var Prefix = DeclaringType.value.ToLower() + "_";

                                    if (ConstantName.ToLower().StartsWith(Prefix))
                                        ConstantName = ConstantName.Substring(Prefix.Length).ToLower().ToCamelCase();

                                    if (string.IsNullOrEmpty(ConstantValue))
                                        w.AppendLine(ConstantName + ",");
                                    else
                                        w.AppendLine(ConstantName + " = " + ConstantValue + ",");
                                }
                                else
                                {
                                    if (string.IsNullOrEmpty(ConstantValue))
                                        w.AppendLine("public static readonly " + ConstantType + " " + ConstantName + ";");
                                    else
                                        w.AppendLine("public static readonly " + ConstantType + " " + ConstantName + " = " + ConstantValue + ";");
                                }

                                w.AppendLine();


                            }


                        }
                    }

                    if (IsEnum.@checked)
                    {
                        w.AppendLine("}");
                    }
                    else
                        w.AppendLine("#endregion");



                    b.value = w.ToString();
                };

            update =
                delegate
                {
                    try
                    {
                        zb.removeChildren();

                        update_output(
                            null
                        );
                        htext.style.color = Color.Blue;
                    }
                    catch (Exception ex)
                    {
                        htext.style.color = Color.Red;
                        b.value = "error: " + ex.Message;
                    }
                };

            DeclaringType.onchange += delegate { update(); };
            IsEnum.onchange += delegate { update(); };


            a.onchange += delegate { update(); };
        }
        public static IHTMLDiv AddDropDownOptions(this TextBox that, params object[] e)
        {
            var x = new IHTMLDiv();

            x.style.backgroundColor = "rgba(255,255,255,1.0)";
            x.style.position = IStyle.PositionEnum.absolute;
            x.style.height = "auto";
            x.style.width = "100%";
            x.style.top = "100%";
            x.style.zIndex = 999;

            var c = that.GetHTMLTarget();

            x.AttachTo(c);

            x.Hide();

            that.GotFocus += delegate
            {
                x.Show();
            };

            that.Leave += delegate
            {
                x.Hide();
            };

            e.AsEnumerable().WithEach(
                k =>
                {
                    {
                        //var o = k as UserControl;
                        var o = k as Control;
                        if (o != null)
                        {
                            o.BackColor = Color.Transparent;

                            o.GetHTMLTarget().With(
                                div =>
                                {
                                    div.AttachTo(x);

                                    div.style.width = "auto";
                                    div.style.position = IStyle.PositionEnum.relative;
                                }
                            );

                            return;
                        }
                    }

                    {
                        var o = (INodeConvertible<IHTMLDiv>)k;
                        {
                            o.AttachTo(x);
                         
                            //o.div.css.hover.style.backgroundColor = "yellow";
                        }
                    }
                }
            );

            return x;
        }
        /// <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)
        {
            content.AttachControlToDocument();

            var x = new IHTMLDiv();

            x.style.backgroundColor = "rgba(255,255,255,1.0)";
            x.style.position = IStyle.PositionEnum.absolute;
            x.style.height = "auto";
            x.style.width = "100%";
            x.style.top = "100%";
            x.style.zIndex = 999;


            x.AttachTo(content.textBox1.GetHTMLTarget());

            x.Hide();
            Action close = delegate
            {
                x.Hide();
            };

            Action<string> add = name =>
                new Option { name = name }.With(
                    o =>
                    {

                        o.AttachTo(x);

                        o.div.css.hover.style.backgroundColor = "green";

                        o.div.onclick +=
                            delegate
                            {
                                Console.WriteLine(o.name.innerText);
                                content.textBox1.Text = o.name.innerText;
                                close();
                                //content.textBox1.Text = o.name;
                            };
                    }
                );


            //content.checkBox1.CheckedChanged += delegate { x.Show(content.checkBox1.Checked); };
            content.textBox1.GotFocus += delegate
            {
                x.Show();
            };


            add("foo");
            add("Marge Simpson");

            new TheOtherOption { }.With(
                o =>
                {
                    o.BackColor = Color.Transparent;

                    o.GetHTMLTarget().With(
                        div =>
                        {
                            div.AttachTo(x);


                            div.style.position = IStyle.PositionEnum.relative;
                        }
                    );

                }
            );

            add("bar");

            var ls = new Option { name = "Lisa Simpson EUR" }.With(o =>
            {
                o.div.css.hover.style.backgroundColor = "rgba(118, 207, 140, 0.7)";

                o.div.onclick +=
                    delegate
                    {
                        content.textBox1.Text = o.name.innerText;
                        close();
                    };
            });

            content.textBox2.AddDropDownOptions(
                new Option { name = "hello" },
                new TheOtherOption { },
                new Option { name = "world" },
                ls

            );

        }
        private static void AddTypeProperty(
    IHTMLDiv parent,
    CompilationProperty type,
    Action<string> UpdateLocation
    )
        {
            var div = new IHTMLDiv().AttachTo(parent);

            div.style.marginTop = "0.1em";
            div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
            div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


            var i = new PublicProperty().AttachTo(div);

            i.style.verticalAlign = "middle";
            i.style.marginRight = "0.5em";

            var s = new IHTMLAnchor { innerText = type.Name }.AttachTo(div);


            s.href = "#";
            s.style.textDecoration = "none";
            s.style.color = JSColor.System.WindowText;

            Action onclick = delegate
            {

            };

            s.onclick +=
                e =>
                {
                    e.PreventDefault();

                    s.focus();

                    UpdateLocation(type.Name);

                    onclick();
                };

            s.onfocus +=
                delegate
                {

                    s.style.backgroundColor = JSColor.System.Highlight;
                    s.style.color = JSColor.System.HighlightText;
                };

            s.onblur +=
                delegate
                {

                    s.style.backgroundColor = JSColor.None;
                    s.style.color = JSColor.System.WindowText;
                };


            onclick =
                delegate
                {
                    var children = new IHTMLDiv().AttachTo(div);

                    children.style.paddingLeft = "2em";

                    AddTypeMethod(children, type.GetGetMethod(), UpdateLocation);
                    AddTypeMethod(children, type.GetSetMethod(), UpdateLocation);


                    //a.GetTypes().ForEach(
                    //    (Current, Next) =>
                    //    {
                    //        AddType(GetNamespaceContainer(children, Current), Current, UpdateLocation);

                    //        ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                    //            50,
                    //            Next
                    //        );
                    //    }
                    //);


                    var NextClickHide = default(Action);
                    var NextClickShow = default(Action);

                    NextClickHide =
                        delegate
                        {
                            children.Hide();

                            onclick = NextClickShow;
                        };

                    NextClickShow =
                        delegate
                        {
                            children.Show();

                            onclick = NextClickHide;
                        };


                    onclick = NextClickHide;
                };
        }
        private static void AddTypeEvent(
        IHTMLDiv parent,
        CompilationEvent type,
        Action<string> UpdateLocation
        )
        {
            var div = new IHTMLDiv().AttachTo(parent);

            div.style.marginTop = "0.1em";
            div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
            div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


            var i = new PublicEvent().AttachTo(div);

            i.style.verticalAlign = "middle";
            i.style.marginRight = "0.5em";

            var s = new IHTMLAnchor { innerText = type.Name }.AttachTo(div);


            s.href = "#";
            s.style.textDecoration = "none";
            s.style.color = JSColor.System.WindowText;

            Action onclick = delegate
            {

            };

            s.onclick +=
                e =>
                {
                    e.PreventDefault();

                    s.focus();

                    UpdateLocation(type.Name);

                    onclick();
                };

            s.onfocus +=
                delegate
                {

                    s.style.backgroundColor = JSColor.System.Highlight;
                    s.style.color = JSColor.System.HighlightText;
                };

            s.onblur +=
                delegate
                {

                    s.style.backgroundColor = JSColor.None;
                    s.style.color = JSColor.System.WindowText;
                };


            onclick =
                delegate
                {
                    var children = new IHTMLDiv().AttachTo(div);

                    children.style.paddingLeft = "2em";

                    AddTypeMethod(children, type.GetAddMethod(), UpdateLocation);
                    AddTypeMethod(children, type.GetRemoveMethod(), UpdateLocation);



                    var NextClickHide = default(Action);
                    var NextClickShow = default(Action);

                    NextClickHide =
                        delegate
                        {
                            children.Hide();

                            onclick = NextClickShow;
                        };

                    NextClickShow =
                        delegate
                        {
                            children.Show();

                            onclick = NextClickHide;
                        };


                    onclick = NextClickHide;
                };
        }
        private void AddType(IHTMLDiv parent, CompilationType type, Action<string> UpdateLocation)
        {
            var div = new IHTMLDiv().AttachTo(parent);

            div.style.marginTop = "0.1em";
            div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
            div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


            var i = default(IHTMLImage);

            if (type.IsInterface)
            {
                i = new PublicInterface();
            }
            else
            {
                i = new PublicClass();
            }

            i.AttachTo(div);

            i.style.verticalAlign = "middle";
            i.style.marginRight = "0.5em";

            var s = new IHTMLAnchor { innerText = type.Name, title = "" + type.MetadataToken }.AttachTo(div);

            if (!string.IsNullOrEmpty(type.HTMLElement))
            {
                var c = new IHTMLCode();

                Action<string, JSColor> Write =
                    (Text, Color) =>
                    {
                        var cs = new IHTMLSpan { innerText = Text };

                        cs.style.color = Color;

                        cs.AttachTo(c);
                    };

                Write("<", JSColor.Blue);
                Write(type.HTMLElement, JSColor.FromRGB(0xa0, 0, 0));
                Write("/>", JSColor.Blue);

                //c.style.marginLeft = "1em";
                c.style.Float = ScriptCoreLib.JavaScript.DOM.IStyle.FloatEnum.right;

                c.AttachTo(s);
            }

            s.href = "#";
            s.style.textDecoration = "none";
            s.style.color = JSColor.System.WindowText;

            Action onclick = delegate
            {

            };

            s.onclick +=
                e =>
                {
                    e.PreventDefault();

                    s.focus();

                    if (TouchTypeSelected != null)
                        TouchTypeSelected(type);

                    UpdateLocation(type.FullName + " - " + type.Summary + " - HTML:" + type.HTMLElement);

                    onclick();
                };

            s.onfocus +=
                delegate
                {

                    s.style.backgroundColor = JSColor.System.Highlight;
                    s.style.color = JSColor.System.HighlightText;
                };

            s.onblur +=
                delegate
                {

                    s.style.backgroundColor = JSColor.None;
                    s.style.color = JSColor.System.WindowText;
                };



            onclick =
                delegate
                {

                    var children = new IHTMLDiv().AttachTo(div);

                    children.style.paddingLeft = "1em";

                    Func<IHTMLDiv> Group = () => new IHTMLDiv().AttachTo(children);

                    var Groups = new
                    {
                        Nested = Group(),
                        Constructors = Group(),
                        Methods = Group(),
                        Events = Group(),
                        Fields = Group(),
                        Properties = Group(),
                    };


                    type.GetNestedTypes().ForEach(
                        (Current, Next) =>
                        {
                            AddType(Groups.Nested, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    );

                    type.GetConstructors().ForEach(
                        (Current, Next) =>
                        {
                            AddTypeConstructor(Groups.Constructors, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    );

                    var HiddenMethods = new List<int>();

                    Action<CompilationMethod> AddIfAny =
                        SourceMethod =>
                        {
                            if (SourceMethod == null)
                                return;

                            HiddenMethods.Add(SourceMethod.MetadataToken);
                        };

                    Action AfterEvents = delegate
                    {

                        type.GetMethods().ForEach(
                            (Current, Next) =>
                            {
                                if (!HiddenMethods.Contains(Current.MetadataToken))
                                {
                                    AddTypeMethod(Groups.Methods, Current, UpdateLocation);
                                }

                                ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                    50,
                                    Next
                                );
                            }
                        );

                    };

                    Action AfterProperties = delegate
                    {
                        type.GetEvents().ForEach(
                            (Current, Next) =>
                            {
                                AddIfAny(Current.GetAddMethod());
                                AddIfAny(Current.GetRemoveMethod());

                                AddTypeEvent(Groups.Events, Current, UpdateLocation);

                                ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                    50,
                                    Next
                                );
                            }
                        )(AfterEvents);
                    };

                    type.GetProperties().ForEach(
                        (Current, Next) =>
                        {
                            AddIfAny(Current.GetSetMethod());
                            AddIfAny(Current.GetGetMethod());

                            AddTypeProperty(Groups.Properties, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    )(AfterProperties);






                    type.GetFields().ForEach(
                        (Current, Next) =>
                        {
                            AddTypeField(Groups.Fields, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    );




                    var NextClickHide = default(Action);
                    var NextClickShow = default(Action);

                    NextClickHide =
                        delegate
                        {
                            children.Hide();

                            onclick = NextClickShow;
                        };

                    NextClickShow =
                        delegate
                        {
                            children.Show();

                            onclick = NextClickHide;
                        };


                    onclick = NextClickHide;
                };
        }
        private static IHTMLDiv AddNamespace(IHTMLDiv parent, IHTMLDiv NextNamespaceOrDefault, string Namespace, Action<string> UpdateLocation)
        {
            var div = new IHTMLDiv();

            if (NextNamespaceOrDefault == null)
                div.AttachTo(parent);
            else
                NextNamespaceOrDefault.insertPreviousSibling(div);

            div.style.marginTop = "0.1em";
            div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
            div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


            var i = new Namespace().AttachTo(div);

            i.style.verticalAlign = "middle";
            i.style.marginRight = "0.5em";

            if (Namespace == "")
                Namespace = "<Module>";

            var s = new IHTMLAnchor { innerText = Namespace }.AttachTo(div);


            s.href = "#";
            s.style.textDecoration = "none";
            s.style.color = JSColor.System.WindowText;

            Action onclick = delegate
            {

            };

            s.onclick +=
                e =>
                {
                    e.PreventDefault();

                    s.focus();

                    UpdateLocation(Namespace);

                    onclick();
                };

            s.onfocus +=
                delegate
                {

                    s.style.backgroundColor = JSColor.System.Highlight;
                    s.style.color = JSColor.System.HighlightText;
                };

            s.onblur +=
                delegate
                {

                    s.style.backgroundColor = JSColor.None;
                    s.style.color = JSColor.System.WindowText;
                };

            var children = new IHTMLDiv().AttachTo(div);

            children.style.paddingLeft = "1em";
            children.Hide();


            var NextClickHide = default(Action);
            var NextClickShow = default(Action);

            NextClickHide =
                delegate
                {
                    children.Hide();

                    onclick = NextClickShow;
                };

            NextClickShow =
                delegate
                {
                    children.Show();

                    onclick = NextClickHide;
                };


            onclick = NextClickShow;

            return children;
        }
        private void RenderAssemblies(
            CompilationArchiveBase archive,
            IHTMLElement parent,
            Func<string, IHTMLDiv> AllTypes,
            Action<string> UpdateLocation,
            Action<Action<Action>> YieldLoadAction)
        {
            var Assemblies = archive.GetAssemblies();

            foreach (var Assembly in Assemblies)
            {
                Console.WriteLine(new { Assembly.Name });

            }

            var q = from a in Assemblies
                    where a.Name.StartsWith("ScriptCoreLib")
                    orderby a.Name
                    select a;

            // limit to only first one for speedup

            foreach (var item2 in q.Take(1))
            {
                var item = item2;

                var div = new IHTMLDiv().AttachTo(parent);

                div.style.marginTop = "0.1em";
                div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
                div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


                var i = new Assembly().AttachTo(div);

                i.style.verticalAlign = "middle";
                i.style.marginRight = "0.5em";

                var s = new IHTMLAnchor { innerText = item2.Name }.AttachTo(div);

                //s.style.color = JSColor.Gray;

                s.href = "#";
                s.style.textDecoration = "none";
                s.style.color = JSColor.System.GrayText;

                Action onclick = delegate
                {

                };

                s.onclick +=
                    e =>
                    {
                        e.PreventDefault();

                        s.focus();

                        UpdateLocation(item.Name);

                        onclick();
                    };

                s.onfocus +=
                    delegate
                    {

                        s.style.backgroundColor = JSColor.System.Highlight;
                        s.style.color = JSColor.System.HighlightText;
                    };

                s.onblur +=
                    delegate
                    {

                        s.style.backgroundColor = JSColor.None;
                        s.style.color = JSColor.System.WindowText;
                    };

                var NamespaceLookup = new Dictionary<string, IHTMLDiv>();

                Func<IHTMLDiv, CompilationType, IHTMLDiv> GetNamespaceContainer =
                    (Container, SourceType) =>
                    {
                        if (!NamespaceLookup.ContainsKey(SourceType.Namespace))
                        {
                            NamespaceLookup[SourceType.Namespace] = null;

                            var NextNamespaceOrDefault = default(IHTMLDiv);

                            //var NextNamespaceOrDefault = NamespaceLookup.Keys.OrderBy(k => k).SkipWhile(k => k == SourceType.Namespace).Select(k => NamespaceLookup[k]).FirstOrDefault();

                            NamespaceLookup[SourceType.Namespace] = AddNamespace(Container, NextNamespaceOrDefault, SourceType.Namespace, UpdateLocation);
                        }

                        return NamespaceLookup[SourceType.Namespace];
                    };


                var children = new IHTMLDiv().AttachTo(div);

                children.style.paddingLeft = "1em";
                Action<Action> LoadAction =
                    done =>
                    {
                        Console.WriteLine("enter LoadAction");

                        s.style.color = JSColor.System.Highlight;

                        Action done_ = delegate
                        {
                            done();
                        };



                        item.WhenReady(
                            a =>
                            {
                                Console.WriteLine("enter WhenReady");

                                s.style.color = JSColor.System.WindowText;

                                Console.WriteLine("before GetTypes ToArray");
                                var TypesArray = a.GetTypes().ToArray();


                                //Console.WriteLine("before TypesByName");

                                //var TypesByName = TypesArray.OrderBy(k => k.Name);

                                //Console.WriteLine("before TypesByName ToArray");
                                //// chokes on android?
                                //var TypesByNameArray = TypesByName.ToArray();

                                //Console.WriteLine("before ForEach");

                                TypesArray.ForEach(
                                    (Current, Index, Next) =>
                                    {
                                        Console.WriteLine("AddType");

                                        if (!Current.IsNested)
                                        {
                                            AddType(
                                                GetNamespaceContainer(children, Current),
                                                Current,
                                                UpdateLocation
                                            );

                                            AddType(
                                                AllTypes(Current.Namespace),
                                                Current,
                                                UpdateLocation
                                            );
                                        }


                                        if (Index % 8 == 0)
                                        {
                                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                                7,
                                                Next
                                            );
                                        }
                                        else
                                        {
                                            Next();
                                        }
                                    }
                                )(done_);

                                Console.WriteLine("exit WhenReady");

                            }
                        );
                    };

                Console.WriteLine("before YieldLoadAction");
                YieldLoadAction(LoadAction);
                Console.WriteLine("after YieldLoadAction");


                var NextClickHide = default(Action);
                var NextClickShow = default(Action);

                NextClickHide =
                    delegate
                    {
                        children.Hide();

                        onclick = NextClickShow;
                    };

                NextClickShow =
                    delegate
                    {
                        children.Show();

                        onclick = NextClickHide;
                    };


                NextClickHide();
            }
        }