(function($){

	$.fn.expandable = function(params){
	
		// give the options their default value
		options = $.extend({
			
		}, params);
			
		openclose = '<a class="expandLink collapsed" title="Click to show or hide explanations and examples" href="#">open</a>';
		
		this.each(function(){
			
			$obj = $(this);
			
			
			$obj.addClass( 'collapsed' );
			
			if( $obj.children().length > 1 ){ // temporary fix without content
				$obj.find( 'h3' ).wrapInner( '<a href="#" title="Click to show or hide explanations and examples" />' );					
				$obj.append(openclose);
				$obj.hover( function(){
					
					$(this).toggleClass( 'hover' );
					
				});
			}else{
				$obj.find( 'h3' ).wrapInner( '<span />' );
			}
			
			
			$obj.find( 'h3, a.expandLink' ).click(function(){
			
				$par = $(this).parent();
				
				if( $(this).hasClass( 'expandLink' )){				
					$linkToggle = $( this );				
				}else{					
					$linkToggle = $par.find( 'a.expandLink' );				
				}
				
				if( $par.hasClass( 'collapsed' ) ){					
					$par.removeClass( 'collapsed' );
					$linkToggle.html( 'close' );
					
				}else{
					
					$par.addClass( 'collapsed' );
					
					$linkToggle.html( 'open' );
					
				}
				
				return false;
				
			}); // h3 click
			
			
		}); // each
		
		return this;
	
	} // expandable
	
})(jQuery);
