(function($){
    //
    // plugin definition
    //
    $.fn.dltoggle = function(options){
		 

        // build main options before element iteration
        var opts = $.extend({}, $.fn.dltoggle.defaults, options);

        //  If "leave-open" is not set then close all but the first.
        //
        if ( !opts["leave-open"] )
        {
			this.find('dd').hide();//close all dds added													   
			$("dt").addClass("closed"); //markg - add closed class to all dt tags
        }

     
        // add the click handler
        return this.find('dt').each(function(){
            $this = $(this);
            jQuery(this).click( function() {

                //
                // Toggle the state.
                //
                $(this).next().toggle();

                //
                // Update the images on the dt's to match the state.
                //
                if ( $(this).next().is(":visible") )
                {
					$(this).addClass("open"); 
					$(this).removeClass("closed");

                }
                else
                {
					$(this).addClass("closed"); 
					$(this).removeClass("open");

                }
                return false;
            } );
        } );
     }

     //
     //  exported function - show all dd-children.
     //
     $.fn.dltoggle_show = function(options)
     {
        return $(this).find('dt').each(function(){
            $this = $(this);
            $this.next().show().end();
					$(this).addClass("open"); 
					$(this).removeClass("closed");
        });
     }

     //
     //  exported function - hide all dd-children.
     //
     $.fn.dltoggle_hide = function(options)
     {
        return $(this).find('dt').each(function(){
            $this = $(this);
            $this.next().hide().end();
            					$(this).addClass("closed"); 
					$(this).removeClass("open");
        });
     }

     //
     // plugin defaults
     //
   //  $.fn.dltoggle.defaults = { "leave-open"   : 0 };

     //
     // end of closure
     //
})(jQuery);
