// encoding: utf-8
/*@cc_on/*@if(@_jscript_version<5.7)try{document.execCommand('BackgroundImageCache',0,1)}catch(e){}/*@end@*/

// ***** jqreq *****
Req(
  'fontsizer',
  'autovalidate',
  'x/ifixpng',
  'imgpop',
  'tabswitcher',
  'equalizeheights',
  'easing-mini',
  'listscroller',
  'q-videoplayer',
  Req.baseUrl.replace(/jq\/$/, 'js/') + 'utils_1.1.js',
  { src: Req.baseUrl.replace(/jq\/$/, 'js/') + 'datepicker/1.0/dp.js', charset: 'iso-8859-1' },

  function(){
    var $ = jQuery,
        article = $('.article'),
        pgmain = $('.pgmain .wrap'),
        pgextra2 = $('.pgextra2 .wrap');

    $('body').addClass('js-active');

    if (!window.EPLICA_loggedin)
    {
      // zebra tables
      article.find('table tr:even').addClass('alt');

      // popup in articles
      article.find('.imgbox a:has(img)').imgPopper();

      // blockquotes
      article.find('blockquote')
          .wrapInner('<div />')
              .find('div')
                  .prepend('<span class="quoteart" />');
    }


    // eq heights
    if(pgextra2.height() > pgmain.height()){
      pgmain.add(pgextra2).equalizeHeights();
    }


    // news 
    var months = 'jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec'.split(',');
    $('.news .item .date')
        .each(function(){
            var dt = $(this).html().split('.');
            $(this).html('<span class="month">' + months[dt[1]-1] + '</span> <span class="day">' + dt[0] + '.</span> <span class="year">' + dt[2] + '</span>');
        });

    $('.fcon').each(function(){
        $(this).find('.fbox .boxbody').equalizeHeights();
      });


    // monthlist
    $('.monthlist').Req('http://www.ehfcn.org/bitar/common/calendar/calendarPager.js', function(){
        var initCalendars = function ( e ) {
            $('div.dateinfo', this)
                .hide()
                .parent()
                .bind('mouseenter focusin', function(e){
                    $(this).find('div.dateinfo')
                        .stop()
                        .css({ opacity : 1 })
                        .css({ height : 'auto' })
                        .css({ width : 'auto' })
                        .show(200, 'easeOut');
                  })
                .bind('mouseleave focusout', function(e){
                    $(this).find('div.dateinfo')
                        .stop()
                        .css({ opacity : 1 })
                        .css({ height : 'auto' })
                        .css({ width : 'auto' })
                        .hide(200, 'easeIn');
                  });
          };

        this
            .eplicaCalendarLoader()
            .bind('reload', initCalendars);

        initCalendars.call(this);
      });


    // spotlight
    var spotlight = $('.spotlight');
    if($('.item', spotlight).length > 1) {
        spotlight
            .listscroller({
                item          : 'div.item',
                windowSize    : 1,
                stepSize      : 1,
                paging        : true,
                speed         : 500,
                autoScrollDelay : 4500,
                controls      : 'below',
                hideClass     : 'overflow',
                wrap          : 'both',
                animation     : 'accordion'
            });
    }


    // dropdown menu
    pgextra2.find('.mnav .branch')
        .addClass('closed')
        .each(function(i){
        
            var li = $(this),
                trigger = false;
          
            li.hover(
                  function(){ // in
                    trigger = false;
                    setTimeout(function(){
                      if(!trigger) {
                        li.removeClass('closed')
                        li.addClass('open');
                      }
                    }, 400);
                  },
                  function(){ // out
                    trigger = true;
                    setTimeout(function(){
                      if(trigger) {
                        li.removeClass('open');
                        li.addClass('closed');
                      }
                    }, 400);
                  }
                );
          });


    if (window.EPLICA_loggedin)
    {

      // newsletter 
      var overview = $('.newsletter .overview .boxbody').append('<ul class="right" />'),
          overviewUl = overview.find('ul:last'),
          overviewLis = overview.find('li');
      
      overviewLis.each(function(i){
          if(i > parseInt(overviewLis.length/2, 10))
          {
            $(this).appendTo(overviewUl);
          }
        });


      // pngfix for IE6
      if ($.browser.msie && parseInt($.browser.version, 10) < 7) {
        $('img[src$=".png"]').Req('x/ifixpng', function(){
            $(this).ifixpng();
          });
      }

    } // end EPLICA_loggedin
    
    if (!window.EPLICA_loggedin)
    {

      $('.videotable .item').each(function () {
          $(this).find('.subtitle').insertAfter($(this).find('.meta')).append('<br />');
        });
              
      var vtable = $('.videotable');
      vtable.find('.boxbody').videoList({
          vidWidth: 596,
          vidHeight: 466,
          thumbnails: true,
          setfragment: true,
          startOpen: vtable.is('.startopen')
        });
    }

    //Removes /nr/xxx from url in newsletter
    $('table .btnback').each(function () {
        var url = window.location.toString().split('/nr');
        $(this).bind('click', function (e) {
            window.location = url;
          });
      });

    // eventslist
    $('body.twocol .eventlist .meta').each(function(){
        $(this).appendTo($(this).parent());
      });


    // challenges
    $('.challenges p:last').addClass('last');
    $('ul.tabs').tabSwitcher({ cssHide : true });
    $('#noflickerCSS').remove();
    $('div.pagestyle').fontsizer();
    datePicker.init();
    $('form').autoValidate();
    

  }
);
// **** /jqreq *****


