//jquery.openclose.js

jQuery.fn.extend({
  openClose: function(options) {
   	options = arguments[0] || {};

	$(this).wrap('<div style="overflow: hidden; width: auto;"></div>');
	var openCloseElement = $(this).parent();

	newThis = this;
	newThis = $.extend({
		isOpen: (openCloseElement.height()!="1"?true:false),
		close: function(after){
			if(openCloseElement.height()!="1"){
				openCloseElement.animate({height: "1px"},"slow",function(){
					if(options.close != undefined &&  typeof(options.close)=="function")
  						options.close();
				});
			}
			this.isOpen = false;

			if(typeof(after)=="function")
  					after();
			return this;
		},
		open: function(after){
			this.isOpen = true;
			if(openCloseElement.height()==1){
				openCloseElement.height($(this).height());
				openCloseElement.animate({height: $(this).height()},"slow", function(){
					openCloseElement.height("auto");
  					if(options.open != undefined &&  typeof(options.open)=="function")
  						options.open();
				});
			}
			
			
			if(typeof(after)=="function")
  				after();
			return this;
		}
     }, newThis || {});
	return newThis;
  }
});
