/* $Id: jquery.dropdownmenu.js 112 2008-07-16 08:10:29Z christofh $ */

/* jQuery compactLinks menus
 * 
 * HTML::
 *   
 *     <ul class="compacts inline" title="optional handle text, if not present a:first text is used">
 *       <li>
 *       	<a href="#1">first</a>
 *       </li>
 *       <li>
 *       	<a href="#2">second</a>
 *       </li>
 *       ...
 *     </ul>
 *   
 * JS::
 * 
 *   $('.compacts').compactLinks({handleClass: 'handle-class'}) // options are optional)
 *      
 *      
 * RESULT::
 * 
 * 		<div class="compactlinks-wrap">
 * 			<b class="handle-class">handle (ul/@title or a:first)</b>
 * 			<ul class="compacts inline">
 * 				...
 *			</ul>
 *		</div>
 * 
 * options
 * -------
 * handleClass
 * 		className that is added to handle which normally simple is a <b> element
 * wrapClass
 * 		className used for wrapping <div>
 * 
 */
jQuery.fn.compactLinks = function(options) {
	var options = options || {}
	var wrapClass = options.wrapClass || 'compactlinks-wrap'
	var handleClass = options.handleClass || ''
	
    return this.each(function(i) {	
        var links = $(this)
        links.css('zIndex', 1000+i)
			 .wrap('<div class="'+ wrapClass + ' ' + (links.attr('class') || '') + '"></div>')
		var wrap = links.parent('div')
		var handle = this.title ? this.title : $('a:eq(0)', links).html()
		this.title = '' // remove to prevent tooltip
		links.hide()
		wrap.prepend('<b class="'+ handleClass + '">'+handle+'</b>').show()
        wrap.hover(
            function() {
                links.show()
            },
            function() {
                links.fadeOut('fast')
            }
        )
    })
}

