(function($) {

  $('#qstr').labelizor();

  $('.home .item .date').each(function() {
      var date = $.trim( $(this).text() ).split('.'),
          month = ['','jan','feb','mar','apr','maí','jún','júl','ágú','sep','okt','nóv','des'];
      $(this).html( '<span class="d">'+ date[0] +'</span><span class="m">'+ month[ date[1] ] +'</span>' );
    });

  if (!window.EPLICA_loggedin) 
  {
    var atable = $('.article table tbody');
    $('tr', atable).removeClass('alt');
    $('tr:nth-child(2n-1)', atable).addClass('alt');
  }

  if ($.browser.msie && $.browser.version < 7) {
    $('img[src$=".png"]').ifixpng();
  }

  $('.pageextra2 .graybox .item img').wrap('<span class="img" />');


  //Article collapser
  var collapsearticle = $('.article.collapse');
  collapsearticle.find('h4')
      .each(function() {
          var heading = $(this);
          heading.wrapInner('<a href="#" />');
          heading.add( heading.nextUntil('h2, h3, h4, .buttons') ).wrapAll('<div class="collapsebox" />');
        });
  collapsearticle.find('.collapsebox')
      .each(function() {
          var collapsebox = $(this);
          collapsebox.find('> *:not(h4)').wrapAll('<div class="collapsecontent" />').parent().hide();
          collapsebox
              .find('h4 a').bind('click', function() {
                  collapsebox.find('.collapsecontent').slideToggle(200);
                  collapsebox.toggleClass('collapse-open');
                  return false;
                });
        });


  $('.fyrirspurn')
      .each(function(){
          var legal = $(this).find('#abending, #fyrirspurn'),
              formTag = $(this).find('#formTag'),
              thankyou = $(this).find('input[name=thank_you_page]');

          formTag.bind('change', function (e) {
              var val = $(this).val()
                  toFilter = val.length ? '#' + val : '';
              legal.hide().filter( toFilter ).show();

              if (val == 'fyrirspurn') {
                thankyou.val('/takk?fid=5');
              }
              else if ( val == 'abending' ) {
                thankyou.val('/takk?fid=6');
              } 
              else {
                thankyou.val('');
              }
            });
        })
      .autoValidate();

  $('.fontsizer').fontsizer();

})(jQuery);
