// 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',
  'anchortags',
  'labelizor',
  'mailtoenabler',
  'equalizeheights',
  'listscroller',
  'q-alistdatesplit',

  function(){
    var $ = jQuery,
        body = $('body').addClass('js-active'),
        article = $('.article'),
        msie =   $.browser.msie   &&  parseInt($.browser.version,10)<9;  // or: $('html').is('.msie');

    var texts = {
        is: {
            newWindow:        'Opnast í nýjum vafraglugga',
            fileText:         'skjal',
            toFacebook:       'Senda á Facebook'
          },
        en: {
            newWindow:        'Opens in new window',
            fileText:         'file',
            toFacebook:       'Share on facebook'
          }
      };
    texts = texts[ $.lang() ]  ||  texts.en;

    if ( body.is('.twocol') && $('.pgmain .wrap').height() < $('.pgextra2 .wrap').height() )
    {
      $('.pgmain .wrap, .pgextra2 .wrap').equalizeHeights();
    }

    if ( body.is('.twocol-reversed') && $('.pgmain .wrap').height() < $('.pgextra1 .wrap').height() )
    {
      $('.pgmain .wrap, .pgextra1 .wrap').equalizeHeights();
    }

    if (!window.EPLICA_loggedin)
    {

      $('.articlelist:has(.date)').addClass('has-date').alistDateSplit({monthAfterDate:0});


      // equal height columns
      var sitems = $('.sbox .item');
      for (var i=0, l=sitems.length; i<l; i+=2)
      {
        sitems.slice(i,i+2).equalizeHeights();
      }
      
      sitems.bind('click', function (e) {
          window.location = $(this).find('a:first').attr('href');
        });
        
        
      $('body.home .focuslist .boxbody')
          .find('.item')
              .each(function () {
                    $(this).find('h3, h4, .summary').wrapAll('<div class="textwrap" />');
                })
          .end()
          .listscroller({
              item: '.item',
              windowSize: 1,
              stepSize: 1,
              animation: 'crossfade',
              paging: true,
              autoScrollDelay: 5000
            })


      //zebra tables
      var tables = $('table');
      tables.not('.details-shares,.details-info').wrap('<div class="tablewrap" />')
      tables.find('tbody tr:nth-child(2n)').addClass('odd');
            
            
      $('.details-image, .details-info')
            .wrapAll('<div class="company-details" />')
            .filter('.details-info')
                .wrap('<div class="details-info-wrap" />')
                .find('td').each(function (i) {
                    $(this).addClass('tcol-'+ (i+1))
                  });


      article.find('.buttons')
          .prepend(
              $('<a class="btnfacebook" href="#">'+ texts.toFacebook +'</a>')
                  .bind('click', function()  {
                      window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location.href),'sharer','toolbar=0,status=0,width=626,height=436');
                      return false;
                    })
            );


      article.find('a.videolink').Req(
          'q-videolinks',
          function() {
            $(this).videoLinks(); //{ vidWidth:'auto',vidHeight:'auto',aspect4x3:false }  Set width and height (default auto) and aspect 4x3 autocalc (default 16x9)
          }
        );


      //tag external urls
      var link, text, useappend, match;
      $('.pgmain a').anchorTags({
                usePatterns:  ['doc', 'pdf', 'xls']
              })
            .filter('.external, .file_pdf, .file_doc, .file_xls')
                    .each(function() {
                        link = $(this);
                        text = '';
                        useappend = false;
                        match = this.className.match(/(^| )file_([a-z]+)( |$)/);
                        if ( match )
                        {
                          text = match[2].toUpperCase() +' '+ texts.fileText;
                        }
                        else if ( $(this).is('.external') )
                        {
                          text = texts.newWindow;
                          useappend = true;
                        }
                        if (text)
                        {
                          link
                              .attr('target', '_blank')
                              .attr('title', $.trim((link.attr('title')||link.text())) +' ('+ text+')')
                              .not(':has(img)')
                              [useappend ? 'append' : 'prepend'](' <span class="icon">('+ text +')</span> ');
                        }
                      });


      // Google maps
      var mapCanvas = $('#map_canvas');
      if (mapCanvas.length)
      {
        // Google maps
        var latlng = new google.maps.LatLng(64.131155, -21.897780),
            myOptions = {
              zoom: 15,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            },
            map = new google.maps.Map(mapCanvas[0], myOptions),
            marker = new google.maps.Marker({
                        position: latlng,
                        map: map, 
                        title:"Nýsköpunarsjóður atvinnulífsins - Kringlunni 7, 3. hæð"
                      });
      }
      
      $('.atvinna').removeClass('box').insertBefore('.pgmain .article .boxbody .buttons');

    } // end loggedin

    //sitemap collapser
    $('.sitemap').Req('treecollapse', function() { 
        $(this).treeCollapse({ 
            branch: 'li:has(ul)', 
            doTogglers: 1, 
            toggler: '> a.expand',
            startOpen: 'ul.level1 > li:has(ul)'
          }); 
        });

    $('#qstr').labelizor();
    $('#noflickerCSS').remove();
    $('.pagestyle').fontsizer();
    $('form').autoValidate();
    Req.loadPageScripts();

  }
);
// **** /jqreq *****

