jQuery.fn.accordion = function(options){

  var settings = {
    handle:'h2',
    width:0,
    callback:false
  };

  if('object' == typeof options){
    jQuery.extend(settings, options);
  }

  $(this).find(settings.handle).each(function(){

    var handle =    $(this);
    var content =   handle.siblings('div.content');
    var container = handle.parent();

    content.hide();
    handle.css('cursor','pointer');

    handle.click(function(){
      if(content.css('display') == 'none'){
        container.addClass('selected');
        //Webkit doesn't seem to pick up width in time to render height correctly...
        content.css('width', (settings.width? settings.width+'px': 'auto') );
        content.slideDown();
      }
      else if(content.css('display') != 'none'){
        content.slideUp(500,function(){
          container.removeClass('selected');
        });
      }
      container.siblings().find('div.content').each(function(){
        $(this).slideUp();
      });
      container.siblings().removeClass('selected');
      if(settings.callback)
        settings.callback( $(this).text() );
    });

  });

}
