// encoding: utf-8
/*@cc_on/*@if(@_jscript_version<5.7)try{document.execCommand('BackgroundImageCache',0,1)}catch(e){}/*@end@*/

// ***** jqreq *****
Req.localPath = Req.localPath || '/skin/basic/';
Req(
  'eutils',
  'fontsizer',
  'autovalidate',
  'anchortags',
  'labelizor',
  'imgpop',

  function(){
    var $ = jQuery,
        articles = $('.article, .articlelist');
        
    $('body').addClass('js-active');

    var texts = {
        is: {
            newWindow:        'Opnast í nýjum vafraglugga',
            fileText:         'skjal'
          },
        en: {
            newWindow:        'Opens in new window',
            fileText:         'file'
          }
      };
    texts = texts[ $.lang() ]  ||  texts.en;

    $('#qstr').labelizor();
    
    if (!window.EPLICA_loggedin) {
      
      articles.find('tbody tr:nth-child(2n-1)').addClass('odd');

      //tag external urls
      var link, text, useappend, match;
      $('.pgmain a').anchorTags({
                usePatterns:  ['doc', 'pdf', 'xls', 'image']
              })
            .filter('.external, .file_pdf, .file_doc, .file_xls, .file_image')
                    .each(function() {
                        link = $(this);
                        text = '';
                        useappend = false;
                        match = this.className.match(/(^| )file_([a-z]+)( |$)/);
                        if ( match )
                        {
                          text = match[2].toUpperCase() +' '+ texts.fileText;
                        }
                        else if ( $(this).is('.external') )
                        {
                          text = texts.newWindow;
                          useappend = true;
                        }
                        if (text)
                        {
                          link
                              .attr('target', '_blank')
                              .attr('title', (link.attr('title')||link.text()) +' ('+ text+')')
                              .not(':has(img)')
                                  [useappend ? 'append' : 'prepend'](' <span class="icon">('+ text +')</span>'+ (useappend ? '' : ' ') );
                        }
                      });
      
      
      articles.find('.imgbox a:has(img)').imgPopper({
                curtainColor : '#ffffff',
                curtainOpacity : '0.75',
                yOffset: 15
              });

    }
    
    //sitemap collapser
    $('.sitemap').Req('treecollapse', function() { 
        $(this).treeCollapse({ 
            branch: 'li:has(ul)', 
            doTogglers: 1, 
            toggler: '> a.expand',
            startOpen: 'ul.level1 > li:has(ul)'
          }); 
        });
    
    $('.pagestyle').fontsizer();
    $('#noflickerCSS').remove();
    $('form').autoValidate();

    //Req.loadPageScripts();
    
    $('body.umsagnir').Req( Req.localPath + 'design/umsagnir/umsagnir.js')

  }
);
// **** /jqreq *****
