/*
---------------------------------
Roel Van Gils' JavaScript Helpers
Last updated: 17-11-2009
---------------------------------
*/

/* Controleer of een font bestaat (Roel Van Gils, 08-05-2009) */

function font_available(f) {
	$('<span id="fa">m</span>')
		.appendTo('body')
		.css('font-family','Arial')
		.css('font-size','72px');
	x = $('#fa').width()*$('#fa').height();
	$('#fa').css('font-family',f+',Arial')
	y = $('#fa').width()*$('#fa').height();
	$('#fa').remove();
	if ((f == 'Arial') || (x!=y))
		return true;
	else
		return false;
};

/* Placeholder text (Roel Van Gils, 09-05-2009) */

jQuery.fn.dummyText=function(dummyText,colourDimmed,colourDefault) {
  var dummyText = (dummyText == null) ? 'Zoek...' : dummyText;
  var colourDimmed = (colourDimmed == null) ? '#888' : colourDimmed;
  var colourDefault = (colourDefault == null) ? '#111' : colourDefault;
  this
  	.attr('value',dummyText)
  	.focus(function() {
  	  $(this).css('color',colourDefault);
  	  if ($(this).attr('value') == dummyText)
  	    $(this).attr('value','')
  	})
  	.blur(function() {
  	  if ($(this).attr('value') == '')
  	    $(this)
  	      .attr('value',dummyText)
  	      .css('color',colourDimmed)
  	})
  	.css('color',colourDimmed);
}

/* Adds a 'first' and 'last' className to list items (Roel Van Gils, 07-06-2009) */

jQuery.fn.firstLast=function(el) {
  $(el+':first-child').addClass('first');
  $(el+':last-child').addClass('last');
}

/* Adds a className to input elements that matches its 'type' attribute (Roel Van Gils, 07-06-2009) */

jQuery.fn.type2class=function(el) {
  $('input').each(function () {
    $(this).addClass($(this).attr('type'))
  });
}

/* Adds zebrastripes (Roel Van Gils, 15-06-2009) */

jQuery.fn.zebraStripes=function(el) {
  $('tr:odd td').addClass('odd');
}

/* Justify height of columns (Roel Van Gils, 06-02-2009) */	

jQuery.fn.vjustify=function() {
    var maxHeight = 0;
    this.each(function() {
        if (this.offsetHeight>maxHeight) {
          maxHeight=this.offsetHeight;
        }
    });
    this.each(function(){
        $(this).height(maxHeight+"px");
        if (this.offsetHeight>maxHeight) {
          $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};
