protected void MiniSummaryRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblCategory = e.Item.FindControl("lblCategory") as Label;
                if (lblCategory != null)
                {
                    int         pageId         = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "PageId"));
                    WebpageInfo parentPageInfo = Webpage.GetWebpageByPageId(pageId);
                    if (parentPageInfo != null)
                    {
                        lblCategory.Text = parentPageInfo.Parent.Text + ":  ";
                    }

                    HyperLink hypTitle = e.Item.FindControl("hypTitle") as HyperLink;
                    if (hypTitle != null)
                    {
                        hypTitle.NavigateUrl = DataBinder.Eval(e.Item.DataItem, "Path").ToString();

                        string scriptStr = "autoEllipseText('" + hypTitle.ClientID + "', \""
                                           + (DataBinder.Eval(e.Item.DataItem, "NavigationText")).ToString().Replace("\"", """) + "\", '"
                                           + lblCategory.ClientID + "');";
                        Page.ClientScript.RegisterStartupScript(GetType(), "truncate" + e.Item.ItemIndex, scriptStr, true);
                    }
                }

                // TODO: Cache this info
                int moduleId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ModuleId"));
                MasterDetailItem               item               = MasterDetailItem.GetSafeResource(moduleId);
                MasterDetailSetting            setting            = item.GetContentList();
                MasterDetailMiniSummarySetting miniSummarySetting = MasterDetailMiniSummarySetting.FetchByID(this.ModuleId);

                Label lblCommentCount = e.Item.FindControl("lblCommentCount") as Label;
                if (lblCommentCount != null)
                {
                    if ((setting != null) && (setting.AllowComments))
                    {
                        int numComments =
                            MasterDetailComment.Query().WHERE(MasterDetailComment.Columns.ModuleId, moduleId).GetCount(
                                MasterDetailComment.Columns.ModuleId);
                        if (numComments > 999)
                        {
                            numComments = 999;                    // max display size is 3 digits.
                        }
                        lblCommentCount.Text    = numComments.ToString();
                        lblCommentCount.ToolTip = numComments + " Reader Comments";
                    }
                    else
                    {
                        lblCommentCount.Visible = false;
                    }
                }

                Label lblTimestamp = e.Item.FindControl("lblTimestamp") as Label;
                if (lblTimestamp != null)
                {
                    if ((miniSummarySetting != null) && ((bool)miniSummarySetting.ShowElapsedTime))
                    {
                        DateTime postDate = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "PostDate"));
                        TimeSpan ts       = DateTime.Now.Subtract(postDate);
                        if (ts.Days > 0)
                        {
                            lblTimestamp.Text = ts.Days + "d ago";
                        }
                        else if (ts.Hours > 0)
                        {
                            lblTimestamp.Text = ts.Hours + "h ago";
                        }
                        else if (ts.Minutes > 0)
                        {
                            lblTimestamp.Text = ts.Minutes + "m ago";
                        }
                        else
                        {
                            lblTimestamp.Text = "< 1m ago";
                        }
                    }
                    else
                    {
                        lblTimestamp.Visible = false;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HtmlLink cssLink = new HtmlLink();

            cssLink.Href = "~/WebModules/MasterDetail/public/css/MasterDetail.css";
            cssLink.Attributes["rel"]  = "stylesheet";
            cssLink.Attributes["type"] = "text/css";
            this.Page.Header.Controls.AddAt(1, cssLink);

            // AntiSpam session var
            Session.Add("AntiSpamVar", "0");

            if (!IsPostBack)
            {
                WebpageInfo         page     = this.WebModuleInfo.Webpage;
                MasterDetailItem    item     = MasterDetailItem.GetSafeResource(this.ModuleId);
                MasterDetailSetting itemList = item.GetContentList();

                CurrentModuleId = item.ModuleId;

                if (itemList != null)
                {
                    lblPostDate.Visible   = itemList.IsPostDateVisible;
                    CommentsPanel.Visible = itemList.AllowComments;

                    if (itemList.AllowComments)
                    {
                        Query q = MasterDetailComment.Query().WHERE(MasterDetailComment.Columns.ModuleId, CurrentModuleId);
                        litCommentsLink.Text = "&nbsp;&nbsp;|&nbsp;&nbsp;<a href='#Comments'>" + q.GetCount(MasterDetailComment.Columns.Id) + " Comment(s)</a>";
                    }
                    if (Page.User.Identity.IsAuthenticated || !itemList.RequireAuthentication)
                    {
                        submitCommentsDiv.Visible = true;
                        lblLoginMsg.Visible       = false;
                    }
                    else
                    {
                        submitCommentsDiv.Visible = false;
                        lblLoginMsg.Visible       = true;
                    }
                }

                if (lblPostDate.Visible)
                {
                    if (page.PostDate.HasValue)
                    {
                        lblPostDate.Text = page.PostDate.Value.ToLongDateString();
                    }
                }

                if (string.IsNullOrEmpty(item.ImagePath))
                {
                    img.Visible = false;
                }
                else
                {
                    img.ImageUrl = ResolveUrl(item.ImagePath);
                }

                litTitle.Text       = page.Text;
                litBody.Text        = item.LongDescription;
                hypBack.NavigateUrl = this.WebModuleInfo.Webpage.Parent.Path;

                CommentsListRepeater.DataSource = new MasterDetailCommentCollection()
                                                  .Where(MasterDetailComment.Columns.ModuleId, CurrentModuleId)
                                                  .OrderByDesc(MasterDetailComment.Columns.CreatedOn)
                                                  .Load();
                CommentsListRepeater.DataBind();
            }
        }