$(function() {

  if ($("#welcome").length > 0) {
    $("#intro li").hide();
    $("#intro li:first").show();
    intro();
  }

  $(".thumbs a").lightBox();

  // Nav: media
  $("#nMedia > a").click(function() { return false; });
  $("#nMedia").hover(function() {
    $(this).find('ul').hide().fadeIn();
  }, function() {
    $(this).find('ul').fadeOut();
  });

  // Footer
  $("body > header a, body > footer a").each(function() {
    $(this).attr('title', $(this).text());
  });
  $("body > footer a, #social a").click(function() {
      window.open($(this).attr('href'));
      return false;
  });

  // Newsletter
  $("#newsletter input").attr('value', 'Your e-mail address').focus(function() {
    $(this).attr('value', '');
  }).blur(function() {
    if ($(this).attr('value') == '') {
        $(this).attr('value', 'Your e-mail address');
    }
  });

  if ($("#newsletter .message").length > 0) {
    $("#newsletter form").hide();

    $("html,body").animate({scrollTop: $("#newsletter").offset().top }, 500);

    $("#newsletter .message a").click(function() {
        $(this).parent().fadeOut(function() {
            $("#newsletter form").fadeIn();
        });
        return false;
    })
  }

});

function intro() {
  setTimeout(function() {
      var visible = $("#intro li:visible");

      if ($("#intro li:visible").index() == $("#intro li").length - 1) {
        $("#intro li:first").fadeIn();
      }
      else {
        visible.next().fadeIn();
      }

      visible.fadeOut();
      intro();
    }, 3000);
}
