/*
jquery.markupmesh
version 0.1.1.1 alpha
10/08/2008

stephen rushing
copyright 2008

major goal is to include ability to define multiple varNames that will correspond with  different parts of the target element's content
*/

jQuery.fn.meshtml = function(options){
	
	var settings = 
	{
		varNames:["mesh"],
		varValues:["each.html()","each.children('h2').html()"],
		replace:false,
		base:"<div class='mesh-wrapper'>{$mm}</div>"
	};
	
	if (options)
	{
		jQuery.extend(settings, options);
	}
		
	return this.each(function()
		{
			jQueryChild = jQuery(this);
			if(jQueryChild.attr('meshed')!="meshed"){
				//add meshed attribute to ensure object is only meshed once
				jQueryChild.attr('meshed','meshed');
				
				var meshedMarkup = settings.base;				
				
				var j=0;
				for(var m=0;m<settings.varNames.length;m++){
					
					if(settings.varValues.length<m)
					j=m;
					
					settings.varValues[j] = settings.varValues[j].replace("each","jQueryChild");
					
					meshedMarkup = meshedMarkup.replace("{$"+settings.varNames[m]+"}", eval(settings.varValues[j]));				

				}
				
				//if replace is false, insert the html inside of the current element				
				if(settings.replace){
					jQueryChild.before(meshedMarkup);
					jQueryChild.remove();
				}else{
					jQueryChild.html(meshedMarkup);
				}
				
				
			}
		});
		
	
	return jQuery(this);

}

