$(document).ready(function() {

  $.each($("#hmenus div.nav a"),function() {
    if($(this).text() == 'Questions') {
      $(this).text('Domande');
    } else if($(this).text() == 'Tags') {
      $(this).text('Tag');
    } else if($(this).text() == 'Users') {
      $(this).text('Utenti');
    } else if($(this).text() == 'Badges') {
      $(this).text('Badge');
    } else if($(this).text() == 'Unanswered') {
      $(this).text('Senza Risposta');
    } else if($(this).text() == 'Ask Question') {
      $(this).text('Nuova Domanda');
    }   
  });

  $.each($("#subheader h2"),function() {
    if($(this).text() == "Recent Questions") {
      $(this).text("Domande Recenti");
    } else if($(this).text() == "All Questions") {
      $(this).text("Tutte le Domande");
    } else if($(this).text() == "Tags") {
      $(this).text("Tag");
    } else if($(this).text() == "Users") {
      $(this).text("Utenti");
    } else if($(this).text() == "Unanswered Questions") {
      $(this).text("Domande Senza Risposta");
    } else if($(this).text() == "Ask a Question") {
      $(this).text("Nuova Domanda");
    } else if($(this).text() == "Badges") {
      $(this).text("Badge");
    } else if($(this).text().search("Answers") > 0) {
      $(this).html($(this).html().replace("Answers", "Risposte"));
    } else if($(this).text().search("Answer") > 0) {
      $(this).html($(this).html().replace("Answer", "Risposta"));
    }
  });

  $.each($("#subheader #tabs a"),function() {
    if($(this).text() == 'active') {
      $(this).text('attive');
    } else if($(this).text() == 'hot') {
      $(this).text('attuali');
    } else if($(this).text() == 'week') {
      $(this).text('settimana');
    } else if($(this).text() == 'month') {
      $(this).text('mese');            
    } else if($(this).text() == 'newest') {
      $(this).text('recenti');
    } else if($(this).text() == 'featured') {
      $(this).text('in rilievo');
    } else if($(this).text() == 'votes') {
      $(this).text('voti');
    } else if($(this).text() == 'name') {
      $(this).text('nome');
    } else if($(this).text() == 'reputation') {
      $(this).text('reputazione');
    } else if($(this).text() == 'oldest') {
      $(this).text('meno recenti');
    } else if($(this).text() == 'tags') {
      $(this).text('tag');
    } else if($(this).text() == 'my tags') {
      $(this).text('miei tag');
    } else if($(this).text().search('featured') == 1) {
      $(this).html($(this).html().replace("featured", "in rilievo"));
    }
  });



  $.each($("div.question-summary div"),function() {
    if($(this).text() == 'votes') {
      $(this).text('voti');
    } else if($(this).text() == 'answers') {
      $(this).text('risposte');
    } else if($(this).text() == 'answer') {
      $(this).text('risposta');
    } else if($(this).text() == 'views') {
      $(this).text('visite');
    } else if($(this).text() == 'view') {
      $(this).text('visita');
    }
  });


  $.each($("#topbar a"),function() {
    if($(this).text() == "login") {
      $(this).text("login");
    } else if($(this).text() == "logout") {
      $(this).text("logout");
    }
  });

  $.each($("#post-form h2"),function() {
    if($(this).text() == "Your Answer") {
      $(this).text("Tua Risposta");
    }
  });

  $.each($("#post-form label"),function() {
    if($(this).text() == "Title") {
      $(this).text("Titolo");
    } else if($(this).text() == "Tags ") {
      $(this).text("Tag");
    } else if($(this).text() == "OpenID Login ") {
      $(this).text("Utente OpenID");
    } else if($(this).text() == "Name ") {
      $(this).text("Nome");
    } else if($(this).text() == "Email never shown") {
      $(this).text("Email - Non visibile pubblicamente");
    } else if($(this).text() == "Home Page ") {
      $(this).text("Sito Web");
    }                   
  });

  $.each($("div#sidebar div.module h4"),function() {
    if($(this).text() == "Related") {
      $(this).text("Correlate");
    } else if($(this).text() == "Formatting Reference") {
      $(this).text("Guida alla Formattazione");
    } else if($(this).text() == "Related Tags") {
      $(this).text("Tag Correlati");
    } else if($(this).text() == "Legend") {
      $(this).text("Legenda");
    } else if($(this).text() == "Recent Tags") {
      $(this).text("Ultimi Tag");
    } else if($(this).text() == "Recent Badges") {
      $(this).text("Ultimi Badge");
    }
  });

  $.each($("#post-form div.form-item-info"),function() {
    if($(this).text().search('Combine multiple words into single-words, space to separate up to 5 tags') > 0) {
      $(this).html($(this).html().replace("Combine multiple words into single-words, space to separate up to 5 tags", "Unisci più parole in una sola, usa lo spazio per separare più parole, fino a 5"));
    }
  });

  $.each($("#mainbar h2"),function() {
    if($(this).text().search('Looking for more?') >= 0) {
      $(this).html($(this).html().replace("Looking for more? Browse the", "Cerchi altro? Consulta la"));
      $(this).html($(this).html().replace("complete list of questions", "lista completa delle domande"));
      $(this).html($(this).html().replace(", or", " o "));
      $(this).html($(this).html().replace("popular tags", "i tag più popolari"));
      $(this).html($(this).html().replace(". Help us answer", ". Aiutaci a rispondere"));
      $(this).html($(this).html().replace("unanswered questions", "alle domande aperte"));
    }
  });

  if($("#submit-button").val() == "Ask Your Question") {
    $("#submit-button").val("Crea una Domanda");
  } else if($("#submit-button").val() == "Post Your Answer") {
    $("#submit-button").val("Scrivi la tua Risposta");
  }

});
