function text_shape(o, options, w1, h1, f1, w2, h2, f2){
	var self = this,
		options = options || {},
		settings = {
			left_class:'l',
			right_class:'r',
			wrapper_class:'shape_text',
			object_class:'shape_text_box',
			cssText:['.shape_text i{ display:block; height:1em; font-size:1em; width:1px; background:red; position:relative; }',
					'.shape_text i.l{ float:left; clear:left; }',
					'.shape_text i.r{ float:right; clear:right; }',
					'.shape_text_box{ overflow:hidden; }'].join('')
		},
		em = self.em ? self.em.height() : ( self.em = $("<div></div>").css({height:"1em", width:0, position:"absolute", left:-10000, top:-10000}).appendTo(document.body)).height();
	
	self.objects = self.objects ? self.objects : [];
	if(!self.styleSheet) cssText(options.cssText || settings.cssText);
	!o || function(){
		var i = -1;
		(i = $(self.objects).index(o)) != -1
			? (self.current = self.objects[i]) &&
			  $(self.current).data("options", $.extend($(self.current).data("options"), options))
			: (
				(self.current = o.length ? o[0] : o) &&
				(self.objects[self.objects.length] = self.current) &&
				$(self.current).data("options", options).addClass(settings.object_class)
			);
	   
		self.options = $(self.current).data("options");
	}();

	function cssText(cssText) {
		self.styleSheet || (self.styleSheet = document.createStyleSheet ? document.createStyleSheet() : $('<style></style>').appendTo("head"));
		return document.createStyleSheet ? (self.styleSheet.cssText = cssText) : self.styleSheet.html(cssText);
	}

	function shy(){
		return { remove:remove, create:create, shy:shy };
	}

	function remove(){
		$('.'+settings.wrapper_class, self.current).remove();
		return { remove:remove, create:create, shy:shy };
	}
   
	function create(){
		remove();
		document.body.className +='';
		var counter = 0;
		while(iteration($(self.current).height()) - parseInt($(self.current).height()/em) < 0) {
			if(++counter > 2) break;
		}
		return { remove:remove, create:create, shy:shy };
	}

	function iteration(height){
		remove();
		var step = em/height,
			wrapper = $("<ins></ins>").attr("class", settings.wrapper_class).prependTo(self.current),
			counter = 0;
			//alert(em/step);
		for(var t=0; t<=1; t+=step){
			if(self.options.f1) {
				$("<i></i>").attr("class", settings.left_class).css("paddingLeft", self.options.f1(t, t*height)).appendTo(wrapper);
			}
			if(self.options.f2){
				$("<i></i>").attr("class", settings.right_class).css("paddingLeft", self.options.f2(t, t*height)).appendTo(wrapper);
			}
			counter++;
		}
		return counter;
	}
   
	return { remove:remove, create:create, shy:shy };
}

