<?php
include ("../../functions.php");
include ("../../conf.php");

if (!$board_config->lang) $board_config->lang = "en";
include ("$www_dir/lang/" . $board_config->lang . "/common.lang.php");

$d = basename($_REQUEST["d"]);

$avatars = avatars($d);


if ($avatars) {
  $d_options = "<option value=''>" . lang("please_select") . "</option>\n";
  $cat_cnt = count($avatars);
  for ($i=0;$i<$cat_cnt;$i++) {
    if ($d == $avatars[$i]["cat"]) $av_key = $i;
    $d_options .= "<option value='" . $avatars[$i]["cat"] . "'>" . $avatars[$i]["cat"] . "</option>\n";
  }
  echo "<div class='avform'>";
  echo "<select name='avatar_directories' onchange=\"changeDir(this.value,'$main_path');\">" . str_replace("value='$d'", "value='$d' selected='selected'", $d_options) . "</select>";
  echo "</div>";
  echo "<div class='avatars'>";
  if (is_numeric($av_key)) {
    for ($i=0;$i<$avatars[$av_key]["cnt"];$i++) {
      echo "<img src='$main_path/$d/" . $avatars[$av_key]["files"][$i] . "' />\n";
    }
  }
  echo "</div>";
?>
<script type="text/javascript">
  $("#sbbavatars .avatars img").click(function() {
    var newSrc = $(this).attr("src");
    $("#sbb .sbbav").attr("src",newSrc);
    $("input[name='sbb_avatar']").val(newSrc);
    closeavatars();
  });
</script>


  
<?php
} else {
  exit("No Avatars :(");
}

?>