/*@cc_on/*@if(@_jscript_version<5.7)try{document.execCommand('BackgroundImageCache',0,1)}catch(e){}/*@end@*/
// encoding: utf-8

(function(){
  if (window.autoValidate)
  {
    autoValidate.init();
    defangForm.resetButtons.init();
  }
  if (window.mailtoEnabler)
  {
    mailtoEnabler.init();
  }
  if (window.fontSizer)
  {
    fontSizer.init();
  }

  if (window.stepPageWidth)
  {
    stepPageWidth.init([980]);
  }

  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()
  }

  if (window.mailtoEnabler)
  {  
    mailtoEnabler.init();
  }

  if(window.labelizor) {
    labelizor.init(["qstr","bookingno"]);
  }

  var c = DOM.$("noContentFlashHack");
  if (c) { c.parentNode.removeChild(c); }
/*
  (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;
    }

  })();
*/

  (function(){
    var tabs = DOM.get( 'div.fnav' );
    var activeClass = 'fnav-current';
    var currentTab;

    // hover event
    function switchTo ( e ) {
      if (currentTab) { DOM.removeClass( currentTab, activeClass ); }
      DOM.addClass( this, activeClass ); 
      currentTab = this;
    }

    // init  
    if (tabs && tabs.length) {
      for (var i=0; i < tabs.length; i++) {
      
        var focusElm = DOM.get('h2.boxhd a', tabs[i])[0];
        
        if(focusElm) {
          Event.add( focusElm, 'focus', switchTo, tabs[i]);
        }
        
        Event.add( tabs[i], 'mouseover', switchTo );
        
      }
      DOM.addClass( tabs[0], activeClass ); 
      currentTab = tabs[0];
    }
  })();


  (function(){

    function plural(n) { return n%10 != 1  ||  n%100 == 11; };
    
    function daysLeftToXmas() {
      var now = new Date() ;
      var tdate = (new Date(now.getFullYear(),12-1,8));
      var msInADay  = 1000*60*60*24;
      return Math.ceil((tdate-now)/msInADay);
    };
    var daysLeft = daysLeftToXmas();

    var targetText = DOM.get("div.pagebody div.fbox h2")[0];

    if(targetText)
    {
      var text = daysLeft;
      if (daysLeft <= 0 || daysLeft > 350)
      {
        text = "The Service web is open!";
      }
      else if(plural(daysLeft))
      {
        text = "<strong>" + text + "</strong> days <br /> until <span>the Service web</span> opens";
      }
      else
      {
        text = "<strong>" + text + "</strong> day <br /> until <span>the Service web</span> opens";
      }
      targetText.innerHTML = text;
    }

  })();


})();


(function($){

  $('body.home .containerno label')
      .bind('click', function() {
          $(this).hide()
          $('#containerno1').focus();
        });
        
  $('a.assistance')
      .bind('click', function(){
          window.open( $(this).attr('href'), 'popupInfo', 'width=700,height=500' );
          return false;
      });
      
  $('div.serviceform form')
      .bind('submit', function(){
        
          $('input#tracking').attr('value', $('#containerno1').attr('value') + '/' + $('#containerno2').attr('value'));
          
          window.open( $(this).attr('action'), 'popupWin', 'width=700,height=500' );
          
      });
  
  /* $('a.popupById').popup(); */
  
  
  $('.home a.interview').appendTo('.home div.fpnewslist div.boxbody');

})(jQuery);


