jQuery.fn.jcmenu = function (options) {

	var options = jQuery.extend( {
		widthperchar : 10
	},options);

this.each(function(){
	// assign an id to this
	var thisid = 'nav_'+Math.floor(Math.random()*100000);
	$(this).attr('rel', thisid);
	var releq = '[rel="'+thisid+'"]';
	// check if this has a subbnav
	if($(releq+' + div').text() != ''){ // contains subnav so continue		
		// give this div an id
		var divid = thisid+'_div';
		$(releq+' + div').attr('id', divid);
		
		// generate a parent span id
		var spanid = thisid+'_1';
		
		// wrap in span
		$(this).wrap('<span id="'+spanid+'" style="position:relative; float:left; display:block; z-index:50"></span>');
		
		// move in subnavdiv
		$(this).after('<div id="'+divid+'_s">'+$('#'+spanid+' + div').html()+'</div>');
		$('#'+divid).remove();
		$('#'+divid+'_s').attr('id', divid);
		
		// get width
		var dividwidth = 0;
		$('#'+divid+' a').each(function(){
			if($(this).text().length > dividwidth){
				dividwidth = $(this).text().length;
			}
		});
		
		dividwidth = (dividwidth * options.widthperchar)+'px';
		
		// assign css
		$('#'+divid).css({
			width : dividwidth
		}); // closes subnav css
		
		// assign hover functions
				
		$('#'+spanid).hover(function(){
			$('#'+divid).show();
		}, function(){
			$('#'+divid).hide();
		});
				
	} // closes subnav check
	
}); // close this.each

}; // close function
