// 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(
  '/codecentre/concat/?utils_1.1.js;fieldsetcloner_1.0.js',
  'eutils',
  'fontsizer',
  'autovalidate',
  'labelizor',
  'equalizeheights',
  'mailtoenabler',
  'imgpop',
  'x/ifixpng',
  'prettynum',
  'tabswitcher',
  
  function(){
    var $ = jQuery,
        bgrade = $.browser.msie && parseInt($.browser.version, 10) < 9;

    $('body').addClass('js-active');
    $('#qstr').labelizor();

    if (!window.EPLICA_loggedin) {

      $('body.home .boxhead, .pgextra1 .boxhead, .pgmain .tbox .boxhead, .nambox h1').wrapInner('<span />').addClass('js-hd');

      $('.pgmain .wrap, .pgextra1 .wrap').equalizeHeights();
      if($.browser.msie) { $('.albums li').equalizeHeights(); };

      //zebra
      $('table.zebra tbody tr:nth-child(2n-1), .teikningaskra tbody tr:nth-child(2n-1)').addClass('alt');

      $('.article > .boxbody').each(function(){
            var article = $(this);

            //new imagebox popup
            $('.imagebox', article)
                .find('.imagelist li a')
                  .imgPopper({
                      curtainColor : '#867F7F',
                      curtainOpacity : '0.8',
                      fadeInSpeed:      200,
                      fadeOutSpeed:     150,
                      disableIeFading:  true
                    })
                .end()
                .filter(':has(li)')
                    .Req('listscroller', function(){
                        $(this).listscroller({
                            item : 'li',
                            paging: true,
                            animation:   bgrade ? 'none' : 'crossfade',
                            windowSize: 1,
                            speed:  600
                          });
                      });


            //popup for regular images in article
            var articleImages = $('> img, p > img, span > img', article);
            articleImages
                .each(function() {
                    var imgSrc = $(this).attr('src'),
                        largeImg = imgSrc.replace(/\/[^\/]+\/([^\/]+)$/, '/popup/$1'),
                        imgTitle = $(this).attr('alt'),
                        imgClass = $(this).attr('class');
                    $(this)
                        .wrap('<a class="zoomlink img-'+ imgClass +'" title="'+ imgTitle +'" href="'+ largeImg +'"></a>')
                        .after('<span class="magnify" />');
                  });
            articleImages
                .parent()
                .imgPopper({
                      curtainColor : '#867F7F',
                      curtainOpacity : '0.8',
                      fadeInSpeed:      200,
                      fadeOutSpeed:     150,
                      disableIeFading:  true
                  });


            //old imgbox popups
            var imgbox = $('.article .imgbox .boxbody:has(a.zoomimg)');
            if(imgbox.length) {
              imgbox.append('<div class="poplinks" style="display:none;" />');

              $('.pgs a', imgbox).each(function() {
                  var _href = $(this).attr('href').split('?')[1].replace(/ListID=\d*&file=/,'');
                  $('<a href="'+ _href +'"><img src="" alt="'+ $(this).attr('title') +'" /></a>').appendTo('.poplinks');
                });

              $('.zoomimg, .poplinks a', imgbox)
                  .imgPopper({
                      curtainColor : '#867F7F',
                      curtainOpacity : '0.8',
                      fadeInSpeed:      200,
                      fadeOutSpeed:     150,
                      disableIeFading:  true
                    });
            };
            $('.zoomimg', imgbox).append('<span class="magnify" />');

        }); // end article




      $('.people table.reportlist')
          .find('td.tel:not(:has(br))')
              .each(function(){
                  $(this).html(
                      $(this).html().replace(/(\d)(\s+\+354)/g, '$1<br /> +354') 
                    );
                });
        /*
          .Req('x/tablesorter-2.0.js', function(){
              $(this)
                  .addClass('sortable')
                  .tablesorter({
                      widgets: ['zebra'],
                      widgetZebra: {css: ["alt",""]},
                      textExtraction: 'complex'
                    });
            });
          */

      $('.gallerybox .boxbody a').append('<span class="mask" />');



      $('table.calc').each(function(){
          var priceInp = $(this).find('.price input'),
              samtInp = $(this).find('.total input'),
              samtVal = 0;

          priceInp
              .bind('change', function (e) {
                  samtVal = 0;
                  priceInp.each(function(){
                      samtVal += parseInt( this.value.replace(/\.|,/g, '') , 10);
                    });
                  samtInp.val( $.prettyNum.make(samtVal) );
                })
              .bind('keyup', function (e) {
                  $(this).val( $.prettyNum.make(this.value) );
                
                  if (!this.value || this.value < 0) {
                    $(this).val('0');
                  }
                })
              .bind('focus', function (e) {
                  this.select();
                })
              .each(function(){
                  if (!this.value) {
                    $(this).val('0');
                  }
                })
              .eq(0).trigger('change');
        });


      //clone time fields
      fieldsetCloner.config['fieldset.cloneable'] = {
        addBtnTemplate : '<div class="addDate"><a id="addDate" href="#" title="Bæta við öðru viðhengi">Bæta við viðhengi</a></div>',
        rowName : 'kennslutimi'
      }
      fieldsetCloner.init();



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



      var imagelist = $('.mediagallery.imagelist li');
      if (imagelist.length) 
      {
        $('img', imagelist).each(function() {
            var _href = $(this).attr('src').replace('/mlist/','/lighbox/');
            $(this).parent().attr('href',_href)
          })
        imagelist.find('a')
              .imgPopper({
                  curtainColor : '#867F7F',
                  curtainOpacity : '0.8',
                  fadeInSpeed:      200,
                  fadeOutSpeed:     150
                });
      }

      $('.namsgreinar .boxbody ul')
          .find('> li')
              .each(function(i) {
                  if(i % 3 == 0) {
                    $(this).css({ clear : 'left' })
                  };
                });

    }


    $('#noflickerCSS').remove();
    $('.pagestyle').fontsizer();
    $('form').autoValidate();


    //raforkureiknivél
    $('#rafreiknir').Req(Req.localPath + 'design/rafreiknir/rafreiknir.js');


    if (!window.EPLICA_loggedin) {
      $('.netfang').mailtoEnabler();
    }
    
    
  }
);
// **** /jqreq *****

