String.prototype.trim = function() {
  a = this.replace(/^\s+/, '');
  return a.replace(/\s+$/, '');
};

$(document).ready(function() {

  $('.answer').each(function(index) {
    var answer = $(this);
    var elShow = $('<div class="answerShow" id="answerShow' + index
      + '">Vís svar</div>')
      .click(function() {
        $(this).hide();
        answer.show();
        $('#answerHide' + index).show();
      });
    elShow.hover(
      function() { $(this).addClass('over'); },
      function() { $(this).removeClass('over'); }
    );
    var elHide = $('<div class="answerHide" id="answerHide' + index + '">'
      + 'Fjal svar</div>')
      .click(function() {
        $(this).hide();
        answer.hide();
        $('#answerShow' + index).show();
      });
    elHide.hover(
      function() { $(this).addClass('over'); },
      function() { $(this).removeClass('over'); }
    );
    $(this).before(elShow).after(elHide).hide();
    elHide.hide();
  });

  $('#spyrHelenuName').focus(function() {
    $(this).attr('class', 'focus');
    if (this.value.trim() == 'Skriva navn títt her ...') {
      this.value = '';
    }
  }).blur(function() {
    $(this).attr('class', '');
    if (this.value.trim() == '') {
      this.value = 'Skriva navn títt her ...';
    }
  });
  
  $('#spyrHelenuEmail').focus(function() {
    $(this).attr('class', 'focus');
    if (this.value.trim() == 'Skriva t-post her ...') {
      this.value = '';
    }
  }).blur(function() {
    $(this).attr('class', '');
    if (this.value.trim() == '') {
      this.value = 'Skriva t-post her ...';
    }
  });
  
  $('#spyrHelenuText').focus(function() {
    $(this).attr('class', 'focus');
    if (this.value.trim() == 'Skriva spurningin her ...') {
      this.value = '';
    }
  }).blur(function() {
    $(this).attr('class', '');
    if (this.value.trim() == '') {
      this.value = 'Skriva spurningin her ...';
    }
  });
  
});

