// 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',
  'imgpop',
  'fickle',
  'curtain',
  'equalizeheights',
  'x/innerfade',
  
  function(){
    var $ = jQuery;

    if (!window.EPLICA_loggedin)
    {

      // layout
      $('body.twocol .pgmain, body.twocol .pgextra2, body.threecol .pgmain, body.threecol .pgextra2').equalizeHeights({ margins:true });
      /* $('body.home .fboxleft .boxbody, body.home .fboxright .boxbody').equalizeHeights(); */


      // pngfix for IE6
      if ($.browser.msie && $.browser.version < 7) {
        $('img[src$=".png"]').Req('x/ifixpng', function(){
            $(this).ifixpng();
          });
      }

      //zebra tables
      $('tbody tr:nth-child(2n-1)').addClass('odd');

      //popup in articles
      $('div.article div.imagebox a.img')
          .each(function() {
            var imgsrc = $(this).find('img').attr('src').replace(/\/[^\/]+\/([^\/]+)$/, '/large/$1');
            $(this).attr('href', imgsrc)
          })


      $('body.home .adverts ul').innerfade({
          animationtype: 'fade',
          speed: 1000,
          timeout: 5000,
          type: 'random',
          containerheight: '168px'
        });

        
      //popup windows
      $.fn.elmPopper = function ( cfg ) {
          var popupElm = this;
          if ( popupElm.length) { 
            var curtainElm = $.curtain({
                        className: 'popup-curtain',
                        bg:        '#404040',
                        opacity:   .90
                      });
            popupElm
                .hide()
                .appendTo('body')
                .addClass('popupblock')
                .prepend('<a class="focustarget" href="#">#</a>')
                .append('<a class="close" href="#">Loka</a>')
                .before(curtainElm)
                .css({ marginLeft: - $.toInt( popupElm.outerWidth() ) / 2 })
                .fickle({
                    fadein: 350,
                    onOpen:   function (e) { $(this).css({ top: 30 + $(window).scrollTop() }).prev().fadeIn(100)  },
                    onClose:  function (e) { popupElm.fadeOut(200, function() { $(this).prev().fadeOut(100); }) },
                    onClosed: function (e) {  }
                  })
                .find('a.close')
                    .bind('click', function (e) {
                        popupElm.fickle('close');
                        return false;
                      })
                .end()
                .fickle('open');
          }
          return popupElm;
      };

      //popup map
      $('a.fjallidpop').each(function(){
          var popup = $('<div class="pop-'+ this.className +'"><img src="'+ this.href +'" alt="" /></div>');
          $(this).bind('click', function (e) {
              var link = $(this);
              if ( link.data('pop') ) {
                link.data('pop').fickle('open');
              } else {
                popup.elmPopper();
                link.data('pop', popup);
              }
              return false;
            });
        });
        
        
      //gisting ajaxpop
      $('a.gistingpop')
          .bind('click', function (e) {
              var link = $(this),
                  popupForm = link.data('popupForm');
              if (popupForm) {
                popupForm.fickle('open');
              } else {
                $.get(
                    link.attr('href'),
                    { justPicPos: 'pgmain' },
                    function(data){
                        var popData = $(data).find('div.box:first');
                        popData.elmPopper();
                        link.data('popupForm', popData);
                      }
                  );
              }
              return false;
            });

    }

    // monthlist (remove empty dates)
    var mlth = $('.monthlist-h th'),
        mltd = $('.monthlist-h td');
    mltd
      .each(function(i) {
          if($(this).hasClass('o'))
          {
              $(this).remove();
              mlth.eq(i).remove();
          }
        });


    $('#noflickerCSS').remove();
    $('.pagestyle').fontsizer();
    $('form').autoValidate();

  }
);
// **** /jqreq *****
