/*@cc_on/*@if(@_jscript_version<5.7)try{document.execCommand('BackgroundImageCache',0,1)}catch(e){}/*@end@*/
// encoding: utf-8
  if (window.collapseSections)
  {
    collapseSections.config = {
      'div.sitenav' : {
        handle      : "collapse",
        headSel     : "h2.boxhead",
        startOpen   : 0,
        showControls : 0,  // 0=off; 1=above; 2=below; 3=both
        hoverOpen   : false,
        hoverClose  : false
      },
      'div.dropmenu div.dropmenu' : {
        handle      : "collapse",
        headSel     : "h3.label",
        startOpen   : 0,
        showControls : 0,  // 0=off; 1=above; 2=below; 3=both
        hoverOpen   : false,
        hoverClose  : false
      }
    };
    collapseSections.init();
  }


  if (window.cbBlockToggler)
  {
    cbBlockToggler.triggers = {
      'rf_heilgamur'   : 'gamastaerd'
    };
    cbBlockToggler.init()
  }


/*
  (function(){

    function plural(n) { return n%10 != 1  ||  n%100 == 11; };
    
    function daysLeftToXmas() {
      var now = new Date() ;
      var xmas = (new Date(now.getFullYear(),11,24));
      var msInADay  = 1000*60*60*24;
      return Math.ceil((xmas-now)/msInADay);
    };
    var daysLeft = daysLeftToXmas();

    var xmasText = DOM.get("#pgmain .xmasbox h2")[0];

    if(xmasText)
    {
      if (daysLeft <= 0 || daysLeft > 350)
      {
      text = "Gleðileg jól!";
      }
      else if(plural(daysLeft))
      {
      text = daysLeft + " dagar til jóla";
      }
      else
      {
      text = daysLeft + " dagur til jóla";
      }

      xmasText.innerHTML = text;
    }

  })();*/

jQuery(function($){

  $('body').addClass('js-active');
  //$('a.interview').appendTo('.fpbox1 .boxbody');
  
  $('#cf_samskiptryggir')
      .bind('change', function (E) {
          if ( this.checked == true ) {
            $('#cf_typeoi1,#cf_typeoi2').parents('fieldset').show();
          } else {
            $('#cf_typeoi1,#cf_typeoi2').attr('checked', false).parents('fieldset').hide();
          }
        })
      .trigger('change');

  if (!window.EPLICA_loggedin)
  {
    /*$('#skilmalar').run(function(){
        $('.samthykja-skilmala .fi_chk a').bind('click', function (e) {
            $('#skilmalar h1').trigger('click');
            return false;
          });
        var bb = $(this).find('.boxbody');
        bb.hide();
        $(this).find('h1').wrapInner('<a href="#" />').bind('click', function (e) {
            bb.slideDown();
            return false;
          });
      });*/
  }
  
 /* // Change the header for the twitter feed
  var twitterCheck = function () {
  	var tTimer = setInterval(function() {
  		  	var element = $('.twtr-hd h4 a');
  			if (element.length != 0) {
  				element.text('Skipafréttir'); 				
  				clearInterval(tTimer);
  			};
  	}, 100);
  };
  twitterCheck(); */
  
  if ($('.pmarket').length)
  {
    $('#cf_name, #cf_tel, #cf_email, #cf_enquiry').labelizor();
  }
  
  $('.fpbox1, .fpbox2').find('.boxbody').equalizeHeights();
  $('.fpbox3, .fpbox4').find('.boxbody').equalizeHeights();
  setTimeout(function(){
	    $.equalizeHeights();
	  }, 500);
  
  //begin: svarbox.is
  var svarbox = $('.svarbox'),
      sboxStep1 = '<strong>Veldu deild:</strong><br/> <ul><li>Samskip<br/><a href="#" class="thjonustudeild">&nbsp;&nbsp;- Þjónustudeild</a><br /> <a href="#" class="fjarreidudeild">&nbsp;&nbsp;- Fjárreiðudeild</a></li><li>Landflutningar <br/><a href="#" class="landflutningar">&nbsp;&nbsp;- Þjónustudeild</a></li></ul>',
      popupPage = function(popurl, w, h) {
        var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes,left=50,top=50,width=640,height=550";
        popup = window.open(popurl,"svarbox",windowprops);
      };

  svarbox
    .delegate('.close', 'click', function (e) {
        svarbox.removeClass('active').find('.boxbody').empty();
        e.preventDefault();
       })
    .delegate('.icon a', 'click', function (e) {
        svarbox.addClass('active').find('.boxbody').html(sboxStep1);
        e.preventDefault();	
      })
    .delegate('.thjonustudeild', 'click', function (e) {
        popupPage('https://svarbox.teljari.is/?c=1041&referer=þjónustudeild','640','550');
        e.preventDefault();
      })
    .delegate('.fjarreidudeild', 'click', function (e) {
        popupPage('https://svarbox.teljari.is/?c=1041&referer=fjárreiðudeild','640','550');
        e.preventDefault();
      })
    .delegate('.landflutningar', 'click', function (e) {
        popupPage('https://svarbox.teljari.is/?c=1041&referer=Landflutningar','640','550');
        e.preventDefault();
      });
  //end: svarbox.is

  $('#qstr').labelizor();
  if ( !window.EPLICA_loggedin )
  {
    $('.netfang').mailtoEnabler();
  }
  $('.pagestyle').fontsizer();
  $('form').autoValidate();
  $('#noContentFlashHack').remove();

})();
