// 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',
  'imgpop',
  'easing-mini',
  'listscroller',
  'imgpop',
  'mailtoenabler',
  'equalizeheights',
  
  function(){
    var $ = jQuery,
        msie6 = $.browser.msie && $.browser.version < 7,
        isLocal = !/^http/.test(document.location),
        localPath = isLocal ? './..' : '/skin/basic';
    
    var langIs = $('html').attr('lang') == 'is',
        nextText = langIs ? 'Næsta' : 'Next',
        prevText = langIs ? 'Fyrri' : 'Previous',
        nextTitle = langIs ? 'Næsta mynd' : 'Next image',
        prevTitle = langIs ? 'Fyrri mynd' : 'Previous image',
        pageText = langIs ? 'Mynd ' : 'Image ',
        ofText = langIs ? ' af  ' : ' of  ';

    
    if (!window.EPLICA_loggedin)
    {
      
      $('body').addClass('js-active');
      
      $('body.home .qbox .item .summary').each(function() {
        var texti = $.trim( $(this).text() );
        if(texti.length > 250) {
          texti = texti.substr(0,250)
          $(this).text(texti + '...');
        }
      });
      
      $('.qbox .boxbody').equalizeHeights();
    
      // labelize search input
      $('#qstr').labelizor();

      // pngfix for IE6
      if (msie6) {
        $('img[src$=".png"]').ifixpng();
      }
      
      //zebra tables
      $('div.article table tr:even').addClass('alt');
      
      
      // Powerplant map
      $('body.home .kort .articlelist').Req(
          'curtain',
          'mappopulizor',
          'x/ui-accordion',
          localPath+'/js/init_map.js',
          function(){  sjominjar.map.init(this);  }
        );
      
      
      var imagelists = $('.article .imagebox')
      if(imagelists.find('li').length > 1) {
          imagelists
            .listscroller({
              item       : 'li',
              aspect     : 'horizontal',
              paging     : true,
              statusPager: true,
              jumpPager: false,
              animation  : 'carousel',
              windowSize : 1,
              stepSize   : 1,
              ofTotalSeparator  : ofText,
              labelNext  : nextText,
              labelPrev  : prevText,
              statusLabel  : pageText,
              titleNext  : nextTitle,
              titlePrev  : prevTitle
          })
        }
      imagelists
        .find('a:has(img)')
            .imgPopper({
                curtainColor : '#fff',
                curtainOpacity : '0.8',
                disableIeFading : 1,
                fadeInSpeed : 200,
                fadeOutSpeed : 100
              });
              

      //popup in articles
      $('div.article div.imgbox a:has(img)')
          .each(function() {
            var imgsrc = $(this).find('img').attr('src').replace(/\/[^\/]+\/([^\/]+)$/, '/large/$1');
            $(this).attr('href', imgsrc)
          }) 
          .imgPopper({
              curtainColor : '#fff',
              curtainOpacity : '0.8'
            });
      
      $('body:not(.home) .qbox .boxbody').each(function() {
          var $this = $(this);
          $this
              .find('h3, ul')
                  .wrapAll('<div class="dropbox" />')
                .parent()
                    .find('ul').hide()
                .parent()
                    .find('h3')
                        .wrapInner('<a href="#" />')
                        .find('a')
                            .bind('click', function() {
                                $('.dropbox', $this).toggleClass('dropopen');
                                $this.find('ul').slideToggle(200, 'easeInOut');
                                return false;
                              });
        });
      

      $('.netfang').mailtoEnabler();
    }
    
    //remove flicker trick
    $('#noflickerCSS').remove();

    // fontsizer
    $('div.pagestyle').fontsizer();

    // validate all forms
    $('form').autoValidate();
        
  }
);
// **** /jqreq *****

