$(document).ready(function () {
  $('html').css('overflow-y', 'scroll');
  $('.ie7 img').css('-ms-interpolation-mode', 'bicubic');
  $('.openModal').click(function (e) {
    $('#basic-modal-content').modal({
      opacity: 80,
      closeHTML: '<a href="#" class="closeModal">Sluit dit venster</a>'
    });
    e.preventDefault();
    var modalhref = $(this).attr('href');
    var modalrel = $(this).attr('rel');
    $('.simplemodal-data').prepend('<iframe src="' + modalhref + '/' + modalrel + '" frameborder="0" width="400px" height="400px" />');
    $('.closeModal').click(function (e) {
      e.preventDefault();
      $.modal.close();
    });
  });
  $(".col-495 a[href^='http://catalogus']").addClass('noexternal');
  $(".col-495 a[href^='http://']:not(.noexternal)").each(function () {
    $(this).addClass('external');
    $(this).attr('target', '_blank');
  });

  $('.togglebox').addClass('js');
  $('.togglebox dt').toggle(function () {
    $(this).next('dd').slideDown();
  }, function () {
    $(this).next('dd').slideUp();
  });

  $('.meta-controls .display').after('<li class="fontsize"><span class="hidden">Zet de tekengrootte op:</span><a href="#" class="pr100" rel="100" title="Zet de tekengrootte op normaal"><span class="hidden">Normaal </span>a</a>    <a href="#" class="pr150" rel="125" title="Zet de tekengrootte op groot"><span class="hidden">Groot </span>A</a>    <a href="#" class="pr200" rel="150" title="Zet de tekengrootte op extra groot"><span class="hidden">Extra groot </span><strong>A</strong></a></li>');
  $('.meta-controls .display input[type=submit]').hide();

  $('#zoeken input[type=text]').each(function () {
    var defaultText = 'typ hier uw zoekwoord';
    $(this).val(defaultText);
    $(this).focus(function () {
      var userInput = $(this).val();
      if (userInput == defaultText) { $(this).val(''); }
    });
    $(this).blur(function () {
      var userInput = $(this).val();
      if (userInput == '') { $(this).val(defaultText); }
    });
  });
  $('.col-wrapper.border').each(function () {
    var colHeight = $(this).height();
    $(this).find('.col-247').css('height', colHeight);
    $(this).find('.col-235').css('height', colHeight);
  });

  if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
    $('.ie7 ul.meta-controls .fontsize a,.ie7 ul.specific-list .phone,.ie7 ul.meta-nav a,.ie6 ul.meta-controls .fontsize a,.ie6 ul.specific-list .phone,.ie6 ul.meta-nav a').css('zoom', '1');
  }

  var ua = $.browser;
  if (ua.mozilla) {
    $('#zoeken input[type=submit]').css('margin', '0 0 0 -1px');
  }

  $('#ddCssStyle').change(function () { $(this).parents('form').submit(); });
  $('.fontsize a').click(function () {
    var fsClass = $(this).attr('rel');
    $('input[name=fontSize]').val(fsClass);
    $(this).parents('form').submit();
    return false;
  });
  
  $('.AxForm textarea').each(function(){
    $(this).after('<p><span class="charsRemaining">400</span> karakters over</p>');
    $(this).keyup(function(){
      var max = parseInt('400');
      if($(this).val().length > max){
        $(this).val($(this).val().substr(0, max));
      }
      $(this).parent().find('.charsRemaining').html((max - $(this).val().length));

    });
  });

});

