$(document).ready(function () {
  e_a();

  // Faux sub-submenu
  $("#sub-nav li").each(function() {
    if (/^- /.test($(this).text())) {
     $(this).hide();
    }
  });
  if (/^- /.test($("#sub-nav li.on").text())) {
    $("#sub-nav li.on").addClass("faux-sub").show();
    $.each($("#sub-nav li.on").prevAll(), function() {
      if (/^- /.test($(this).text())) {
        $(this).show().addClass("faux-sub");
      } else {
        return false;
      }
    });
  }
  $.each($("#sub-nav li.on").nextAll(), function() {
    if (/^- /.test($(this).text())) {
      $(this).show().addClass("faux-sub");
    } else {
      return false;
    }
  });

  // Random image on frontpage
  var n = Math.ceil(Math.random()*5);
  $("#front").attr("src", "/images/front_"+n+".jpg");

  // Picture gallery
  $("#pictures").galleryView({
   panel_width: 580,
   panel_height: 387,
   frame_width: 100,
   frame_height: 66,
   transition_interval: 0,
   overlay_height: 45,
   background_color: "#333",
   border: "2px solid #999"
  });
});

var e_a = function() {
  var h = location.hostname.replace(/^www\./, "@");
  $("span.e").each(function() {
    var n = $(this).attr("id").replace(/\d/g, "");
    var e = n.replace("=", ".") + h;
    var a = $("<a></a>").attr("href", "mailto:"+e).html(e);
    $(this).html(a);
  });
};