// 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',
  'labelizor',
  'imgpop',

  function(){
    var $ = jQuery;

    // labelize search input
    $('#qstr').labelizor();
    //fonsizer 
    $('.pagestyle').fontsizer();
    
    
    $('.home .sbox li:last-child').addClass('last');
    

    //Old JS - can't see that it's serving any purpose but i decided to have it here rather than lose it 


    if (window.collapseSections) {
      collapseSections.config = {
        'div.dropmenu' : {
          handle      : 'dropmenu',
          headSel     : "h2.boxhead"
        },
        'div.droplist div.item' : {
          handle      : 'collapse',
          headSel     : "h3"
        }
      };
      collapseSections.init();
    }



    if (!window.EPLICA_loggedin)
    {

      //Move links to 'embætti' to .buttons1
      $('.linkto a').each(function () {
          $(this).appendTo('.buttons');
        });

      // pngfix for IE6
      if ($.browser.msie && $.browser.version < 7) {
        $('img[src$=".png"]').Req('x/ifixpng', function(){
            $(this).ifixpng();
          });
      }

    //Split up ul's
    $('.splitlist .boxbody')
        .each(function(){
            $(this).find('ul').addClass('col1');
            var col2 = $('<ul class="col2" />'),
                lis = $(this).find('li'),
                count = lis.length;

            lis.slice( 0, count/2 )
                .appendTo( col2 );

            $(this).prepend(col2);
        });

      //zebra tables
      $('tbody tr:nth-child(2n-1)').addClass('odd');
      //$('tbody tr:nth-child(2n)').addClass('even');


      //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)
          })
          .imgPopper({
              curtainColor : '#ffffff',
              curtainOpacity : '0.75',
              yOffset: 15
            });

      //extra date labels within auctions
      $('body.naudungarsolur .sbox .item') // lists
          .each(function() {
                // assuming only two dates are found for each item
            var dates = $(this).find('span.date'),
                date1 = dates.first(),
                date2 = dates.last();
            var dateLabel1 = 'Dags. uppboðs: ' + date1.text(),
                dateLabel2 = 'Birtingardagur: ' + date2.text();
            date1.text(dateLabel1);
            date2.text(dateLabel2);
          });
      $('body.naudungarsolur .article.event') // single event
          .each(function() {
                // assuming only one event date is registered
            var date1 = $(this).find('ul.meta strong').first(),
                date2 = $(this).find('span.date').first();
            var dateLabel1 = 'Dags. uppboðs: ' + date1.text(),
                dateLabel2 = 'Birtingardagur: ' + date2.text();
            date1.text(dateLabel1);
            date2.text(dateLabel2);
          });
          
      //fix 'no articles found' within auctions
      $('body.naudungarsolur .sbox .boxbody p')
          .each(function() {
            if ($(this).text() == 'Engin grein fannst.') {
              $(this).text('Engin uppboð eru skráð næstu þrjá daga.')
            }
          });
    }

    //sitemap collapser
    $('.sitemap').Req('treecollapse', function() { 
        $(this).treeCollapse({ 
            branch: 'li:has(ul)', 
            doTogglers: 1, 
            toggler: '> a.expand',
            startOpen: 'ul.level1 > li:has(ul)'
          }); 
        });

    //remove flicker trick
    $('#noflickerCSS').remove();

    // fontsizer
    $('.pagestyle').fontsizer();

    // validate all forms
    $('form').autoValidate();

  }
);
// **** /jqreq *****

