
$(document).ready(function() {

  $('.focus').focus();

  /* clear default value on focus */
  $('.def_value').focus(function() {
      var input = this;
      if(($(input).attr('name') == 'q') && ($(input).val() != 'Trefwoord(en)') && ($(input).val() != 'Keyword(s)')) return true;
      if ( $(this).val() == this.defaultValue) $(this).val('');
  });
  /* reset default value on focus lose */
  $('.def_value').blur(function() {
      if ( $(this).val() == "") $(this).val(this.defaultValue);
  });

  /* toggle definition lists */
  $('dt').click(function() {
      var activate = false;
      if(!$(this).hasClass('active')) activate = true;

      $('dt').removeClass('active');
      $('dd').removeClass('active');

      if(activate == true) $(this).addClass('active').next().addClass('active');
  });

  /* expand/collapse top menu items */
  $('#top .menu > li').hover(function() {
      var current_item = this;
      if($(current_item).data('opening') == null) {
          $('#top .menu > li').each(function() {
              $(this).removeClass('active');
              $(this).removeData('opening');
              $(this).each(function() {
                  $('ul', this).hide();
              });
          });
      }
      $(current_item).addClass('active');
      $(current_item).data('opening', true);
      $('ul', current_item).show();
  }, function() {
      var current_item = this;
      $(current_item).data('opening', false);
      window.setTimeout(function(){
        if($(current_item).data('opening') == false) {
            $('ul', current_item).hide();
           // window.setTimeout(function() {
                $(current_item).removeClass('active');
           // }, 750);
        }
      }, 1500);
  });

  /* makes an href container clickable */
  $('#content div.group').click(function() {
      if($('a', this).attr('target') == '_blank') {
          window.open($('a', this).attr('href'), "Unisafe");
      } else {
          window.location = $('a', this).attr('href');
      }
  });

  /* lightbox */
  var lightboxparams = {
      overlayBgColor: '#808080',
      overlayOpacity: 0.6,
      imageLoading: '/style/lightbox-ico-loading.gif',
      imageBlank: '/style/lightbox-blank.gif',
      imageBtnClose: '/style/lightbox-btn-close.gif',
      imageBtnPrev: '/style/lightbox-btn-prev.gif',
      imageBtnNext: '/style/lightbox-btn-next.gif'
  };

  $('a.lightbox').lightBox(lightboxparams);

  $('#content ul.tabs li').click(function() {
      var li = this;

      var offset = 0;

      var start = $('a', li).attr('href').substring(1,0).toLowerCase();

      if(start != '#') return true;

      $('#content ul.tabs li').removeClass('active');
      $('#content ul.tabs li .arrow').html('>');
      $('#content .product-specs .tab-content').hide();

      $('.arrow', li).html('<img src="/style/tab_active.gif" alt=">">');
      $('#content .product-specs .loader').show();

      $('#content .product-specs .loader').hide();

      $(li).addClass('active');

      switch($('a', li).attr('href'))
      {
        case '#specifications':
          $('#content .product-specs .specifications').show();
          offset = $('#content .product-specs .specifications').offset().top;
          break;
        case '#order':
          $('#content .product-specs .order').show();
          offset = $('#content .product-specs .order').offset().top;
          break;
        case '#projects':
          $('#content .product-specs .projects').show();
          offset = $('#content .product-specs .projects').offset().top;
          break;
        case '#documentation':
          $('#content .product-specs .documentation').show();
          if($('#content .product-specs .documentation')) {
            offset = $('#content .product-specs .documentation').offset().top;
          } else {
            offset = 2000;
          }
          break;
        default:
          break;
      }
      $('html, body').animate({ scrollTop: (offset-15) });

      return false;
  });

  $('#footer .print').click(function() {

      window.print();

      return false;
  });

});
