// 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',
  'equalizeheights',
  'listscroller',
  'tabswitcher',
  'labelizor',
  'imgpop',

  function(){
    var $ = jQuery;
    
    // labelize search input
    $('#qstr').labelizor();

    $('.mnav li').bind('mouseenter mouseleave', function (e) {
        $(this).toggleClass('hover');
      });
    
    $('#noflickerCSS').remove();

    if (!window.EPLICA_loggedin)
    {
      $('body').addClass('js-active');

      // 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');


      var tabarticle = $('h2.tabhead:first').parent();
      $('h2.tabhead', tabarticle).each(function(){
          $(this).nextUntil('h2.tabhead, p.buttons').wrapAll('<div class="tabpane" />').parent().prepend( $(this) );
        });
      $('.tabpane', tabarticle).makeTabbox().tabSwitcher();

        
      $('div.catnav').each(function(){
          $('> .boxhead', this).wrapInner('<span />')
          
          var smScnd = $('<ul class="level1 scnd" />'),
              smLis = $('ul.level1 > li', this);
          smLis.each(function(i) {
              if ( i > (smLis.length/2) - 1  ) {
                $(this).appendTo(smScnd);
              }
            })
          smScnd.appendTo( $('> .boxbody', this) );

        });


      $('body.home').run(function() {

          //topscroller
          $('div.carousel > .boxbody', this)
              .filter(function() { return $(this).find('div.item').length > 1 })
                  .listscroller({
                      item: 'div.item',
                      paging: true,
                      windowSize: 1,
                      stepSize: 1,
                      animation  : 'carousel',
                      aspect     : 'horizontal'
                    });

          //topscroller
          $('div.imgbanner > .boxbody', this)
              .filter(function() { return $(this).find('div.item').length > 1 })
                  .listscroller({
                      item: 'div.item',
                      paging: false,
                      windowSize: 1,
                      stepSize: 1,
                      autoScrollDelay: 5000,
                      animation  : 'crossfade'
                    });

          $('div.col1, div.col2', this).each(function(){
              $('div.tab-box', this).tabSwitcher();
            });
                  
        });

      $('body.project-home').run(function() {

          //topscroller
          $('div.carousel > .boxbody', this)
              .filter(function() { return $(this).find('div.item').length > 1 })
                  .listscroller({
                      item: 'div.item',
                      paging: true,
                      windowSize: 1,
                      stepSize: 1,
                      animation  : 'carousel',
                      aspect     : 'horizontal'
                    });


          $('div.snav', this).remove();
                  
        });

      var article = $('div.article div.boxbody'),
          articleImages = $('> img, p > img', article);
      articleImages
          .filter(function() {return !$(this).is('.nopop') })
              .each(function() {
                  var imgSrc = $(this).attr('src'),
                      largeImg = imgSrc.replace(/\/[^\/]+\/([^\/]+)$/, '/large/$1'),
                      imgTitle = $(this).attr('alt');
                  $(this)
                      .wrap('<a title="'+ imgTitle +'" href="'+ largeImg +'"></a>');
                })
              .parent()
                  .imgPopper({
                      curtainColor : '#ffffff',
                      curtainOpacity : '0.75',
                      yOffset: 15
                    });
        
      //popup in articles
      $('div.imagebox a.img', article)
          .each(function() {
            var imgsrc = $(this).find('img').attr('src').replace(/\/[^\/]+\/([^\/]+)$/, '/large/$1');
            $(this).attr('href', imgsrc)
          })
          .imgPopper({
              curtainColor : '#ffffff',
              curtainOpacity : '0.75',
              yOffset: 15
            });
      
      var yearIndex = $('.yearindex');
      $('p', yearIndex).hide();
      $('h3', yearIndex).wrapInner('<a href="#" />').find('a').bind('click', function (e) {
          $(this).closest('li').toggleClass('open').find('p').toggle();
          return false;
        });
      if ( $('a.current', yearIndex).length ) {
        $('a.current', yearIndex).closest('li').filter(function() { return !$(this).is('.open') }).find('h3 a').trigger('click');
      } else {
        $('li:first-child h3 a', yearIndex).trigger('click');
      }
      
    }
    
    $('body.twocol .pgmain .wrap, body.twocol .pgextra2 .wrap').equalizeHeights();
    $('div.col1, div.col2').equalizeHeights();

    //sitemap collapser
    $('div.sitemap').Req('treecollapse', function() { 
        $(this).treeCollapse({ 
            branch: 'li:has(ul)', 
            doTogglers: 1, 
            toggler: '> a.expand',
            startOpen: 'ul.level1 > li:has(ul)'
          }); 
        });


    $('.pagestyle').fontsizer();
    $('form').autoValidate();

  }
);
// **** /jqreq *****

