$(init);

function init() {

  $("form.userform").each(
    function() {
      FormRegistry.init($(this));
    }
  );

  if ($.browser.msie) {
    $("object, embed, applet").each(
      function() {
        this.outerHTML = this.outerHTML;
      }
    );
    try {
      document.execCommand("BackgroundImageCache", false, true);
    }
    catch(err) {}
  }

  newsletterHandler();
  faq();

  $("#sitemap li:last, #sitemap ul li:last").addClass("last");

}

function newsletterHandler() {

  $("#newsletter_subscribe, #newsletter_unsubscribe").click(
    function() {
      /*if (!/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/.test($("#newsletter_input"))) {
        alert('Prašome įvesti savo el. pašto adresą');
        return false;
      }*/
      $("#newsletters")
        .find("input[@name='act'], input[@name='form_type']")
          .val($(this).attr('id').split('_')[1])
        .end()
        .trigger('submit');
    }
  );

}


function faq() {

  $("#faq")
    .find("dt")
      .css({cursor: 'pointer'})
      .click(
        function() {
          if ($(this).next().is("dd")) {
            $(this).parent().find("dd:visible").hide();
            $(this).next().show();
          }
        }
      )
    .end()
    .find("dd").hide();

}

window.onload = function() {
  $("#footer").css({borderBottom: "1px solid #fff"});
  $("#nav").hide().show();
}
