// encoding: utf-8
/*@cc_on/*@if(@_jscript_version<5.7)try{document.execCommand('BackgroundImageCache',0,1)}catch(e){}/*@end@*/

// ***** jqreq *****
Req(
  'fontsizer', 
  'autovalidate', 
  'labelizor', 
  'x/ifixpng', 
  'mailtoenabler', 
  'equalizeheights', 
  function(){
    var $ = jQuery,
        lang = $('html').attr('lang');
    
    $('.mnav li.current a').append('<span class="arrow">&nbsp;</span>');
    
    // labelize search input
    $('#qstr, #s_email').labelizor();
    
    if (!window.EPLICA_loggedin) {
      
      $('body.home .pgmain .box .boxbody').equalizeHeights();
      
      $('.pgextra3 .randomarticle .summary')
          .each(function() {
              var tabtext = $(this).text();
              ;;;window.console&&console.log( tabtext.length );
              if (tabtext.length > 225) {
                //only use first 180 letters of summary in frontpage tab articles
                tabtext = tabtext.substr(0,225) + '... ';
              }
              $(this).html( tabtext );
            });
            
      $('.pgmain .article .boxbody:first').prepend('<div class="fontsizer"><span class="title">Leturstærð</span><ul><li class="dwn"><a title="Minnka letrið" href="/bitar/c2/style/setStyleCookie.jsp?fontSize=-1">A-</a></li><li class="up"><a title="Stækka letrið" href="/bitar/c2/style/setStyleCookie.jsp?fontSize=1">A+</a></li></ul></div>');
      $('.fontsizer').fontsizer();
      
      //zebra tables
      $('.article table tr:even').addClass('alt');

      var articlePics = $('.article a, .articlelist a');
      articlePics.filter('[href$=".pdf"], [href$=".PDF"]').addClass('pdf');
      articlePics.filter('[href$=".doc"], [href$=".DOC"], [href$=".docx"], [href$=".DOCX"]').addClass('doc');
      articlePics.filter('[href$=".xls"], [href$=".XLS"], [href$=".xlsx"], [href$=".XLSX"]').addClass('xls');

      // Add "send to facebook" link to articles
      
      var fbText = (lang == 'no') ? 'Send til facebook' : (lang == 'is') ? 'Senda á facebook' : 'Send to facebook';
      $('.buttons')
          .append(
              $('<a class="btnfacebook" href="#">'+ fbText +'</a>')
                  .bind('click', function()  {
                      window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location.href)+'&t='+encodeURIComponent($('h1').text()),'sharer','toolbar=0,status=0,width=626,height=436');
                      return false;
                    })
            );

      //toggle list items
       $('.mapnav').each(function(){
          var mapnav = $(this),
                lastSubList = [];
          mapnav.find('.level2').hide();
          mapnav
              .delegate('.level1 > li > a', 'click', function (e) {
                  var link = $(this);
                  if (lastSubList[0])
                  {
                    lastSubList.hide()
                  }
                  lastSubList = link.nextAll('.level2').show();
                  return false;
                });
        });

      //enable mailto
      $('span.netfang').mailtoEnabler();
        
      if (!$('.pgextra3').length) {
        $('.layouthack').css({ height:50 });
        $('.pgwrap2').css({ 'margin-bottom': -50 });
      }
    }

    // validate all forms
    $('form').autoValidate();
    
    //remove flicker trick
    $('#noflickerCSS').remove();
    
    if (!window.EPLICA_loggedin) {
      // pngfix for IE6
      if ($.browser.msie) {
        $('img[src$=".png"]').ifixpng();
      }
    }
    
  }
);
// **** /jqreq *****

