/// <summary>
    /// Prepares the layout of the web part.
    /// </summary>
    protected override void PrepareLayout()
    {
        StartLayout();

        if (IsDesign)
        {
            Append("<table class=\"LayoutTable\" cellspacing=\"0\" style=\"width: 100%;\">");

            if (ViewModeIsDesign())
            {
                Append("<tr><td class=\"LayoutHeader\">");

                // Add header container
                AddHeaderContainer();

                Append("</td></tr>");
            }

            Append("<tr><td>");
        }

        // Content before zones
        Append(BeforeZones);

        string separator = Separator;
        string before    = BeforeZone;
        string after     = AfterZone;

        string zoneclass = ZoneCSSClass;
        string zonewidth = ZoneWidth;

        // Render the zones
        for (int i = 1; i <= Zones; i++)
        {
            if (i > 1)
            {
                Append(separator);
            }
            Append("<div");

            // Zone class
            if (!String.IsNullOrEmpty(zoneclass))
            {
                Append(" class=\"", zoneclass, "\"");
            }

            // Zone width
            if (!String.IsNullOrEmpty(zonewidth))
            {
                Append(" style=\"width: ", zonewidth, "\";");
            }

            Append(">", before);

            // Add the zone
            CMSWebPartZone zone = AddZone(ID + "_" + i, "[" + i + "]");

            Append(after, "</div>");
        }

        // Content after zones
        Append(AfterZones);

        if (IsDesign)
        {
            Append("</td></tr>");

            // Footer
            if (AllowDesignMode)
            {
                Append("<tr><td class=\"LayoutFooter cms-bootstrap\" colspan=\"2\"><div class=\"LayoutFooterContent\">");

                // Zone actions
                AppendRemoveAction(ResHelper.GetString("Layout.RemoveZone"), "Zones");
                Append("&nbsp;&nbsp;");
                AppendAddAction(ResHelper.GetString("Layout.AddZone"), "Zones");

                Append("</div></td></tr>");
            }

            Append("</table>");
        }

        // Register scripts
        string[] scripts = ScriptFiles.Split('\r', '\n');
        foreach (string script in scripts)
        {
            // Register the script file
            string sfile = script.Trim();
            if (!String.IsNullOrEmpty(sfile))
            {
                ScriptHelper.RegisterScriptFile(Page, sfile);
            }
        }

        // Add init script
        string resolvedInitScript = MacroResolver.Resolve(InitScript);

        if (!string.IsNullOrEmpty(resolvedInitScript))
        {
            ScriptHelper.RegisterStartupScript(this, typeof(string), ShortClientID + "_Init", ScriptHelper.GetScript(resolvedInitScript));
        }

        // Register CSS files
        string[] cssFiles = CSSFiles.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
        Array.ForEach(cssFiles, cssFile => CssRegistration.RegisterCssLink(Page, cssFile.Trim()));

        // Add inline CSS
        string inlinecss = MacroResolver.Resolve(InlineCSS);

        if (!string.IsNullOrEmpty(inlinecss))
        {
            // Add css to page header
            CssRegistration.RegisterCssBlock(Page, "zonesWithEffectInlineCss_" + ClientID, inlinecss);
        }

        FinishLayout();
    }