<:

# Hauptmenü generieren

sub main_menu {
    my @dirs = @_;
    my $width = 100/($#dirs+1);

    print "<center><table border=0 cellpadding=2 cellspacing=10 width=90%><tr>";
    foreach $rubrik (@dirs) {
	if ("<get-var WML_SRC_DIRNAME>" =~ /src\/$rubrik/) {
	    $color="<menu-bgcolorsel>";
	    if ("<get-var WML_SRC_BASENAME>" eq "index") {
		printf "<th align=center width=%d%% bgcolor=#%s>", $width, $color;
		print "<font size-=5 color=\"#<menu-bgcolor>\"> · </font>"
		    if ($rubrik ne $dirs[0]);
		printf "<font face=\"Helvetica,Arial\" color=\"#<menu-fgcolor>\">%s</font></th>\n", $rubrik;
	    } else {
		printf "<th align=center width=%d%% bgcolor=#%s>", $width, $color;
		print "<font size-=5 color=\"#<menu-bgcolor>\"> · </font>"
		    if ($rubrik ne $dirs[0]);
		printf "<font face=\"Helvetica,Arial\" color=\"#<menu-fgcolor>\"><a href=%s%s/>%s</a></font></th>\n",
			$root_prefix, $rubrik, $rubrik;
	    }
	} else {
	    $color="<menu-bgcolor>";
	    printf "<th align=center width=%d%% bgcolor=#%s>", $width, $color;
	    print "<font size-=5 color=\"#<menu-bgcolor>\"> · </font>"
		if ($rubrik ne $dirs[0]);
	    printf "<font face=\"Helvetica,Arial\" color=\"#<menu-fgcolor>\"><a href=%s%s/>%s</a></font></th>\n",
		$root_prefix, $rubrik, $rubrik;
	}
    }
    print "</tr></table></center>\n";
}

# @_ ist ein Array, dessen *letztes* Element die Anzahl
# der Elemente enthaelt
#
sub web_calc_table_width
{
    my $count = pop(@_);
    my @widths = @_;
    my $i;
    my $mod;
    my $tabwidth = 0;

    foreach $i (@widths) {
	$tabwidth = $i if ((($count) % $i) == 0);
    }
    if (!$tabwidth) {
	foreach $i (@widths) {
	    $tabwidth = $i if ((($count) % $i) > $mod);
	    $mod = ($count) % $i;
	}
    }
    return $tabwidth;
}

sub specials_menu
{
    my $tabwidth = 0;
    my $i;
    my $elems = shift;
    my %elems = %$elems;
    my @keys;
    my $width;
    my $foo;

    if (%elems) {
	@keys = keys %elems;
	$tabwidth = &web_calc_table_width(6,5,4,3,$#keys+1);
	$width = 100/$tabwidth;
 
	print "<center><table border=0 cellpadding=2 cellspacing=10 width=90%><tr>";
	$i=0;
	while ($i <= $#keys) {
	    print "<tr>" if (! ($i % $tabwidth));

	    $foo = sprintf ("<font face=\"Helvetica,Arial\" color=\"#<menu-fgcolor>\"><a href=\"%s\">%s</a></font>"
			    , $keys[$i], $elems{$keys[$i]});
	    printf "<td align=center width=%d%% bgcolor=#<menu-bgcolor>>%s\n",
	        $width, $foo;

	    $i++;
	    if (! ($i % $tabwidth)) {
		print "</td></tr><p>\n";
	    } else {
		print "<font size-=5 color=\"#<menu-bgcolor>\"> · </font></td>";
	    }
	}
	if ($i % $tabwidth) {
	    do {
		print "<td bgcolor=#<menu-bgcolor>>&nbsp;</td>";
		$i++;
		print "</tr><p>" if (! ($i % $tabwidth));
	    } until (!($i % $tabwidth));
	}
	print "</table></center>\n";
    }
}

:>
