# -*-s2-*-

layerinfo type = "layout";
layerinfo name = "Punquin Elegant";
layerinfo redist_uniq = "punquin/layout";
layerinfo previews = "punquin/punquin.jpg";

# Colors
propgroup colors {
  property Color body_bgcolor { 
      des = "Page background color";
      s1color = "stronger_accent";
  }
  property Color main_bgcolor {
      des = "Background of text areas";
      s1color = "page_back";
  }
  property Color main_fgcolor {
      des = "Text color";
      s1color = "page_text";
  }
  property Color subject_color { 
      des = "Color of entry subjects";
      s1color = "page_text_em";
  }
  property Color title_color { 
      des = "Color of headers and titles";
      s1color = "page_text_title";
  }
  property Color border_color { 
      des = "Color of borders";
      s1color = "weak_back";
  }
  property Color link_color {
      des = "Link color";
      s1color = "page_link";
  }
  property Color vlink_color {
      des = "Visited link color";
      s1color = "page_vlink"; 
  }
  property Color alink_color { 
      des = "Active link color";
      s1color = "page_alink";
  }
  property Color comment_bar_one_bgcolor {
      des = "Alternating background color for comment bars (one)";
  }
  property Color comment_bar_two_fgcolor {
      des = "Text color on alternating comment bars (one)";
  }
  property Color comment_bar_two_bgcolor {
      des = "Alternating background color for comment bars (two)";
  }
  property Color comment_bar_one_fgcolor {
      des = "Text color on alternating comment bars (two)";
  }
  property Color comment_bar_screened_bgcolor {
      des = "Background bar color for screened comments";
  }
  property Color comment_bar_screened_fgcolor {
      des = "Text color on background bar for screened comments";
  }
}
set body_bgcolor = "#6666cc";
set main_bgcolor = "#ffffff";
set main_fgcolor = "#000000";
set subject_color = "#c00000";
set title_color = "#8b1a1a";
set border_color = "#eeeeff";
set link_color = "#000050";
set vlink_color = "#500050";
set alink_color = "#ff00c0";
set comment_bar_one_bgcolor = "#c0c0ff";
set comment_bar_one_fgcolor = "#000000";
set comment_bar_two_bgcolor = "#eeeeff";
set comment_bar_two_fgcolor = "#000000";
set comment_bar_screened_bgcolor = "#dddddd";
set comment_bar_screened_fgcolor = "#000000";

propgroup presentation {
  property bool show_recent_userpic {
      des = "Show the userpic on the recent entries page?"; 
  }
  property string sidebar_position {
      des = "Position of the sidebar relative to the main content";
      values = "left|Left|right|Right";
  }
  property use font_base;
  property use font_fallback;
  property use page_recent_items;
  property use page_friends_items;
  property use use_shared_pic;
  property use view_entry_disabled;
  property bool show_entrynav_icons {
    des = "Toggle to show the next, memory, edit, etc icons on the entry view page";
  }
  property string page_background_image {
      des = "URL to an image to be used for the page background";
  }
  property use linklist_support;
  property use external_stylesheet;
}
set font_base = "Verdana, Arial, Helvetica";
set font_fallback = "sans-serif";
set show_recent_userpic = false;
set sidebar_position = "left";
set page_recent_items = 20;
set page_friends_items = 20;
set view_entry_disabled = false;
set show_entrynav_icons = true;
set page_background_image = "";
set linklist_support = false;

propgroup text {
  property string text_gotop {
      des = "Link text to 'top of the page'";
      noui = 1;
  }
  property use text_post_comment;
  property use text_read_comments;
  property use text_post_comment_friends;
  property use text_read_comments_friends;
  property use text_website_default_name;
}
set text_gotop = "Go to Top";
set tags_aware = true;

function print_stylesheet ()
{
    var string font = "$*font_base, $*font_fallback";
    print clean_url($*page_background_image) != "" ? "body { background-image: url($*page_background_image); }" : "";
    print """
body {
    background-color:  $*body_bgcolor;
    color:             $*main_fgcolor;
    font:              normal normal 10pt $font;
}
a {
    text-decoration:   none;
    color:             $*link_color;
    background:        transparent;
    font:              normal normal 10pt $font;
}
a:visited {
    color:             $*vlink_color;
    background:        transparent;
}
a:active {
    color:             $*alink_color;
    background:        transparent;
}
#title {
    font:              normal bold 10pt $font;
    color:             $*title_color;
    text-align:        center;
}
.date {
    font:              normal bold 12pt $font;
    color:             $*title_color;
    text-align:        right;
}
.comments {
    font:              normal normal 8pt $font;
}
hr.separator {
    color:             $*border_color;
}
.siteplug {
    font:              normal normal 8pt $font;
}
#yearheader {
    text-align:        right;
    color:             $*title_color;
    font:              normal bold 12pt $font;
}
th.monthheader {
    color:             $*title_color;
}
th.daysheader {
    color:             $*subject_color;
}

/* Tables. Fun. */

table#main {
    border:            solid 0px $*body_bgcolor;
}
table.standard {
    border:            solid 5px $*border_color;
    background-color:  $*main_bgcolor;
    color:             $*main_fgcolor;
    font:              normal normal 10pt $font;
}
table.standard>td {
    background-color:  $*main_bgcolor;
    color:             $*main_fgcolor;
}
table.standard td {
    font:              normal normal 10pt $font;
}
    """;
}


function Page::lay_sidebar_navigation () { }

function print_sidebar(Page p) {
    var string title = $p->title();
    var string userpic;
    var Image up_img = $p.journal.default_pic;
    if (defined $up_img) {
        $userpic = """<p align="center"><img border="0" src="$up_img.url" height="$up_img.height" width="$up_img.width" alt="" /></p>""";
    }

    var string website_name = $p.journal.website_name ? $p.journal.website_name : $*text_website_default_name;
    var string website;
    if ($p.journal.website_url != "") {
        $website = """&gt; <a href="$p.journal.website_url">$website_name</a><br />""";
    }

    var string links;
    foreach var string v ($p.views_order) {
        $links = "$links&gt; " + ($p.view == $v ?
                           lang_viewname($v) :
                           "<a href='$p.view_url{$v}'>"+lang_viewname($v)+"</a>") + "<br />\n";
    }

    # Table Wrapper
    "<!-- Begin Main Sidebar -->\n<td valign='top' align='$*sidebar_position'>";
    "<table width='150' class='standard' cellpadding='5' cellspacing='0'>\n";
    "<tr valign='top'><td align='left'>";

    # Title
    "<div style='text-align:center'><span style='color: $*title_color'><strong>$title</strong></span></div>\n";

    # Links
    "<p>$links\n$website\n";
    $p->lay_sidebar_navigation();

    # Userpic
    "</p>"; if($userpic != "") { "<div style='text-align:center'>$userpic</div>"; }

    # Link List
    if (size $p.linklist > 0 and $*linklist_support) {
        if (not $p.linklist[0].is_heading) {
            "<b>Links</b><br />";
        }
        $p->print_linklist();
    }

    # End Table
    "</td></tr></table>\n<!-- End Main Sidebar -->";
}

function print_gotop (Page p)
{
    "<td valign='bottom' align='$*sidebar_position'>\n<!-- Begin Small Sidebar -->\n";
    "<table width='150' class='standard' cellpadding='5' cellspacing='0'>\n";
    "<tr valign='top'><td align='left'>\n";
    $p->lay_sidebar_navigation();
    "<br />&gt; <a href='#top'>$*text_gotop</a><br>\n</td></tr></table>\n<!-- End Small Sidebar -->";
}

function Page::print () 
{
    var string title = $this->title();
    var string main_position = $*sidebar_position == "left" ? "right" : "left"; 

    # Head
    println "<html><head>";

    if ($*external_stylesheet) {
        println """<link rel="stylesheet" href="$.stylesheet_url" type="text/css" />""";
    } else {
        println """<style type="text/css">"""; print_stylesheet(); "</style>";
    }
    $this->print_head();

    "<title>$title</title>\n</head>\n";

    # Body
    "<body>\n<a name='top'></a><div align='center'>\n";

    # Table wrapper
    "<table id='main' cellpadding='5' cellspacing='0' width='90%'>\n<tr>";

    if ($*sidebar_position == "left") { print_sidebar($this); }

    # Main content
    "<td valign='top' align='$main_position' rowspan='2'>\n<!-- Begin Main -->\n";
    "<table class='standard' width='100%' height='90%' cellpadding='5' cellspacing='0'><tr valign='top'><td>\n";
    $this->print_body();
    "</td></tr></table>\n<!-- End Main -->\n</td>";

    if ($*sidebar_position == "right") { print_sidebar($this); }

    # Go to top
    "</tr><tr>";
    print_gotop($this);
    "</tr><tr>";

    # Plug the site!
    "<td colspan='2' align='$main_position'>\n";
    "<a href='$*SITEROOT/'>$*SITENAME</a></td>\n";

    "</tr></table></div></body></html>";
}

function print_entry (Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text)
{
    var string time = $e.time->time_format();
    if ($e.new_day or $p.view == "entry") {
        "<p class='date'>"; print $e.time->date_format("%%month%% %%dayord%%, %%yyyy%%"); "</p>";
        "<hr class='separator' />";
    }

    if ($p.view == "entry" and $*show_entrynav_icons)
    {
        print "<div style='text-align: center'>";
        $e->print_linkbar();
        print "</div>";
    }

    "<table border='0' cellpadding='2' cellspacing='0'><tr>";

    if ($p.view == "friends" or
        $e.poster.username != $e.journal.username or
        $*show_recent_userpic == true)
    {
        # Lots of muddled logic. Yay.

        """<td valign=top align="middle" style="background-color: $bgcolor" width="100">""";
        if ($p.view == "friends") { 
            """<a href='""" + $e.journal->base_url() + """/' style="color: $fgcolor; font-weight: bold">$e.journal.username</a><br />""";
        }
        if ($e.poster.username != $e.journal.username) {
            if ($p.view == "friends") { 
                """[<a href='""" + $e.poster->base_url() + """/' style="color: $fgcolor">$e.poster.username</a>]<br />""";
            } else {
                """<a href='""" +  $e.poster->base_url() + """/' style="color: $fgcolor; font-weight: bold">$e.poster.username</a><br />""";
            }
        }
        if (defined $e.userpic) {
            if (($*show_recent_userpic == false) and 
	        ($p.view != "friends") and
		($p.journal_type != "C") ) { }
            else { """<img border="0" src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="" />""";
            }
        }
        "</td>";
    }
    "<td valign='top'><strong>$time";
    if ($e.subject) { " - <span style='color: $*subject_color'>$e.subject</span>"; }

    if ($e.security) {
        " "; $e.security_icon->print();
    }
    "</strong><br />";
    if (not $hide_text) {
        print $e.text; "<br />";
        if (size $e.metadata) {
            foreach var string k ($e.metadata) {
                var string key = $k;
                var string val = $e.metadata{$k};
                if ($k == "mood") {
                    $key = $*text_meta_mood;
                } elseif ( $k == "music" ) {
	            $key = $*text_meta_music;
	        }
                if ($k == "mood" and defined $e.mood_icon) {
                    var Image i = $e.mood_icon;
                    $val = "<img src='$i.url' width='$i.width' height='$i.height' align='absmiddle' alt='[mood icon]' /> $val";
                }
                "<strong>$key:</strong> $val<br />";
            }
        }
        if ($e.tags) {
            var int tcount = 0;
            "<div class='ljtags'><strong>Tags:</strong> ";
            foreach var Tag t ($e.tags) {
                """<a rel="tag" href="$t.url">$t.name</a>""";
                $tcount++;
                if ($tcount != size $e.tags) { ", "; }
            }
            "</div>";
        }
    }
    "</td></tr></table>";
    $e.comments->print(); 
}

function Page::print_entry (Entry e) 
{
    print_entry($this, $e, null Color, null Color, false);
}

function FriendsPage::print_entry (Entry e) {
    var Friend f = $.friends{$e.journal.username};
    print_entry($this, $e, $f.bgcolor, $f.fgcolor, false);
}

function RecentPage::print_body {
    foreach var Entry e ($.entries) {
        $this->print_entry($e);
    }
}

function FriendsPage::print_body {
    foreach var Entry e ($.entries) {
        $this->print_entry($e);
    }
}


function RecentPage::lay_sidebar_navigation () {
    var int total = size $.entries;
    var string nav = "";
    if ($.nav.backward_url != "") {
        $nav = """&gt; <a href="$.nav.backward_url">previous $total entries</a>""";
    }
    if ($.nav.forward_url != "" and $.nav.backward_url != "") {
        $nav = "$nav<br />";
    }
    if ($.nav.forward_url != "") {
        $nav = """${nav}&gt; <a href="$.nav.forward_url">next $total entries</a>""";
    }
    print $nav;
}

function CommentInfo::print ()
{
    if (not $.enabled) {
        "<p align='right' class='comments'>&nbsp;</p>";
        return;
    }
    "<p align='right' class='comments'>(";
    if ($.count > 0 or $.screened) {
        $this->print_readlink();
        "&nbsp;|&nbsp;";
    }
    $this->print_postlink();
    ")</p>";
}

function YearPage::print_body {
    "<p id='yearheader'>$.year</p>\n";
    foreach var YearMonth m ($.months) {
        $this->print_month($m);
    }
}

function YearPage::print_year_links ()
{
    foreach var YearYear y ($.years) {
        if ($y.displayed) {
            "&gt; $y.year<br />";
        } else {
            "&gt; <a href=\"$y.url\">$y.year</a><br />";
        }
    }
}

function YearPage::lay_sidebar_navigation () 
{
    $this->print_year_links();
}

function YearPage::print_month(YearMonth m)
{
    if (not $m.has_entries) { return; }
    # Table Wrapper
    "<center><p><table border='1' cellpadding='4' width='80%'>\n";

    # Month Header
    "<tr align='center'><th colspan='7' class='monthheader'>\n";
    print $m->month_format();
    "</th></tr>\n";

    # Weekdays Header
    "<tr align='center'>\n";
    foreach var int d (weekdays()) {
        "<th class='daysheader'>"+$*lang_dayname_short[$d]+"</th>\n";
    }
    "</tr>\n";

    # Weeks
    foreach var YearWeek w ($m.weeks) {
        $w->print();
    }

    # Footer
    "<tr><td colspan='7'><div style='text-align: center'><a href='$m.url'>view subjects</a></div></td></tr>\n";

    # End Table
    "</table></p></center>\n";
}

function YearWeek::print () {
    "<tr>";
    if ($.pre_empty) { "<td colspan='$.pre_empty'>&nbsp;</td>"; }
    foreach var YearDay d ($.days) {
        "<td valign='top'><strong>$d.day</strong><div style='text-align: center'>";
        if ($d.num_entries) {
            "<a href='$d.url'>$d.num_entries</a>";
        } else {
            "&nbsp;";
        }
        "</div></td>\n";
    }
    if ($.post_empty) { "<td colspan='$.post_empty'>&nbsp;</td>"; }
    "</tr>";
}

function DayPage::print_body() {
    if (not $.has_entries) {
        "<table width='100%'><tr><td><p class='date'>\n";
        print $.date->date_format("%%month%% %%dayord%%, %%yyyy%%");
        "</p><hr class='separator' width='100%' /></td></tr>";
        "<tr><td><blockquote align='center'>"; print ehtml($*text_noentries_day); "</blockquote></td></tr></table>";
    } else {
        foreach var Entry e ($.entries) {
            $this->print_entry($e);
        }
    }

    var string tprev = ehtml($*text_day_prev);
    var string tnext = ehtml($*text_day_next);

    "<hr class='separator' width='100%' />\n";
    "<table width='100%'><tr align='middle'>\n";

    "<td width='33%' align='left'><a href='$.prev_url'>$tprev</a></td>\n";
    "<td align='center' width='33%'>[<a href='"; print $this.journal->base_url(); "/calendar'>$*text_view_archive</a>]</td>\n";
    "<td width='33%' align='right'><a href='$.next_url'>$tnext</a></td>\n";

    "</tr></table>";
}

function EntryPage::print_body ()
{
        set_handler("unscreen_comment_#", [
                                           [ "style_bgcolor", "cmtbar#", "$*comment_bar_one_bgcolor", ],
                                           [ "style_color", "cmtbar#", "$*comment_bar_one_fgcolor", ],
                                           ]);
        set_handler("screen_comment_#", [
                                         [ "style_bgcolor", "cmtbar#", "$*comment_bar_screened_bgcolor", ],
                                         [ "style_color", "cmtbar#", "$*comment_bar_screened_fgcolor", ],
                                         ]);

    print_entry($this, $.entry, null Color, null Color, $.viewing_thread);
    if ($.entry.comments.enabled and $.comment_pages.total_subitems > 0)
    {
        $this->print_multiform_start();
        print "<h2 class='date'>Comments:</h2>";
        "<hr class='separator' />";
        if ($.comment_pages.total_subitems > 0) {
            $.comment_pages->print();
            $this->print_comments($.comments);
        }
        if ($this.multiform_on) {
            print "<h2 class='date'>Mass Action:</h2>";
            "<hr class='separator' />";
            $this->print_multiform_actionline();
            $this->print_multiform_end();
        }
    }
}

function EntryPage::print_comment (Comment c) {
    var Color background; var Color color;
    if ($c.screened) {
        $background = $*comment_bar_screened_bgcolor;
        $color = $*comment_bar_screened_fgcolor;
    } elseif ($c.depth % 2) {
        $background = $*comment_bar_one_bgcolor;
        $color = $*comment_bar_one_fgcolor;
    } else {
        $background = $*comment_bar_two_bgcolor;
        $color = $*comment_bar_two_fgcolor;
    }
    var string poster = defined $c.poster ? $c.poster->as_string() : "<i>(Anonymous)</i>";
    var string sub_icon;
    if (defined $c.subject_icon) {
        $sub_icon = $c.subject_icon->as_string();
    }
    "<a name='$c.anchor'></a><div id='cmtbar$c.talkid' style='background-color: $background; color: $color; margin-top: 10px; width: 100%'>";
    "<table cellpadding='2' cellspacing='0' summary='0' style='width: 100%'><tr valign='top'>";
    if (defined $c.userpic and $*comment_userpic_style != "off") { 
        var int w = $c.userpic.width;
        var int h = $c.userpic.height;
        # WARNING: this will later be done by the system (it'll be a
        # constructional property), so don't copy this hack into your
        # layout layers or you'll be messed up later.
        if ($*comment_userpic_style == "small") {
            $w = $w / 2;
            $h = $h / 2;
        }
        print "<td style='width: 102px'><img src='$c.userpic.url' width='$w' height='$h' alt='[User Picture]' /></td>";
    }

    "<td style='width: 100%'><table style='width: 100%'><tr>";

    ### From, date, etc
    "<td align='left' style='width: 50%'>";
      print "<table>";
      print "<tr><th align='right' style='font-size: .9em'>From:</th><td>$poster</td></tr>\n";
      print "<tr><th align='right' style='font-size: .9em'>Date:</th><td style='white-space: nowrap'>";
        print $c.time->date_format("long") + " - " + $c.time->time_format() + "</td></tr>";
      if ($c.metadata{"poster_ip"}) { print "<tr><th align='right' style='font-size: .9em'>IP Address:</th><td>(" + $c.metadata{"poster_ip"} + ")</td></tr>"; }
    "</table></td>";

    ### Gadgets
    "<td align='right' style='width: 50%'>";
    if ($this.multiform_on) {
        " <label for='ljcomsel_$c.talkid'>$*text_multiform_check</label>";
        $c->print_multiform_check();
    }
    $c->print_linkbar();
    "</td></tr>";

    ### Subject / icon
    print "<tr valign='top'><td style='width: 50%'>";
    print (defined $c.subject_icon or $c.subject != "") ? "<h3>$c.subject_icon $c.subject</h3>" : "";
    print "</td>";

    ### Permalink
    print "<td style='width: 50%' align='right'><strong>(<a href='$c.permalink_url'>Link</a>)</strong></td></tr>";

    print "</table></td></tr></table></div>";
    print "<div style='margin-left: 5px'>$c.text</div>";
    print "<div style='margin-top: 3px; font-size: smaller'>";
    if ($c.frozen) {
        print "(Replies frozen)";
    } else {
        print "(<a href='$c.reply_url'>Reply to this</a>) ";
    }
    if ($c.parent_url != "") { "(<a href='$c.parent_url'>Parent</a>) "; }
    if ($c.thread_url != "") { "(<a href='$c.thread_url'>Thread</a>) "; }
    "</div>";
}

function ReplyPage::print_body() {
    if (not $.entry.comments.enabled)
    {
        "<h2 class='date'>$*text_reply_nocomments_header</h2>";
        "<hr class='separator' />";
        "<p>$*text_reply_nocomments</p>";
        return;
    }
    "<p class='date'>"; print $.replyto.time->date_format("%%month%% %%dayord%%, %%yyyy%%"); "</p>";
    "<hr class='separator' />";

    "<table border='0' cellpadding='2' cellspacing='0'><tr>";

    """<td valign=top align="middle" width="100">""";
    print defined $.replyto.poster ? $.replyto.poster->as_string() : "<i>(Anonymous)</i>";
    if (defined $.replyto.userpic) {
        print """<img border="0" src="$.replyto.userpic.url" width="$.replyto.userpic.width" height="$.replyto.userpic.height" alt="" />""";
    }
    "</td>";

    "<td valign='top'><strong>"; print $.replyto.time->time_format();
    if ($.replyto.subject) { " - <span style='color: $*subject_color'>$.replyto.subject</span>"; }

    "</strong><br />";

    print $.replyto.text; "<br />";

    "</td></tr></table>";
    "<p align='right' class='comments'><a href='$.entry.comments.read_url'>Read Comments</a></p>";
    "<h2 class='date'>Reply</h2>";
    "<hr class='separator' />";
    $.form->print();
}

function print_theme_preview ()
{
    """
<table width="100%" style="background-color: $*body_bgcolor; border: solid 1px #000000"><tr><td style="color:$*main_fgcolor">
  <table bgcolor="$*border_color" border="0" cellpadding="5" cellspacing="0" width="60%" align="center">
    <tr><td valign="center" align="center">
      <table width="100%" height=90% bgcolor="$*main_bgcolor" border="0" cellpadding="5" cellspacing="0">
        <tr valign="top"><td>
          <p align="right"><font color="$*title_color" face="verdana,arial,helvetica" size="3">
            <strong>December 18th, 2002</strong></font><hr noshade color="$*border_color" size="1" width="100%" />
          </p>
          <font face="verdana,arial,helvetica" size="2">
          <b>01:22 am - <font color="$*subject_color">Test</font></b><font face="verdana,arial,helvetica" size="2"><br />
          Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit. 
          Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit.</font>
          <p align="right">(<a style="color: $*link_color" href="#">Read # Comments</a> | <a style="color: $*vlink_color" href="#">Leave a comment</a>)</p>
        </td></tr>
      </table>
    </td></tr>
  </table>
</td></tr></table>
    """;
}