// 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(
  'autovalidate',
  'easing-mini',
  'equalizeheights',
  'eutils',
  'fontsizer',
  'imgpop',
  'labelizor',
  'tabswitcher',
  //'x/cookie',
  
  function(){
    var $ = jQuery;

  $('div.pagestyle').fontsizer();
  
  $('form').autoValidate();
  
  $('#qstr').labelizor();
  
  $('ul.tabs').tabSwitcher();

  $('#noflickerCSS').remove();
  
  if (!window.EPLICA_loggedin) {
    $("div.article table tr:odd").addClass("alt");
  }
  
  //heightfix bokasafn boxes
  $('body.bokasafn')
      .find('div.pgmain .box, div.pgextra2 .vefur-olfuss')
          .not('.hours')
              .equalizeHeights();
  
  $('body.bokasafn')
      .find('div.pgmain .article .boxbody, div.pgextra2 .snav .boxbody')
          .equalizeHeights();
  
  // frontpage newsticker
  var fpnewsbody = $('body.home div.toparticle div.boxbody')
          .addClass( 'bodboxy-active' );
  
  fpnewsbody.find('div.item')
      .each(function() {
          $(this)
              .find('h3, div.summary')
                  .wrapAll('<span class="headline"></span>');
      })
      .find('span.headline')
          .bind('click', function(){
              window.location=$(this).find('a:first').attr('href'); 
              return false;
          });
          

  if (fpnewsbody.length)
  {
    var newsitems = fpnewsbody.find('> div.item'),
        visibleIndex = 0,
        switchHlTimeout,
        topnavHd = fpnewsbody.parent().find('h2.boxhead').text(),
        headlinelist = $('<div class="topnav"><h2 class="boxhead">' + topnavHd + '</h2><div class="boxbody"><ul class="newsheadlinelist itemlist"></ul></div></div>'),
        _activeClass = 'active';

    newsitems
        .slice( 1 )
            .hide()
        .end()
        .each(function(i){
            var _this = $(this),
                newsheadline = $('<li>')
                    .addClass( this.className.replace(/(^| )((item|itm\d*|firstitem)( |$))+/g, '$1') )
                    .addClass( i===0 ? _activeClass:'' )
                    .append( _this.find('h3 > a').clone() )
                    .append( '<i class="bottom" />' )
                    .bind('mouseenter', function (e) {
                        var _thisHeadline = this;
                        if (!headlinelist.queue().length)
                        {
                          switchHlTimeout = setTimeout(function () {
                              var visibleIndexAtStart = visibleIndex;
                              visibleIndex = _thisHeadline.listIndex;
                              headlinelist
                                  .queue(function(){
                                      newsitems
                                          .eq( visibleIndexAtStart )
                                              .fadeOut( 125 )
                                              .queue(function(){
                                                  headlinelist.dequeue();
                                                  $(this).dequeue();
                                                });
                                    })
                                  .queue(function(){
                                      headlines
                                          .eq( visibleIndexAtStart )
                                              .removeClass( _activeClass );
                                      $(_thisHeadline)
                                          .addClass( _activeClass );
                                      headlinelist.dequeue();
                                      newsitems
                                          .eq( _thisHeadline.listIndex )
                                              .fadeIn( 400, 'easeIn' );
                                    });

                            }, 350);
                        }
                      })
                    .bind('mouseleave', function (e) {
                        clearTimeout( switchHlTimeout );
                        switchHlTimeout = null;                            
                      })
                    .appendTo( headlinelist.find('ul.itemlist') );
            newsheadline[0].listIndex = i;
          });

    headlinelist.prependTo($('div.pgmain div.wrap'));
    headlines = headlinelist.find('li');

  };
   
  

   //Timed display of marquee header links on 'hat' pages
  $('.sub .toparticle .item')
      .hide()
      .eq(0)
          .show();
      // Still need to code the time interval part...
  
  
  // Toggles Year Index month lists
  $('.yearindex p').hide();  // Hide the month lists
  $('.yearindex h4').click(function() {
      $(this).next('p').toggle();  // When year link is clicked, toggle its month list 
      return false;
  }); 
  
  
});
// **** /jqreq *****