// 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(
  'fontsizer',
  'autovalidate',
  'curtain',
  'imgpop',

  function(){
    var $ = jQuery,
        isIS = $('html').attr('lang') == 'is';
    
    //zebra stafflist
    $('div.employeelist ul li:nth-child(2n-1)').addClass('alt');

    if (!window.EPLICA_loggedin)
    {
      //youtube popup á forsíðu
      $('body.home .hdimage a').bind('click', function (e) {
          var href = $(this).attr('href');
          if (/youtu\.be/i.test( href ))
          {
            var youtubeId = 'http://www.youtube.com/embed/' +  href.match(/\/([0-9a-z]+)$/i)[1]  + '?rel=0&autoplay=1',
                ytFrame = '<iframe title="YouTube video player" width="700" height="505" src="'+ youtubeId +'" frameborder="0" allowfullscreen></iframe>',
                ytTempl = $('<div class="ipopup-container" style="display: none;"><div class="ipopup-curtain" style="display: block; background-color: rgb(0, 58, 102); opacity: 0.75;"></div><div class="ipopup-container-wrapper" style="position: absolute;top:60px;left:50%;margin-left:-398px;z-index: 110;"><div class="image">' +
                            '</div><a href="#" class="close" title="Loka">Loka</a></div></div>');

            ytTempl.find('.ipopup-curtain, .close').bind('click', function (e) {
                ytTempl
                    .find('iframe').remove().end()
                    .fadeOut('fast');
		return false;
              });

            $(window).bind('keyup', function (e) {
                  if ( e.keyCode == 27 )
                  {
                    ytTempl.find('.ipopup-curtain').trigger('click');
                  }
                });

            ytTempl.find('.image').append(ytFrame).end().appendTo('body').fadeIn('fast');
                
            return false;
          }
        });
      
      //popup in articles
      $('.imagelist ul a')
          .each(function() {
            var imgsrc = $(this).find('img').attr('src').replace(/\/[^\/]+\/([^\/]+)$/, '/xlarge/$1');
            $(this).attr('href', imgsrc)
          })
          .imgPopper({
              curtainColor : '#003a66',
              curtainOpacity : '0.75',
              yOffset: 60
            });


      //Leiðavísir
      var leidavisir = $('.questions .boxbody');
      if ( leidavisir.length ) {

          var rdos = leidavisir.find('.fi_rdo, .ext'),
              posb = $('#rg, #ge, #rb, #tb, #tf');

          leidavisir[0] && leidavisir[0].reset();
          rdos.slice(1).hide();
          posb.hide();

          leidavisir.find('input:radio').bind('change', function (e) {
              posb.hide();

              $(this).closest('fieldset')
                          .find('li').removeClass('selected').end()
                          .nextAll('fieldset')
                              .removeClass('done')
                              .hide()
                              .find('li').removeClass('selected').end()
                              .find('input:radio').attr('checked',false);
            
              $(this).closest('fieldset').prevAll('fieldset').andSelf().addClass('done').find('input');
            
              $(this).parent().addClass('selected');
                          

              var val = $(this).val().split('-');
              if ( val[0] == 'goto' ) 
              {
                $('#' + val[1]).show();
              } 
              else // if ( val[0] == 'end' ) 
              {
                for (var i=1; i<val.length; i++) {
                  $('#' + val[i]).show();
                }
              }
            });

          var txtrestart = isIS ? 'Byrja aftur' : 'Start over';
          $('.ext').append('<a class="restart" href="#restart">'+txtrestart+'</a>');
            
          $('.restart').bind('click', function (e) {
              leidavisir[0].reset();
              rdos.removeClass('done').find('li').removeClass('selected');
              rdos.slice(1).hide();
              posb.hide();
              return false;
            });
      }
    }

    // fontsizer
    $('.pagestyle').fontsizer();
    $('form').autoValidate();

  }
);
// **** /jqreq *****
