$( document ).ready(function(){

  /*
   * Submenu
   */
  var timer;
  $( '.villadm' ).hover(function(){
    clearTimeout( timer );
    $( '.villadm' ).addClass('h');
    $( '#dropdown' ).show();
  },function(){
    timer = setTimeout("hideMenu()",300);
  });
  $( '#dropdown a' ).hover(function(){
    clearTimeout( timer );
    $( '.villadm' ).addClass('h');
  },function(){
    timer = setTimeout("hideMenu()",300);
  });

  /*
   * H2 Koppen
   */
  $('h1').Heading({url: 'assets/h1/',logo:true});
  $('h2').Heading({url: 'assets/coloured/',logo:false});
  $('h3').Heading({url: 'assets/h2/',logo:true});

});

/**
 * om de dropdown te verstoppen
 */
function hideMenu() {
  $( '.villadm' ).removeClass('h');
  $( '#dropdown' ).hide();
}

/*
 * Heading replacement class
 */
(function($){
  $.fn.Heading = function(options) {
    var defaults = {
      url: 'assets/h2/',
      logo: false
    };
    var options = $.extend(defaults, options);
    return this.each(function() {
      $(this).css('visitbility','hidden');
      var heading = $(this);
      var text = heading.html();
      var img = '';
      if( $(this).hasClass('nocolor') ) {
        options.url = 'assets/h2/';
      }
      if( $(this).hasClass('logo') ) {
        text = text.replace('<SPAN><!-- --></SPAN>','').replace('<span><!-- --></span>','').replace('<br/>','');
        img = '<span><!-- --></span>';
      }
      if( options.logo ) {
        text = text.replace('<SPAN><!-- --></SPAN>','').replace('<span><!-- --></span>','').replace('<br/>','');
        img = '<span><!-- --></span>';
      }
      img += "<img class='replacement' src='" + options.url + escape( text ) + ".png' alt='' title='' />";
      heading.html( img );
      $(this).css('visibility','visible');
    });
  }
})(jQuery);
