public static IHTMLDiv ConvertToImageReflection(ReflectionSetup rs)
        {
            var Control = new IHTMLDiv();

            Control.style.SetLocation(rs.Position.X, rs.Position.Y, +rs.Size.X, +rs.Size.Y);

            rs.Image.style.SetLocation(0, 0, rs.Size.X, rs.Size.Y);
            rs.Image.AttachTo(Control);

            #region drag

            if (rs.Drag)
            {
                rs.Image.onmousedown += Native.DisabledEventHandler;
                rs.Image.style.cursor = ScriptCoreLib.JavaScript.DOM.IStyle.CursorEnum.move;

                var drag = new DragHelper(rs.Image);

                drag.Enabled   = true;
                drag.Position  = rs.Position;
                drag.DragMove +=
                    delegate
                {
                    Control.style.SetLocation(drag.Position.X, drag.Position.Y);
                };
            }

            #endregion

            #region GetRect
            Func <int, int, int, int, string> GetRect =
                (left, top, width, height) =>
            {
                // rect (top, right, bottom, left)
                var x = string.Format("rect({0}px, {1}px, {2}px, {3}px)", top, width + left, height + top, left);
                return(x);
            };
            #endregion


            #region CopyLineY
            Action <ReflectionFrameInfo> CopyLineY =
                i =>
            {
                var clone = (IHTMLImage)rs.Image.cloneNode(true);

                clone.style.SetLocation(0, i.Offset + i.To, rs.Size.X, i.Size);
                clone.style.clip    = GetRect(0, i.From, rs.Size.X, 1);
                clone.style.Opacity = i.Opacity;
                clone.AttachTo(i.Owner);
            };
            #endregion



            #region y
            var YMax = (rs.Size.Y * rs.ReflectionZoom).ToInt32();

            if (rs.Bottom >= 0)
            {
                var _bottom = new IHTMLDiv();
                _bottom.style.SetLocation(0, rs.Size.Y - 1 + rs.Bottom, rs.Size.X, YMax);
                _bottom.AttachTo(Control);
                _bottom.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int y = 0; y < YMax; y++)
                {
                    CopyLineY(
                        new ReflectionFrameInfo
                    {
                        From    = y,
                        To      = YMax - y * 2,
                        Opacity = y / YMax,
                        Size    = YMax,
                        Offset  = 0,
                        Owner   = _bottom
                    }
                        );
                }
            }

            if (rs.Top >= 0)
            {
                var _top = new IHTMLDiv();
                _top.style.SetLocation(0, -YMax - rs.Top, rs.Size.X, YMax);
                _top.AttachTo(Control);
                _top.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;


                for (int y = 0; y < YMax; y++)
                {
                    CopyLineY(
                        new ReflectionFrameInfo
                    {
                        From    = y,
                        To      = YMax - y * 2,
                        Opacity = (1 - (y / (YMax))),
                        Size    = YMax,
                        Offset  = 0,
                        Owner   = _top
                    }
                        );
                }
            }
            #endregion

            var XMax = (rs.Size.X * rs.ReflectionZoom).ToInt32();



            #region CopyLineX
            Action <ReflectionFrameInfo> CopyLineX =
                i =>
            {
                var clone = (IHTMLImage)rs.Image.cloneNode(true);

                clone.style.SetLocation(i.Offset + i.To, 0, i.Size, rs.Size.Y);
                clone.style.clip    = GetRect(i.From, 0, 1, rs.Size.Y);
                clone.style.Opacity = i.Opacity;


                clone.AttachTo(i.Owner);
            };
            #endregion

            #region x

            if (rs.Right >= 0)
            {
                var _right = new IHTMLDiv();
                _right.style.SetLocation(rs.Size.X - 1 + rs.Right, 0, XMax, rs.Size.Y);
                _right.AttachTo(Control);
                _right.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int x = 0; x < XMax; x++)
                {
                    CopyLineX(
                        new ReflectionFrameInfo
                    {
                        From    = x,
                        To      = XMax - x * 2,
                        Opacity = (x / (XMax)),
                        Size    = XMax,
                        Offset  = 0,
                        Owner   = _right
                    }
                        );
                }
            }

            if (rs.Left >= 0)
            {
                var _left = new IHTMLDiv();
                _left.style.SetLocation(-XMax - rs.Left, 0, XMax, rs.Size.Y);
                _left.AttachTo(Control);
                _left.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int x = 0; x < XMax; x++)
                {
                    CopyLineX(
                        new ReflectionFrameInfo
                    {
                        From    = x,
                        To      = XMax - x * 2,
                        Opacity = (1 - (x / (XMax))),
                        Size    = XMax,
                        Offset  = 0,
                        Owner   = _left
                    }
                        );
                }
            }
            #endregion

            return(Control);
        }
        public MyImageReflection()
        {
            Native.Document.body.style.background = "url(" + Assets.Path + "/bg.jpg)";
            Native.Document.body.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

            new IHTMLImage(Assets.Path + "/pt-tokyotaxiorange-01t.png").InvokeOnComplete(
                img =>
                {
                    var Size = new Point(img.width, img.height);
                    var Position = new Point(
                        32 + Size.X,
                        32 + Size.Y
                        );


                    var Control =
                        new ReflectionSetup
                        {
                            Image = img,
                            Right = 2,
                            Left = 2,
                            Top = 2,
                            Bottom = 2,
                            Position = Position,
                            Size = Size,
                            ReflectionZoom = 1.0,
                            
                        }.ConvertToImageReflection();

                    Control.AttachToDocument();
                }
            );

            new IHTMLImage(Assets.Path + "/old-Preview.png").InvokeOnComplete(
                img =>
                {
                    var Size = new Point(img.width, img.height);
                    var ReflectionZoom = 1.0;
                    var Position = new Point(
                        Native.Window.Width - (Size.X + Size.X * ReflectionZoom * 2).ToInt32(),
                        Native.Window.Height - (Size.X + Size.Y * ReflectionZoom * 2).ToInt32()
                        );


                    var Control =
                         new ReflectionSetup
                         {
                             Image = img,
                             Position = Position,
                             Size = Size,
                             ReflectionZoom = 0.5,

                             Bottom = 2
                         }.ConvertToImageReflection();
                    Control.AttachToDocument();
                }
            );

            new IHTMLImage(Assets.Path + "/Preview.png").InvokeOnComplete(
                img =>
                {
                    var Size = new Point(img.width, img.height);
                    var ReflectionZoom = 1.0;
                    var Position = new Point(
                        (Size.X * ReflectionZoom * 2).ToInt32(),
                        Native.Window.Height - (Size.X + Size.Y * ReflectionZoom * 2).ToInt32()
                        );

                    
                    var Control = 
                         new ReflectionSetup
                         {
                             Image = img,
                             Position = Position,
                             Size = Size,
                             ReflectionZoom = 0.5,

                             Bottom = 2
                         }.ConvertToImageReflection();

                    Control.AttachToDocument();
                }
            );
        }
        public static IHTMLDiv ConvertToImageReflection(ReflectionSetup rs)
        {

            var Control = new IHTMLDiv();

            Control.style.SetLocation(rs.Position.X, rs.Position.Y, +rs.Size.X, +rs.Size.Y);

            rs.Image.style.SetLocation(0, 0, rs.Size.X, rs.Size.Y);
            rs.Image.AttachTo(Control);

            #region drag

            if (rs.Drag)
            {
                rs.Image.onmousedown += Native.DisabledEventHandler;
                rs.Image.style.cursor = ScriptCoreLib.JavaScript.DOM.IStyle.CursorEnum.move;

                var drag = new DragHelper(rs.Image);

                drag.Enabled = true;
                drag.Position = rs.Position;
                drag.DragMove +=
                    delegate
                    {
                        Control.style.SetLocation(drag.Position.X, drag.Position.Y);
                    };


            }

            #endregion

            #region GetRect
            Func<int, int, int, int, string> GetRect =
                (left, top, width, height) =>
                {
                    // rect (top, right, bottom, left)
                    var x = string.Format("rect({0}px, {1}px, {2}px, {3}px)", top, width + left, height + top, left);
                    return x;
                };
            #endregion


            #region CopyLineY
            Action<ReflectionFrameInfo> CopyLineY =
                i =>
                {
                    var clone = (IHTMLImage)rs.Image.cloneNode(true);

                    clone.style.SetLocation(0, i.Offset + i.To, rs.Size.X, i.Size);
                    clone.style.clip = GetRect(0, i.From, rs.Size.X, 1);
                    clone.style.Opacity = i.Opacity;
                    clone.AttachTo(i.Owner);
                };
            #endregion



            #region y
            var YMax = (rs.Size.Y * rs.ReflectionZoom).ToInt32();

            if (rs.Bottom >= 0)
            {
                var _bottom = new IHTMLDiv();
                _bottom.style.SetLocation(0, rs.Size.Y - 1 + rs.Bottom, rs.Size.X, YMax);
                _bottom.AttachTo(Control);
                _bottom.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int y = 0; y < YMax; y++)
                {
                    CopyLineY(
                        new ReflectionFrameInfo
                        {
                            From = y,
                            To = YMax - y * 2,
                            Opacity = y / YMax,
                            Size = YMax,
                            Offset = 0,
                            Owner = _bottom
                        }
                    );
                }
            }

            if (rs.Top >= 0)
            {
                var _top = new IHTMLDiv();
                _top.style.SetLocation(0, -YMax - rs.Top, rs.Size.X, YMax);
                _top.AttachTo(Control);
                _top.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;


                for (int y = 0; y < YMax; y++)
                {
                    CopyLineY(
                        new ReflectionFrameInfo
                        {
                            From = y,
                            To = YMax - y * 2,
                            Opacity = (1 - (y / (YMax))),
                            Size = YMax,
                            Offset = 0,
                            Owner = _top
                        }
                    );
                }
            }
            #endregion

            var XMax = (rs.Size.X * rs.ReflectionZoom).ToInt32();




            #region CopyLineX
            Action<ReflectionFrameInfo> CopyLineX =
                i =>
                {
                    var clone = (IHTMLImage)rs.Image.cloneNode(true);

                    clone.style.SetLocation(i.Offset + i.To, 0, i.Size, rs.Size.Y);
                    clone.style.clip = GetRect(i.From, 0, 1, rs.Size.Y);
                    clone.style.Opacity = i.Opacity;


                    clone.AttachTo(i.Owner);
                };
            #endregion

            #region x

            if (rs.Right >= 0)
            {
                var _right = new IHTMLDiv();
                _right.style.SetLocation(rs.Size.X - 1 + rs.Right, 0, XMax, rs.Size.Y);
                _right.AttachTo(Control);
                _right.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int x = 0; x < XMax; x++)
                {
                    CopyLineX(
                          new ReflectionFrameInfo
                          {
                              From = x,
                              To = XMax - x * 2,
                              Opacity = (x / (XMax)),
                              Size = XMax,
                              Offset = 0,
                              Owner = _right
                          }
                      );
                }
            }

            if (rs.Left >= 0)
            {
                var _left = new IHTMLDiv();
                _left.style.SetLocation(-XMax - rs.Left, 0, XMax, rs.Size.Y);
                _left.AttachTo(Control);
                _left.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int x = 0; x < XMax; x++)
                {
                    CopyLineX(
                          new ReflectionFrameInfo
                          {
                              From = x,
                              To = XMax - x * 2,
                              Opacity = (1 - (x / (XMax))),
                              Size = XMax,
                              Offset = 0,
                              Owner = _left
                          }
                      );
                }
            }
            #endregion

            return Control;
        }
        public ExampleGalleryWithReflections()
        {

            Native.Document.body.style.Aggregate(
               style =>
               {
                   style.backgroundColor = Color.Gray;
                   style.backgroundImage = "url(assets/ExampleGallery/bg.png)";

                   style.color = Color.White;
               }
           );

            try
            {
                IStyleSheet.Default.AddRule("a.Preview img.PreviewShadow").style.display = IStyle.DisplayEnum.none;
                IStyleSheet.Default.AddRule("a.Preview:hover img.PreviewShadow").style.display = IStyle.DisplayEnum.block;
            }
            catch
            {
                // no css support
            }

            var Menu = new IHTMLDiv().AttachToDocument();
            var Title = typeof(ExampleGalleryWithReflections).Name;

            new IHTMLElement(IHTMLElement.HTMLElementEnum.h1,
                Title).AttachTo(Menu);

            Native.Document.title = Title;

            new IHTMLImage("assets/ExampleGallery/PreviewSelection.png").InvokeOnComplete(
            selection =>
                {
                    base.Initialize(Menu,
                        (image, href, type, TypeClicked) =>
                        {
                            var div =
                                new ReflectionSetup
                                {
                                    Image = image,
                                    Position = new Point(0, 0),
                                    Size = new Point(120, 90),
                                    ReflectionZoom = 0.5,
                                    Drag = false,
                                    Bottom = 2
                                }.ConvertToImageReflection();

                            div.style.position = IStyle.PositionEnum.relative;
                            div.style.marginTop = "3em";
                            div.style.marginLeft = "1em";
                            div.style.marginRight = "1em";
                            div.style.marginBottom = "3em";
                            div.style.Float = IStyle.FloatEnum.left;

                            #region name
                            var name = new IHTMLAnchor(href, type.Name);

                            name.style.position = IStyle.PositionEnum.absolute;
                            name.style.textDecoration = "none";
                            name.style.color = Color.White;
                            name.className = "PreviewName";

                            name.target = "_blank";
                            name.style.top = "-1.5em";
                            name.AttachTo(div);
                            #endregion

                            var a = new IHTMLAnchor(href, "");

                            var cselection = (IHTMLImage)selection.cloneNode(false);
                            cselection.style.borderWidth = "0px";
                            cselection.style.SetLocation(-9, -9);
                            cselection.style.zIndex = 1;
                            cselection.className = "PreviewShadow";
                            cselection.AttachTo(a);

                            a.className = "Preview";
                            a.target = "_blank";
                            image.style.border = "0px solid black";
                            image.AttachTo(a);
                            image.style.zIndex = 2;
                            a.AttachTo(div);
                            a.style.zIndex = 2;
                            a.style.SetLocation(0, 0);

                            a.onclick +=
                                ev =>
                                {
                                    ev.PreventDefault();

                                    TypeClicked(type);
                                };

                            return div;
                        });
                    }
             );
        }