/* This jquery function returns the first element. This is not a chainable function. */
$.fn.head = function() {
  var elems = this.get();
  if (elems.length == 0) return null;
  return elems[0];
}

/* This jquery function makes sure all it's argument are the same height (the height of the
   higest element). A minimum height to ensure can also be passed as argument.
*/
$.fn.sameHeight = function() {
  var elems = this.get();
  var max = 0;
  if (arguments.length > 0) max = arguments[0];
  for (var i = 0; i < elems.length; i++) {
    if (elems[i].offsetHeight > max) max = elems[i].offsetHeight;
  }
  for (var i = 0; i < elems.length; i++) {
    elems[i].style.height = max + "px";
  }
  return $();
}

/* This jquery function sets the opacity of it's arguments. The opacity should be passed as
   as an integer from 0 to 100. Opacity code courtesy of 
   Clagnut http://clagnut.com/sandbox/imagefades/ 
*/
$.fn.set_opacity = function() {
  var opacity = 100;
  var visibility = 'visible';
  
  // Read the required opacity
  if (arguments.length > 0) opacity = arguments[0];
  opacity = (opacity >= 100)?99.999:(opacity < 0?0:opacity);
  
  // See whether we should hide the object
  if (opacity == 0) visibility = 'hidden';
  
  var elems = this.get();
  for (var i = 0; i < elems.length; i++) {
    var obj = elems[i];
    if (obj.style.visibility != visibility) obj.style.visibility = visibility;
    // IE/Win
    obj.style.filter = "alpha(opacity:"+opacity+")";
    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity/100;
    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
  }
}

