(function($) {

	$.fn.foldout = function(options){
		
		var defaults = {
				'selectedstyle' : 'dropdownselected',
				'hoverstyle' : 'dropdownhover'
		  };
		
		var opts = jQuery.extend(defaults, options);


									 		
		$(this +".jqdropdownbox a").unbind().click( function() {
		 			this.foldout = false;
					$(".jqdropdownbox").animate({height:"hide",width:"hide"},100);
					$(".jqdropdown").removeClass(opts.selectedstyle);
		});											
														
		//bind item clicks
		$(this +".jqdropdown a").unbind().click( function() {
      var foldout = false;
      var wrapcontainer = jQuery(this).parent().parent();					
				if(! this.foldout){													 
		      jQuery(wrapcontainer).find(".jqdropdownbox").animate({height:"show"},100,function(){ jQuery(wrapcontainer).find(".jqdropdownbox").animate({height:"show",width:"show"},300);});
		      jQuery(this).parent().addClass(opts.selectedstyle);
					this.foldout =true;
				}else{
		      jQuery(wrapcontainer).find(".jqdropdownbox").animate({height:"hide",width:"hide"},300,function(){jQuery(wrapcontainer).find(".jqdropdownbox").animate({height:"hide"},100);});
		      jQuery(this).parent().removeClass(opts.selectedstyle);
					this.foldout = false;
				}
				return(false);
		  }).hover(function(){
			  jQuery(this).parent().addClass(opts.hoverstyle);
		  },function(){
			  jQuery(this).parent().removeClass(opts.hoverstyle);
		  });
	};
	
})(jQuery);