// 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',
  'labelizor',
  'imgpop',
  'equalizeheights',
  'x/innerfade',

  function(){
    var $ = jQuery,
        isIS = $('html').attr('lang') == 'is';

    // labelize search input
    $('#qstr').labelizor();

    $('body:not(.home) .pgmain, .pgextra2').equalizeHeights();

    if (!window.EPLICA_loggedin)
    {

      $('body.home .pgmain .box .boxbody').equalizeHeights();
      
      isIS ? $('body').addClass('is') : $('body').addClass('en');

      $('.toparticle .imagelist')
          .innerfade({
              animationtype: 'fade',
              speed: 1000,
              timeout: 4000,
              type: 'sequence',
              containerheight: '274'
            });


      //zebra tables
      $('tbody tr:nth-child(2n-1)').addClass('odd');


      //popup in articles
      $('.article .imagebox a.img')
          .each(function() {
            var imgsrc = $(this).find('img').attr('src').replace(/\/[^\/]+\/([^\/]+)$/, '/popup/$1');
            $(this).attr('href', imgsrc)
          })
          .imgPopper({
              curtainColor : '#f8f8f3',
              curtainOpacity : '0.9',
              yOffset: 80
            });

      //popup in articles
      var galleylist = $('.mediagallery.imagelist li');
      for (var i=0, l=galleylist.length; i<l; i+=4)
      {
        var max = 0;
        galleylist.slice(i,i+4)
            .each(function(){
                max = Math.max( $(this).height() , max );
              })
            .css({ 'height': max });
      }
      galleylist.find('a')
          .each(function() {
            var imgsrc = $(this).find('img').attr('src').replace(/\/[^\/]+\/([^\/]+)$/, '/popup/$1');
            $(this).attr('href', imgsrc)
          })
          .imgPopper({
              curtainColor : '#f8f8f3',
              curtainOpacity : '0.9',
              yOffset: 80
            });

      // pngfix for IE6
      if ($.browser.msie && $.browser.version < 7) {
        $('img[src$=".png"]').Req('x/ifixpng', function(){
            $(this).ifixpng();
          });
      }

    } // end loggedin

    //sitemap collapser
    $('.sitemap').Req('treecollapse', function() { 
        $(this).treeCollapse({ 
            branch: 'li:has(ul)', 
            doTogglers: 1, 
            toggler: '> a.expand',
            startOpen: 'ul.level1 > li:has(ul)'
          }); 
        });

    //common
    $('#noflickerCSS').remove();
    $('.pagestyle').fontsizer();
    $('form').autoValidate();

  }
);
// **** /jqreq *****

