window.ttfconfig = {
	//copy:true,
  ttfCustomDriver: 'http://www.hypnotherapienederland.nl/font.php?'
}


var XXDBG=false;
/**
 * If document.getElementsByClassName does not exist, define it
 * It is supported at least from FireFox 3, maybe some more browsers
 */
(function(){
	if (!document.getElementsByClassName)
	{
		document.getElementsByClassName = function(clsName)
		{
			var retVal = new Array();
			var els = document.getElementsByTagName("*");
			clsname = clsName.toLowerCase();

			for(var i = 0;i < els.length;i++)
			{
				if(els[i].className.indexOf(" ") >= 0)
				{
					var classes = els[i].className.split(" ");
					for(var j = 0;j < classes.length;j++)
					{
						if(classes[j].toLowerCase() == clsName)
						{
							retVal.push(els[i]);
							break;
						}
					}
				}
				else if(els[i].className.toLowerCase() == clsName)
				{
					retVal.push(els[i]);
				}
			}
			return retVal;
		}
	}
})();

//utility method
function var_dump(obj,ret,dofunc)
{
	var s='';
	dofunc=dofunc||false;
	for (var k in obj)
	{
		var isf = typeof(obj[k])=='function';
		//if (obj.hasOwnProperty(k) && typeof(obj[k])!='function')
		//if (obj.hasOwnProperty(k) && typeof(obj[k])!='function')
		if (!isf || (isf && dofunc))
		{
			s+=k+'='+obj[k]+'\n';
		}
	}
	if (!ret) alert(s);
	else return s;
}

/*
var tffHide=tff_config.hide||"body";
if(tff_config.hide!==false)
{
	window._tff26=function(id)
	{
		setTimeout(
			function(){
				var el=document.getElementById(id);
				if(el){((/safari|konqueror/i.test(uA))?el.parentNode.removeChild(el):el.disabled=true);}
			}
		,1)
	};
	if(typeof(tffHide)!="string")
	{
		tffHide="body"
	}
	document.write("<style id=\"tffHide\" type=\"text/css\">"+tffHide+"{"+((document.compatMode!="CSS1Compat")?"filter:Alpha(opacity=0);":"position:relative;left:-"+2*screen.width+"px;")+"}</style>");
	setTimeout("_tff26('tffHide');",2000);
}

*/

/* define the main TTF object and some statics */
var ttf={};
ttf.cssutil=null;
ttf.bodyFontSize=null;
ttf.ua=navigator.userAgent;
ttf.isOpera=/opera/i.test(ttf.ua);
ttf.isKonquerer=/konquerer/i.test(ttf.ua);
//ttf.isOpera = window.opera && opera.buildNumber;
ttf.isWebkit = /Webkit/.test(ttf.ua);
ttf.isIE = !ttf.isWebkit && !ttf.isOpera && (/MSIE/i.test(ttf.ua));// && /Explorer/i.test(ttf.ua.appName));
ttf.isIE6 = ttf.isIE && /MSIE [56]/gi.test(ttf.ua);
ttf.isIE7 = ttf.isIE && /MSIE [7]/gi.test(ttf.ua);
ttf.isGecko = !ttf.isWebkit && /Gecko/gi.test(ttf.ua);
ttf.isMac = /Mac/gi.test(ttf.ua); //ttf.ua.indexOf('Mac')!=-1;
ttf.isAir = ttf.isAdobe = /adobeair/i.test(ttf.ua);
ttf.isIObject = /(iPad|iPhone)/i.test(ttf.ua);

/* define some static util methods */
ttf.timestamp=function(){return new Date().getTime();}
ttf.trim=function(v){return v?v.replace(/^\s*|\s*$/g,''):v;}
ttf.rtrim=function(v){return v?v.replace(/\s*$/g,''):v;}
ttf.ltrim=function(v){return v?v.replace(/^\s*/g,''):v;}
ttf.unquote=function(v){return !v?v:v.replace(/(\'|\")/g,'');}
ttf.ucfirst=function(v){return !v?v:v.substring(0,1).toUpperCase()+v.substring(1);}
ttf.escape=function(v){return !v?v:v.replace(/\+/g,'%2B').replace(/\s/g,'+').replace(/@/g,'%40');}
//ttf.ttfEscape=function(v){return escape(v.replace(/\+/g, "%2B").replace(/\s/g, "+")).replace(/@/, "%40");}
ttf.htmlspecialchars=function(v){
	if (!v)return '';
	v=v.replace(/\&/gi,'&amp;');
	v=v.replace(/>/gi,'&gt;');
	v=v.replace(/</gi,'&lt;');
	v=v.replace(/\"/gi,'&quot;');
	v=v.replace(/\'/gi,'&#039;');
	return v;
};

/* define some static conversion util methods */
ttf.pt2px=function(pt){return !pt?pt:parseFloat(pt)/0.75;}
ttf.pc2px=function(pc){return !pc?pc:(parseFloat(pc)*12)/0.75;}
ttf.in2px=function(v){return !v?v:(parseFloat(v)*72)/0.75;}
ttf.cm2px=function(cm){return !cm?cm:(parseFloat(cm)*28.346)/0.75;}
ttf.mm2px=function(cm){return !cm?cm:(parseFloat(cm)*2.835)/0.75;}

ttf.defaultSizes = {
	'xx-small':'60%',
	'x-small':'75%',
	'small':'89%',
	'medium':'100%',
	'large':'120%',
	'x-large':'150%',
	'xx-lage':'200%',
	'smaller':'89%',
	'normal':'100%',
	'larger':'120%',
	'1':'60%',
	'2':'89%',
	'3':'100%',
	'4':'120%',
	'5':'150%',
	'6':'200%',
	'7':'300%'
};

ttf.settings={
	fontreg:'',
	fontcache:{}
}

ttf.__debug=[];
ttf._debug=function(m){ttf.__debug.push(m);}
ttf.cleardebug=function(){ttf.__debug=[];}
ttf.showdebug=function(id){
	var d=ttf.__debug.join('\n');
	if (!id || !document.getElementById(id)) alert(d);
	else document.getElementById(id).innerHTML = d;
	ttf.cleardebug();
};

ttf.config={};
ttf.config._setup=function(cfg)
{
	var _config={
			script:"ttfu.js",
			blankImage:"tff_blank.gif",

			testimage:true,
			onfailtest:null,
			//testservice:false,

			imagetype:"",
			setlinkverticalalign:"middle",
			minimumfontsize:0,
			increasefontsize:0,
			maxnodes:0,
			maxwords:0,
			maxtime:4,
			fixsizetags:true,
			fixalphaimageloadersizebug:true,
			fixrelativefontsize: true, 
			fixlineheight: true,

			transparentbackground:null,
			delayedloading:true,
			hidetext:true,
			start:true,
			fixTransparency:false,
			pngForceFix:false,

			cache:false,
			cachedirs:false,
			cachefiles:false,
			encodeurls:false,

			replacements:'',
			lazyreplace:false,
			styleattribute:true,
			setreplaceddisabled:false,
			quotesrules:true,
			stylesheetrules:true,
			linkedstylesheets:true,
			importstylesheets:true,

			oncomplete:false,
			path: false,
			ttfdriver: 'tff.php?',
			ttfcustomdriver: 'http://62.45.208.79/prot/eszenzz.nl/DSONE_CMS/font.php?',
			debug:false,

			fonttag:true,
			fontface:true,
			fontstretch:true,
			fontweigth:true,
			fontstyle:true,
			fontvariant:true,

			textdecoration:true,
			removetextdecoration:false,
			fixtextdecorationnowrap:true,
			letterspacing:true,
			textproperties:true,
			hover:true,

			copy:false
			//,start:false
			,wrap:false //whether or not to wrap the full text, or display it as a whole
		};
	var _defCfg={
			"cachedir": "cache",
			"createcachefiles": "cachefiles",
			"createcachedirs": "cachedirs",
			"backgroundtransparent":"transparentbackground",
			"encode": "encodeurls",
			"replace": "replacements",
			"onreplace": "oncomplete",
			"afterreplace": "oncomplete",
			"afterreplacement": "oncomplete",
			"autostart": "start",
			"autorun": "start",
			"run": "start",
			"testimagesupport":"testimage"
		};

	var wcfg = cfg||window.ttf.config;
	//wcfg.path = wcfg.path || window.tff;
	for(var v in wcfg)
	{
		var p=v.replace(/([_\-]+)/g,"").toLowerCase();
		p=_defCfg[p]||p;
		_config[p]=wcfg[v];
	}
	if(_config.start===false)
	{
		wcfg.start=true;
	//	if(tffHide)
	//	{
	//		_tff26("tffHide");
	//	}
	//	return;
	}
	if(typeof(_config.wrap)!="undefined")
	{
		_config.nowrap=!_config.wrap;
	}
	//if (_config.getelementsbycss) getElementsByCSS = _config.getelementsbycss;
	_config.imagetype=_config.imagetype.toLowerCase()||"png";
	if(_config.transparentbackground==null)
	{
		_config.transparentbackground=(_config.imagetype=="png")
	}
	_config.fixTransparency=(_config.transparentbackground && !ttf.isIE7 && ttf.isIE6 && _config.imagetype=='png');
	_config.pngForceFix=(_config.imagetype=="png"&&(ttf.isIE7||_config.fixTransparency));
	// Now, if we have forced transparency fix, we need to setup an alpha loader method
	if(_config.fixTransparency&&!_config.sprite&&!window._ttfLoadAlpha)
	{
//ttf._debug('TTF LOAD ALPHALOADER');
		window._ttfLoadAlpha=function()
		{
			if(this.src.toString().indexOf(cfg.blankImage)>-1){return}
			this.setAttribute("mouseout",this.src);

			if(_config.fixalphaimageloadersizebug)
			{
				if(!this.newimage)
				{
					this.style.visibility="hidden";
					var img=new Image();
					img.onload=function()
					{
						_ttfLoadAlpha.apply(this.obj);
						this.obj=null;
						this.onerror=null;
						this.onload=null;
					};
					img.obj=this;
					this.newimage=img;
					this.newimage.src=this.src;
					return;
				}
				else
				{
					var s=this.style;
					s.visibility="visible";
					s.width=this.newimage.width+"px";
					s.height=this.newimage.height+"px";
					this.newimage.obj=null;
					this.newimage.onload=null;
					this.newimage.onerror=null;
					this.newimage=null
				}
			}
			else
			{
				var s=this.style;
				s.width="auto";
				s.height="auto";
				s.width=this.offsetWidth+"px";
				s.height=this.offsetHeight+"px"
			}
			s.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\""+this.src.replace(/%/g,"%25")+"\",sizingMethod=\"crop\")";
			this.onload=null;
			if (this.getAttribute("tff_line-height") && !this.parentNode.getAttribute("tff_line-height_set"))
			{
				_tffSetLineHeight.apply(this);
			}
			this.src=_config.path+_config.blankImage;
		}
	}
	//append text properties config
	_config.textprops=new Array("shadow","shadow-opacity","opacity","rotation");
	if(_config.textproperties)
	{
		for(var i=0,l=_config.textprops.length,p;i<l;i++)
		{
			if(p=_config.textprops[i].replace(/\-/,""))
			{
				_config["text"+p]=true;
			}
		}
	}
	//
	_config._doRenderTextProps=false;
	for(var i=0,l=_config.textprops.length,p;i<l;i++)
	{
		if(_config._doRenderTextProps=((p=_config.textprops[i].replace(/\-/,""))&&_config["text"+p]&&(!ttf.isSafari||p!="shadow")))
		{
			break;
		}
	}
	return _config;

}

ttf.getDriver=function(nocache)
{
	var cfg=window.ttf.config;
	nocache=nocache||false;
	return (!nocache&&cfg.cache)||cfg.ttfcustomdriver||cfg.ttfdriver;
}


window.ttf=ttf;
window.ttf.config=new ttf.config._setup( window.ttfcfg||window.ttfconfig||{} );

// fallback method for image errors
// Only when cache is detected will this method continue.
window._onCacheFail=function()
{
	if(this.src.indexOf("tff.php?f=")>-1)
	{
		return;
	}
	this.style.visibility="hidden";
	this.onload=function()
	{
		this.style.visibility="";
		if(window._ttfLoadAlpha)
		{
			_ttfLoadAlpha.apply(this);
		}
		else
		{
			if(this.getAttribute("tff_line-height"))
			{
				_tffSetLineHeight.apply(this);
			}
		}
	};
	// we should remove this image and replace the old 
	//  real text?
	//this.onerror = function(){};
	this.onerror = null;
	var src=this.src;
	this.src=ttf._cache2url(src);
};


function ttfu_init()//cfg)
{
	var cfg=window.ttf.config;
	cfg.path=cfg.path||getScriptPath(cfg.script);
	ttf.__load();
}

// loading mechanism used for kickstarting 
// the ttf replacement
ttf.__load=function(theObj,cfg)
{
	var cfg=cfg||window.ttf.config;

	ttf.cssutil = ttf.cssutil || new CSSUtil();
	ttf.cssutil.importedstyles = cfg.importstylesheets;
	ttf.cssutil.linkedstyles = cfg.linkedstylesheets;
	ttf.cssutil.inlinestyles = true;
	ttf.cssutil.removeimports = false;

	//this should be done somewhere... not here though :S
	if(theObj&&theObj.setAttribute)
	{
		theObj.setAttribute("tff_replaced",null);
		theObj.setAttribute("tff_line-height_set",null)
	}
	if(cfg.testimage===false)
	{
		start();
	}
	else
	{
		var imgx=new Image();
		imgx.onload=start;
		imgx.onerror=function(){ttf.dispatchOn('onfailtest',null,'ttf delayed loader')};
		cfg.path=cfg.path||getScriptPath(cfg.script);
		var blankImage=cfg.path+cfg.blankImage;
		if(cfg.testservice)
		{
			blankImage+="?"+(new Date).getTime();
		}
		imgx.src=blankImage;
	}
}

	function start(theObj) //theObj can be removed????
	{
ttf._debug('start [this='+typeof(this)+'|'+(this.constructor?this.constructor.toString():'')+']');
		this.onload=null;
		this.onerror=null;
//		_28=null;
//		parsedItems=0;
//		replacedItems=0;
//		document.tff_start_time=tStart;
//		tStop=0;
//		runTime=0;
		var cfg=window.ttf.config;
		cfg.path=cfg.path||getScriptPath(cfg.script);

		//create base image (used for cloning)
		img=document.createElement("IMG");
		img.className="tff_img";
		if(cfg.sprite)
		{
			img.src=cfg.path+cfg.blankImage;
		}
		var s=img.style;
		s.display="inline";
		s.padding=s.margin="0px";
		s.border=cfg.imageborder||"none";
		if(cfg.delayedloading&&!cfg.sprite&&(ttf.isIE||ttf.isOpera))
		{
			s.visibility="hidden";
		}
		s.width="auto";
		s.height="auto";
		s.verticalAlign=cfg.imagealign||"middle";

		//create ttf images
		document.tff_inserted_images=new Array(0);
		if(theObj)
		{
			ttf._createTTF(theObj)
		}

//[PV_FREE] PRO VS FREE [PRO RENDERS ALL, FREE RENDERS H1-H4]
//		for(var t=1;t<4;t++){
//			var col=document.getElementsByTagName("H"+t);
//			for(var c=0,l=col.length,txt;c<l;c++){ttf._createTTF(col[c]);}
//		}
//[PV_FREE_END]
//[PV_PRO] (PRO RENDERS ALL)
		// prepare
		var fonts;
		if (cfg.replacements)
		{
			//simple direct configured replacement, disable stylesheet handling
			cfg.stylesheetrules = cfg.stylesheettext = false;
		}
		if (cfg.stylesheettext)
		{
			//stylsheet text handling, disable stylesheet rules handling
			cfg.stylesheetrules = false;
		}
		if (cfg.stylesheetrules && (ttf.isOpera || ttf.isKonqueror))
		{
			//set stylesheet text handling, disable stylesheet rules handling
			cfg.stylesheetrules = false; //[Opera won't handle this]
			cfg.stylesheettext = true;
		}
		if (!ttf.isOpera || ttf.isOpera8)
		{
			//only opera [except opera8] handles quotes
			cfg.quotesrules = false;
		}
		if (cfg.fontface && ttf.isFireFox35)
		{
			// FireFox 3.5 has full font-face support...
			cfg.fontface=false;
		}

		// execute
		var rawFontCss = '';
		if (cfg.stylesheettext || cfg.fontface || cfg.fontstretch || cfg._doRenderTextProps)
		{
			rawFontCss = ttf.cssutil.getCssSource();
		}
		ttf.parseFontFaces(rawFontCss);
		ttf.applyTTFAttributes(rawFontCss);
		ttf.applyFontTags();
		ttf.fixSizeTags();
		ttf.applyReplacements();
		ttf.applyStyleSheetText(rawFontCss);
		ttf.applyStyleAttributes();
		ttf.applyStyleSheetRules();
//[PV_PRO_END]

		//complete...
		img=null;
		ttf.dispatchOnComplete();
		ttf.dispatchOnLoad();
		ttf.dispatchDelayLoad();

//		tStop=getTimestamp();
//		document.tff_end_time=tStop;
//		if(tffHide)
//		{
//			_tff26("tffHide");
//		}
//		finish();

		var __sxx=var_dump(ttf.settings, true)+'\n'+var_dump(cfg,true);
		var d=document.getElementById('debugger');
		var msg=__sxx + '\n' + ttf.__debug.join('\n');
		if (d)
		{
			if (typeof d.innerText != 'undefined')d.innerText=(msg);
			else if (typeof d.innerHTML != 'undefined')d.innerHTML=ttf.htmlspecialchars(msg);
		}
		//else alert(msg);
		if (cfg.debug)ttf.showdebug();else ttf.cleardebug();

	}

//ttf.Proto=function(cfg)
//{
//	cfg=cfg||window.ttf.config;
//}

// ----------------------------------
// -- Raw TTF CSS Utility methods
// this method should be more generic, i.e. belongs to another class or so.
// also, it should work with the TTFCache (Font Cache Utility), where the results of these are stored.
// Therefore, belongs there as a function? (including handle font name parsing...)
ttf.parseFontFaces=function(rawCss,cfg)
{
	cfg=cfg||window.ttf.config;
	// find font faces and put in cache...
	if (cfg.fontface)
	{
		// parse font-face definitions from raw css source
		//@font-face { font-family: XXXX; src: url(XXXX.ttf); }
		var cch=[];
		var re = new RegExp(/@font-face([^{]*)\{([^}])+\}/gi);
		if (fonts = rawCss.match(re))
		{
			for (var i=0; i<fonts.length; i++)
			{
				// add to cache | cacheregex
				var font = ttf.locateFontName(fonts[i]);
				ttf.settings.fontcache[font] = ttf.parseFontFaceUrl(fonts[i]);
ttf._debug('[cfg.fontface] located font-face: '+font+' => '+ttf.settings.fontcache[font]);
				cch.push(font);
			}
			ttf.settings.fontreg = '('+cch.join('|')+')';
		}
		cch=null;
	}
}

ttf.applyTTFAttributes=function(rawCss,cfg)
{
	cfg=cfg||window.ttf.config;
	if (cfg.fontstretch)
	{
ttf._debug('[cfg.fontstretch] TODO | UNTESTED');
		// set raw ttf attributes on elements, so they can be handled later
//		setTTFAttributesFromCss(rawCss, 'font-stretch');
	}

	if (cfg._doRenderTextProps)
	{
ttf._debug('[cfg._doRenderTextProps] TODO | UNTESTED');
		// apply text properties
		for (var i=0; i<cfg.textprops.length; i++)
		{
			var p=cfg.textprops[i];
			var k=p.replace(/\-/g,'');
			if (k && cfg['text'+k] && (!ttf.isSafari || p!='shadow'))
			{
				// set raw ttf attributes on elements, so they can be handled later
//				setTTFAttributesFromCss(rawCss, 'text-'+p);
			}
		}
	}
}
// -------------------------------------
// -- various applicators for style
ttf.applyStyleSheetText=function(rawCss,cfg)
{
	//handle stylesheet text, if any
	cfg=cfg||window.ttf.config;
	//handle raw stylesheet text processing [Opera always!]
	if (cfg.stylesheettext)
	{
ttf._debug('[cfg.stylesheettext] TODO! | UNTESTED!');
		var rep = new Array(0), cf;
		var objSheet;
		// parse raw css for font selectors
		//fonts = _findAllCssProperties(rawCss, "font");
		fonts = ttf.cssutil.findCssClasses(rawCss, "font");
		//
		for (var i=0; i<fonts.length; i++)
		{
			cf = fonts[i];
			font = ttf.parseFontName( ttf.locateFontName(cf.match) );
			if (!font)
			{
				continue;
			}
			//
			if (cfg.quotesrules)
			{
				//insert css quotes rule
				if (!objSheet) objSheet=document.createElement('style').sheet;
				var nrule = cf.selector+'{quotes:"'+font+'";}';
				objSheet.insertRule(nrule, objSheet.cssRules.length);
				rep.push({s:cf.selector, f:font});
			}
			else
			{
				//'normal' behavior
				if (ttf.isOpera || ttf.isKonqueror)
				{
					//again ... opera is specially treated
					var els = getElementsForCssSelector( cf.selector );
					for (var j=0; j<els.length; j++)
					{
						var el = els[i];
						//set by attributes that get handled
						var patt = el.getAttribute("tff_font_set_by_code");
						var cfont = el.getAttribute("tff_font");
						if (!cfont || (patt && compareSelectors(cf.selector, patt)))
						{
							// set
							el.setAttribute("tff_font", font);
							el.setAttribute("tff_font_set_by_code", cf.selector);
						}
						rep.push(el);
					}
				}
				else
				{
					_applyStyle( cf.selector, font );
				}
			}
		}
		// if 'replaced' is set, handle it [Opera, Konqueror and cfg.quotesrules]
		if (ttf.isOpera | ttf.isKonqueror)
		{
			if (cfg.quotesrules && objSheet)
			{
				// insert rule sheet
				objSheet = objSheet.ownerNode;
				document.getElementsByTagName('head')[0].appendChild(objSheet);
				objSheet = null;
			}
			if (cfg.styleattribute)
			{
				applyStyleAttributes();
			}
			//
			for (i=0; i<rep.length; i++)
			{
				if (cfg.quotesrules)
				{
					//apply from definition
					_applyStyle( rep[i].s, rep[i].f );
				}
				else
				{
					//apply from element
					ttf._createTTF( rep[i], rep[i].getAttribute("ttf_font") );
				}
				rep[i] = null;
			}
		}
	}
}

ttf.applyStyleSheetRules=function(cfg)
{
	// handle stylesheet rules processing [verified working IE7, FF3]
	cfg=cfg||window.ttf.config;
	if (cfg.stylesheetrules)
	{
ttf._debug('[[@applyStyleSheetRules[[ cfg.stylesheetrules ');
		var csel="";
		function _scanStyleSheet(objSheet)
		{
ttf._debug('  [[@applyStyleSheetRules[[@_scanStyleSheet():'+objSheet);
			if (objSheet.disabled) return;
			if (!cfg.linkedstylesheets && objSheet.href && (linkObj.href!=document.location)) return;

			if (ttf.isIE && cfg.importstylesheets)
			{
				var impts=objSheet.imports;
				for (i=0; i<impts.length; i++)
				{
					_scanStyleSheet(impts[i]);
				}
			}
			// get rules
			try{ var rules = objSheet.rules || objSheet.cssRules; }
			catch (e){return;}
			//
			var rule, rulestyle, f;
			for (var i=0; i<rules.length; i++)
			{
				rule = rules[i];
				//rule type not implemented at least IE 7; Mozilla/Gecko only?
// see http://help.dottoro.com/ljqtncer.php
//(0|UNKNOWN_RULE|), (1|STYLE_RULE|), (2|CHARSET_RULE|@charset), (3|IMPORT_RULE|@import),
//(4|MEDIA_RULE|media), (5|FONT_FACE_RULE|@fontFace),(6|PAGE_RULE|@page)
					if (rule.type==5)
					{
						//@font-face rule
						continue;
					}
					if (rule.type==3)
					{
						// import: handle it
						if (cfg.importedstyles) _scanStyleSheet( rule.styleSheet );
						continue;
					}
					if (typeof(rule.type)!='undefined' && rule.type!=1)
					{
						//not a normal rule
						continue;
					}
				//
				rulestyle = rule.style;
				if (!rulestyle) continue;
				f = (ttf.isSafari && !rulestyle.fontFamily) ? rulestyle.font : rulestyle.fontFamily;
				if (!f) continue;
				// find ttf, tff, zipped or url font and add to selectors if found
				if (f.match(/(\.| )(ttf|tff|zip)/i) || f.indexOf('://')>-1 || (cfg.fontface && f.match(new RegExp(ttf.settings.fontreg))))
				{
					csel += (csel?",":'') + rule.selectorText;
				}
			}
		}
		var sheets = document.styleSheets;
		for (i=0; i<sheets.length; i++)
		{
			_scanStyleSheet(sheets[i]);
		}

		if (csel)
		{
			//apply selectors
			_applyStyle( csel );
		}
	}
}

ttf.applyStyleAttributes=function(cfg)
{
	//handle style attributes on elements
	cfg=cfg||window.ttf.config;
	if (cfg.styleattribute && !ttf.isOpera && !ttf.isKonqueror)
	{
ttf._debug('[[@applyStyleAttributes[[cfg.styleattribute]');
		applyStyleAttributes();
	}
}

ttf.applyReplacements=function(cfg)
{
	// handle replacements [UNTESTED AS YET]
	cfg=cfg||window.ttf.config;
	if (cfg.replacements)
	{
ttf._debug('[[@applyReplacements[[cfg.replacements[[ TODO|UNTESTED('+cfg.replacements.length+')');
		for (var i=0; i<cfg.replacements.length; i++)
		{
			var rep = cfg.replacements[i].split(':');
			var selector = ttf.trim(rep[0]);
			var font = ttf.trim(rep[1].replace(/( (ttf))/i,'.$2'));
			_applyStyle( selector, font );
		}
	}
}

ttf.fixSizeTags=function(cfg)
{
	//fix SMALL|BIG tags (IE only, verified working IE7)
	cfg=cfg||window.ttf.config;
	if (ttf.isIE && cfg.fixsizetags)
	{
ttf._debug('[[@fixSizeTags()[[cfg.fixsizetags');
		var defs = {SMALL:'89%', BIG:'120%'}
		for (var k in defs)
		{
			var els=document.getElementsByTagName(k);
			for (var i=0; i<els.length; i++)
			{
				if (ttf.ieCorrectFontSize(els[i], ttf.parseStyle(els[i], 'font-size')))
				{
					els[i].style.fontSize = defs[k];
				}
			}
		}
	}
}

ttf.applyFontTags=function(cfg)
{
	//apply inline <font> tags [verified working: IE7, FF3]
	cfg=cfg||window.ttf.config;
	if (cfg.fonttag)
	{
ttf._debug('[[applyFontTags()[[cfg.fonttag');
		var els=document.getElementsByTagName('font');
		for (var i=0; i<els.length; i++)
		{
			var el=els[i];
			//Opera stores the font face on the 'face' attribute, other browsers need style parsing
			//var font = ttf.parseFontName( ttf.isOpera ? el.getAttribute('face') : ttf.parseStyle(el,'font-family') );
			var font = ttf.parseStyle(el,'font-family');
			//if (!font && ttf.isOpera) font = el.getAttribute('face');
			if (!font && (ttf.isOpera || el.face)) font = el.getAttribute('face');
			if (font)
			{
				ttf._createTTF(el, ttf.parseFontName(font));
			}
		}
	}
}


// -- STYLE APPLICATION UTILITY METHODS  ----- //
function applyStyleAttributes(regex)
{
ttf._debug('[[@applyStyleAttributes()');
	//regex = regex || "<([^>]*)style([^=]*)=([^>]+)font-family([^,^;^>]+)((.| )(ttf|tff))?([^>]+)>";
	regex = regex || "<([^>]*)style([^=]*)=([^>]+)font-family([^,^;^>]+)(.| )(ttf|tff)?([^>]+)>";
	//regex = regex || "<([^>]*)style([^=]*)=([^>]+)font-family([^,^;^>]+)(.| )(ttf|tff)?([^>]+)>";
	//regex = regex || "<([^>]*)style=([^>]+)font-family([^,^;^>]+)(.| )(ttf|tff)?([^>]+)>";
	if (ttf.isOpera || ttf.isKonqueror)
	{
		var src = ttf.XHttp.getFile(document.location.toString() + (document.location.toString().indexOf("?") > -1 ? "&" : "?") + "tff=true");
	}
	else
	{
		var src = document.body.innerHTML;
	}
	src = src.replace(/(\n|\r|\t)/g, "");
//alert(src);
	var matches = src.match(new RegExp(regex, "gi"));

	src = null;
	if (matches)
	{
ttf._debug("[[@applyStyleAttributes[[ MATCHES -| "+matches.length);
		var styleSelectors = new Array;
		for (var i = 0, l = matches.length; i < l; i++)
		{
			var matchfont = matches[i].toString();
ttf._debug("[[@applyStyleAttributes[[ matchfont -| "+matches[i]);
			var tag = matchfont.substring(1, matchfont.indexOf(" "));
			var id = "";
			var tmpcls = "";
			var attribs;
			if ((styleSelectors[tag] == null || ttf.isOpera || ttf.isKonqueror) && (attribs = matchfont.match(/(id=|class=)([^\s]+)([\s])/gi)))
			{
				for (var j = 0, ml = attribs.length; j < ml; j++)
				{
					var attrib = attribs[j];
					if (attrib.substring(0, 2) == "id")
					{
						id = attrib.substring(3).replace(/('|")/g, "");
					}
					else
					{
						if (attrib.substring(0, 5) == "class")
						{
							tmpcls = attrib.substring(6).replace(/('|")/g, "");
						}
					}
				}
				if (tmpcls)
				{
					tmpcls = ttf.trim(tmpcls);
					if (styleSelectors[tag] == null) {tag += "." + tmpcls;}
				}
				if (id)
				{
					id = ttf.trim(id);
					if (styleSelectors[tag] == null)
					{
						tag += "#" + id;
					}
				}
				if ((ttf.isOpera || ttf.isKonqueror) && id && document.getElementById(id))
				{
					document.getElementById(id).setAttribute("tff_font", locateFontName(matchfont));
				}
			}
			if (styleSelectors[tag] == null)
			{
				styleSelectors[tag] = tag;
			}
		}
		var clsnames = "";
		for (var t in styleSelectors)
		{
			clsnames += (clsnames ? "," : "") + styleSelectors[t];
		}
ttf._debug("[[@applyStyleAttributes[[ call _applyStyle("+clsnames+")");
		_applyStyle(clsnames);
	}
}
function _applyStyle(selector, font)
{
ttf._debug("[[@applyStyle("+selector+", "+font+")");
	var cfg = window.ttf.config;
	if (!selector) {return false;}
	var col = ttf.cssutil.getElementsForCssSelector(selector);
ttf._debug("  [[@_applyStyle[[ cols:"+col.length+"");
	if (cfg.maxnodes && col.length > cfg.maxnodes) {return;}
	for (var c = 0, l = col.length, txt; c < l; c++)
	{
		if (col[c].getAttribute("tff_replaced"))
		{
			continue;
		}
		if (col[c].tagName != "INPUT")
		{
			if ((txt = ttf.trim(col[c].innerText || col[c].innerHTML)) == "") {continue;}
			if ((txt = ttf.trim(txt.replace(/(\n|\r|\t|\s)/g, ""))) == "") {continue;}
			if (!ttf.isIE && txt.replace(/<([^>]+)>/g, "") == "") {continue;}
		}
		else
		{
			continue;
		}
ttf._debug("  [[@_applyStyle[[ call _createTTF("+col[c].tagName+", "+font+")");
		ttf._createTTF(col[c], font);
		if (cfg.maxtime_reached) {return false;}
	}
}
////////////////////////////
/*
/////////////////////////////////////////////////
// ------------------------------------------- //
// -- TTF ATTRIBUTE UTILITY METHODS  --------- //
function setTTFAttributesFromCss(rawsrc, cssCls)
{
	return setTTFAttributesFromSelectors(cssCls, ttf.cssutil.findCssClasses(rawsrc, cssCls));
}
function setTTFAttributesFromSelectors(cssCls, properties)
{
	for (var i = 0, ml = properties.length, m; i < ml; i++)
	{
		m = properties[i];
		var col = ttf.cssutil.getElementsForCssSelector(m.selector);
		for (var c = 0, l = col.length; c < l; c++)
		{
			setTTFAttributeValue(col[c], cssCls, m.selector, m.value);
		}
	}
}
function setTTFAttributeValue(obj, attrib, selector, value)
{
	attrib = "tff_" + attrib;
	if (obj.getAttribute(attrib) && !obj.getAttribute(attrib + "_set_by_code"))
	{
		return;
	}
	if (compareSelectors(selector, obj.getAttribute(attrib + "_set_by_code")))
	{
		obj.setAttribute(attrib, value);
		obj.setAttribute(attrib + "_set_by_code", selector);
		var col = getAllCssMatches(obj);
		for (var c = 0, l = col.length; c < l; c++)
		{
			col[c].setAttribute(attrib, value);
		}
	}
	obj = null;
}
function compareSelectors(selector, attribValue)
{
	if (!selector) {return false;}
	if (!attribValue) {return true;}
	if (selector.indexOf(attribValue) > -1) {return true;}
	selector = selector.split(" ");
	attribValue = attribValue.split(" ");
	if (selector[selector.length - 1].indexOf("#") > -1)
	{
		//ID will always be unique.
		return true;
	}
	if (attribValue[attribValue.length - 1].indexOf("#") > -1)
	{
		//ID will always be unique.
		return false;
	}
	var dotCountSelector = 0;
	var dotCountAttrib = 0;
	var idCountSelector = 0;
	var idCountAttrib = 0;
	for (var i = 0, l = Math.min(selector.length, attribValue.length); i < l; i++)
	{
		if (selector[i])
		{
			if (selector[i].indexOf(".") > -1) {dotCountSelector++;}
			if (selector[i].indexOf("#") > -1) {idCountSelector++;}
		}
		if (attribValue[i])
		{
			if (attribValue[i].indexOf(".") > -1) {dotCountAttrib++;}
			if (attribValue[i].indexOf("#") > -1) {idCountAttrib++;}
		}
	}
	if (idCountSelector || idCountAttrib) {return idCountSelector > idCountAttrib;}
	if (dotCountSelector || dotCountAttrib) {return dotCountSelector > dotCountAttrib;}
	return selector.length > attribValue.length;
}

/////////////////////////////////////////////////
*/


ttf._createTTF = function(obj,font, fontstretch, textshadow, textrotation)
{
ttf._debug("  [[@_createTTF");
	if (!obj || !obj.tagName)return false;
	var tag = obj.tagName,cfg=cfg||window.ttf.config;
	switch (tag)
	{
		case 'IMG':
		case 'BR':
		case 'HR':
		case 'TEXTAREA':
		case 'SELECT':
		case 'OPTION':
		case 'SCRIPT':
		case 'NOSCRIPT':
		case 'STYLE':
		case 'EMBED':
		case 'OBJECT':
		case 'PARAM':
		case 'META':
		case 'MAP':
		//case 'INPUT':
			return false;
	}
///////////////////////////////////////////////////////////////////////////////
		if(obj.getAttribute("tff_replaced"))//&&!tStop)
		{
ttf._debug("  [[@_createTTF[[ NO PROCESS TTF_REPLACED");
			//don't process already processed
			return;
		}
		if(!cfg.setreplaceddisabled&&(!(ttf.isOpera||ttf.isKonqueror)||!cfg.styleattribute))
		{
ttf._debug("  [[@_createTTF[[ SET TTF_REPLACED");
			//set elements processd
//			obj.setAttribute("tff_replaced","1");
		}
	//	parsedItems++;
///////////////////////////////////////////////////////////////////////////////
		var style=ttf.parseStyle(obj);
		if(obj.tagName=='INPUT' || obj.childNodes.length==0)
		{
			return false
		}

	//	if(((ttf.isOpera&&!cfg.quotesrules)||ttf.isKonqueror)||(cfg.replacements&&cfg.lazyreplace))
	//	{
	//		font=(obj.getAttribute("tff_font")||font);
	//	}
	//	else
		{
			//font=ttf.parseFontName(style[cfg.quotesrules?"quotes":"fontFamily"])||font;
			font=ttf.parseFontName(style.fontFamily)||font;
ttf._debug(' -| _createTTF found FONT-FAMILY '+font);
		}
		if(!font)
		{
			return false;
		}
		//do some styling from CSS
		if (cfg.fontstretch)
		{
			fontstretch = style['font-stretch'] || obj.getAttribute("tff_font-stretch") || fontstretch;
		}
		if (cfg.textshadow)
		{
			textshadow = style['text-shadow'] || obj.getAttribute("tff_text-shadow") || textshadow;
		}
		if (cfg.textrotation)
		{
			textrotation = style['text-rotation'] || obj.getAttribute("tff_text-rotation") || textrotation;
		}

		//parse children
		var style=false,l=obj.childNodes.length,i,isprocessed=false;
ttf._debug("  loop childs ("+l+") for "+tag+" ("+obj.id+")"+img);
ttf._debug("[[--TSHADE "+obj.style["textShadow"] + ','+ttf.parseStyle(obj,'text-shadow'));
		for(i=0;i<l;i++)
		{
			if(obj.childNodes[i].nodeType==3&&font)
			{
ttf._debug('  childnode.type == 3');
				if(font=="*")
				{
					continue;
				}
				if(!style)
				{
//ttf._debug('[[X>>PGEN QSA -> font='+font+',size='+size);
					style=ttf.parseStyle(obj);
					var bcol=ttf.parseBackColor(obj).replace(/#/,"");
					var lineheight=false;
					//fix line height?
					if (cfg.fixlineheight)
					{
						//var size=ttf.parseFontSize(style.fontSize);
//ttf._debug('[[X>>... QSA -> font='+font+',size='+size);
						lineheight = style.lineHeight;
						if (lineheight == 'normal')
						{
							lineheight = cfg.setlineheight;
						}
						if (ttf.isOpera && lineheight && lineheight==parseInt(lineheight).toString())
						{
							lineheight = false;
						}
						if (lineheight) lineheight = ttf.parseFontSize(lineheight, size);
						if (lineheight==size) lineheight = false;
						if (lineheight)
						{
ttf._debug('[[@_createTTF[[lineheight|='+lineheight+']]]]');
							// we have a lineheight: define _setLineHeight callback
							if (!window._tffSetLineHeight)
							{
								window._tffSetLineHeight = function ()
								{
									if (this.src.toString().indexOf(blankImage) > -1 && !this.getAttribute("tffSprite")) {return;}
									var p = this.parentNode;
									if (p.getAttribute("tff_line-height_set")) {return;}
									else {p.setAttribute("tff_line-height_set", "1");}
									var hLine = this.getAttribute("tff_line-height");
									if (!hLine) {return;}
									var _a0 = (parseInt(hLine) - this.offsetHeight) / 2;
									if (_a0 > 0 && !isOpera && !isIE) {return;}
									_a0 += "px";
									var col = p.getElementsByTagName("IMG");
									for (var c = 0, l = col.length, el, s; c < l; c++)
									{
										el = col[c];
										if (el.className.indexOf("tff_img") > -1)
										{
											if (!fixTransparency || ___config.sprite) {el.onload = null;}
											s = el.style;
											s.marginTop = _a0;
											s.marginBottom = _a0;
										}
									}
								};
							}
						}
					}

					var doAlphaLoad=(cfg.fixTransparency&&b=="transparent"&&!cfg.sprite);
					var size,col;
					var tProps = {shadow: textshadow, rotation: textrotation};
					//var src=ttf.buildTffSrc(obj,style,font,s,c,b);
ttf._debug('[[@_createTTF[[make QSA -> font='+font+',size='+size);
					var src=ttf.makeSrcQSA(obj,style,font,size,col,bcol,fontstretch,tProps);
					var doHover=false;

					if (tag=='A')
					{
						if (cfg.hover) doHover=true;
						if (ttf.isIE && cfg.setlinkverticalalign && !lineheight && style.verticalAlign=='auto')
						{
							obj.style.verticalAlign = cfg.setlinkverticalalign;
						}
					}

					if (cfg.encodeurls)
					{
						src += '&c2='+ttf.encodeCacheUrl(src);
					}

					img.className="tff_img tff_"+font.replace(/(\s|\.)/g,"_");
					img.setAttribute('ttf_line_height', lineheight||"");
					var ttfDriver=ttf.getDriver();
					var _50=false;
					if(!ttfDriver.match(/:\/\//))
					{
						ttfDriver=cfg.path+ttfDriver;
					}
				}
				isprocessed=(ttf._createWords(obj.childNodes[i],style,img,ttfDriver,src,_50,doHover,doAlphaLoad,lineheight)||isprocessed);
			}
			else
			{
				if(!obj.childNodes[i].tagName)
				{
					continue;
				}
ttf._debug('  childnode.type != 3');
				isprocessed = ttf._createTTF(obj.childNodes[i], font, fontstretch, textshadow, textrotation) || isprocessed;
			}
			if(isprocessed)
			{
ttf._debug('  break processing');
				//break processing (due to ttf._createWords)
				var nl=obj.childNodes.length;
				i+=(nl-l);
				l=nl;
				isprocessed=false;
			}
			if(cfg.maxtime_reached)
			{
				break;
			}
		}
		obj=null;
		return false;
}

//verified OK
window._ttfInitHover = function () 
{
	var cfg=window.ttf.config;
	var obj = this.parentNode;
	setTimeout(function ()
	{
		var src = ttf.makeSrcQSA(obj);
		if (cfg.encodeurls)
		{
			src = "&c2=" + encodeCacheUrl(src);
		}
		var col = obj.getElementsByTagName("IMG");
		for (var c = 0, l = col.length; c < l; c++)
		{
			if (col[c].className.indexOf("tff_img") > -1)
			{
				var _52 = col[c].getAttribute("tffText");
				var driver = ttf.getDriver();
				if (!driver.match(/:\/\//))
				{
					driver = cfg.path + driver;
				}
				var tmp = src.substring(1) + "&s=" + ttf.escape(_52);
				if (cfg.cache)
				{
					tmp = ttf._url2cache(tmp);
					col[c].onerror = _onCacheFail;
				}
				tmp = driver + tmp;
				var cursrc = tmp;
				var newsrc = col[c].getAttribute("mouseout") || col[c].src;
				cursrc = cursrc.substring(cursrc.indexOf(driver));
				newsrc = newsrc.substring(newsrc.indexOf(driver));
				if (cursrc == newsrc)
				{
					col[c].onmouseover = null;
					return;
				}
				col[c].setAttribute("mouseover", tmp);
				if (ttf.fixTransparency && col[c].style.filter.indexOf("AlphaImageLoader") > -1)
				{
					_ttfHover(obj, "over");
				}
				else
				{
					col[c].setAttribute("mouseout", col[c].src);
					col[c].src = tmp;
				}
				col[c].onmouseover = function(){ _ttfHover(this.parentNode, "over"); };
				col[c].onmouseout = function (){ _ttfHover(this.parentNode, "out"); };
			}
		}
		col = null;
		obj = null;
	}, 0);
};

//verified OK
window._ttfHover = function (obj, type)
{
	var cfg=window.ttf.config;
	var col = obj.getElementsByTagName("IMG");
	for (var c = 0, l = col.length; c < l; c++)
	{
		if (col[c].className.indexOf("tff_img") > -1)
		{
			if (ttf.fixTransparency && col[c].style.filter.indexOf("AlphaImageLoader") > -1)
			{
				// this is yet untested
				var src = col[c].getAttribute("mouse" + type);
				col[c].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"" + src.replace(/%/g, "%25") + "\",sizingMethod=\"crop\")";
				col[c].src = cfg.path + cfg.blankImage;
			} 
			else
			{
				col[c].src = col[c].getAttribute("mouse" + type);
			}
		}
	}
	col = null;
};

ttf._createWords=function(el,style,img,ttfDriver,src,_57,doHover,doAlphaLoad,lineheight)
{
ttf._debug('[[@_createWords '+el.nodeName+','+el.parentNode.nodeName);
	if(!el) return false;
	if(!el.nodeValue) return false;

	var cfg=cfg||window.ttf.config;
	var parent=el.parentNode;
	var val=el.nodeValue;
ttf._debug("  [[@_createWords[[ "+(parent.nodeName||el.nodeName)+' -| '+val);
	val=val.replace(/([\n\r\s\t]+)/g," ");
	val=val.replace(/^([\s]+)/g," ");
	val=val.replace(/([\s]+)$/g," ");
	val=ttf.trim(val);
	if (val=="") return false;
	//replace escaped spaces
	val=val.replace(new RegExp(unescape("%A0"),"g")," ");
	// transform text by CSS rule?
	var trfrm = style["textTransform"];
	if (trfrm=="uppercase") val=val.toUpperCase();
	if (trfrm=="lowercase") val=val.toLowerCase();

	// set wrapper mode. Note: LINK TEXTS are NOT WRAPPED by default!
	var nowrap=cfg.nowrap||(style["whiteSpace"]=='nowrap');

	//break into words
	var words = (nowrap?[val]:val.split(" "));
	if (cfg.maxwords && words.length>cfg.maxwords)
	{
		return false;
	}

	// validate running time
	//var cTime=getTimestamp();
	//if(cfg.maxtime&&(cTime-tStart>cfg.maxtime*1000))
	//{
	//	cfg.maxtime_reached=true;
	//	return false;
	//}

	if (cfg.textdecoration)
	{
		var d = ttf.unquote(style.textDecoration);
		if (d != "normal" && d != "none") 
		{
			if (cfg.removetextdecoration)
			{
				obj.style.textDecoration = "none";
			}
			else
			{
				if (cfg.fixtextdecorationnowrap)
				{
					//this fixes no wrap
					//e.g. for A elements in normal behavior (underlined)
ttf._debug('  [[@_createWords[[cfg.fixtextdecorationnowrap[[ '+(parent.nodeName||el.nodeName));
					words = new Array(val);
				}
			}
		}
	}
	
	if(cfg.hidenode)
	{
		parent.style.visibility="hidden";
	}
	if(cfg.title)
	{
		img.title=val.replace(/\n/,"");
		if(parent.title)
		{
			if(parent.title.toLowerCase().indexOf(img.title.toLowerCase())==-1)
			{
				img.title+=", "+parent.title;
			}
			else
			{
				img.title=parent.title;
			}
		}
	}

	// render words
ttf._debug('  [[@_createWords[[ttfDriver -| '+ttfDriver);
	var capitalize = (trfrm=='capitalize');
	var _60=false;

	for (var i=0; i<words.length; i++)
	{
		if (i>0)parent.insertBefore(document.createTextNode(" "),el);
		if (ttf.trim(words[i])=="")
			continue;
		if (capitalize) words[i] = ttf.ucfirst(words[i]);
		//replaceditems++;

		//create new image by cloning imagenode
		var el2 = img.cloneNode(false);
		if(cfg.alt)
		{
			el2.alt=words[i]+" ";
		}
		el2.setAttribute("tffText",words[i]);
		if(doHover&&(!doAlphaLoad||!cfg.sprite||!cfg.spritealphaimageloader))
		{
			el2.onmouseover=_ttfInitHover;
		}
		if(doAlphaLoad)
		{
			el2.onload=_ttfLoadAlpha;
		}
		else if (lineheight)
		{
			el.onload = _tffSetLineHeight;
		}
	
		var tmp=src.substring(1)+"&s="+ttf.escape(words[i]);
		if(cfg.cache)
		{
			tmp=ttf._url2cache(tmp);
			el2.onerror=window._onCacheFail;
		}
		//now insert the new image
ttf._debug('  [[@_createWords[[ tag-|'+(parent.nodeName||el.nodeName) + '; delayed-|'+cfg.delayedloading+'; ttf-|'+tmp);
		parent.insertBefore(el2,el);
		//el.style.className = '';
		
		// FORCE TRANSPARENCY ON BGND!
		if (!!parent) parent.style.backgroundColor = 'transparent';
		else if (!!el) el.style.backgroundColor = 'transparent';
		
		// force parent visibility (eszenzz mod/hack)
		if (!!parent) parent.style.visibility='visible';

		if(cfg.delayedloading)
		{
			document.tff_inserted_images[document.tff_inserted_images.length]={"before":el,"space":(i>0),"node":el2,"src":ttfDriver+tmp}
		}
		else
		{
			el2.src=ttfDriver+tmp;
		}
		el2=null;
	}

/////////////////////////////////////////////////
	// if not a link or anchor or image, 
	// [TFF.com: Enable copying replaced text, inserts invisible transparent element with text.]
	var docopy = cfg.copy&&parent.tagName!="A"&&parent.parentNode.tagName!="A"&&parent.tagName!="BUTTON";
	if (docopy)
	{
		var container = document.createElement('SPAN');
		//
	}
	else
	{
		var container = parent;
	}
/////////////////////////////////////////////////
/////////////////////////////////////////////////
		if(cfg.copy&&parent.tagName!="A"&&parent.parentNode.tagName!="A"&&parent.tagName!="BUTTON")
		{
ttf._debug('  [[@_createWords[[ cfg.copy');
			if(!window._ttfOnCopyText)
			{
				//ttf show/hide
				window._ttfOnCopyText=function(parent,value)
				{
					var col=parent.parentNode.getElementsByTagName("IMG");
					for(var c=0,l=col.length;c<l;c++)
					{
						if(col[c].className.indexOf("tff_img")>-1)
						{
							col[c].style.visibility=value;
						}
					}
				}
			}
ttf._debug('  [[@_createWords[[ tag-|'+(parent.nodeName||el.nodeName));
			var elx=document.createElement("SPAN");
var insertbefore=el.nextSibling;
			elx.appendChild(parent.removeChild(el));
ttf._debug('  [[@_createWords[[ appended child [el to new]');
			if(style["display"]=="block")
			{
				elx.appendChild(document.createElement("BR"))
			}
			var s=elx.style;
			s.position="absolute";
			s.zIndex=1000;
			if(ttf.isIE)
			{
				s.filter="Alpha(opacity=0)";
			}
			else
			{
				s.opacity="0";
			}
ttf._debug('  [[@_createWords[[ parent inserted (new el)');
			parent.insertBefore(elx,parent.firstChild);
//			parent.insertBefore(el2,insertbefore);
			elx.onmousedown=function()
			{
				window._ttfOnCopyText(this,"hidden");
				var s=this.style;
				s.filter?s.filter="none":s.opacity="1";
			};
			elx.onmouseout=function()
			{
				window._ttfOnCopyText(this,"visible");
				var s=this.style;
				s.filter?s.filter="Alpha(opacity=0)":s.opacity="0";
			}
		}
		else
		{
			if(_60||cfg.hidetext)
			{
				el.nodeValue=(_60||ttf.isKonqueror?" ":"")
			}
		}
	//	runTime+=(getTimestamp()-cTime);
		return true;

}

ttf.makeSrcQSA = function(obj,style,font,size,col,bcol,fontstretch, _63)
{
	var qsa='',cfg=window.ttf.config;
	_63 = _63|{};
	style=style||ttf.parseStyle(obj);
	font=font||ttf._objGetFont(obj,style);
	//var font=ttf.parseStyle(cel,'font-family');
	//font = font || (isOpera && !___config.quotesrules || isKonqueror ? obj.getAttribute("tff_font") : parseFontName(style[___config.quotesrules ? "quotes" : "fontFamily"]));
ttf._debug('!!!! QSA FS1:'+size);
	size = size||ttf.parseDefaultFontSize(obj);
	col=col||ttf.parseColor(style['color']);
	bcol=bcol||ttf.parseBackColor(obj);
ttf._debug('!!!! QSA FS2:'+size);
	size=ttf.adjustFontSize(font,size);
ttf._debug('!!!! QSA FS3:'+size);
	if (/['"]([^'"]*)['"]/i.test(font)===true)
	{
		font=/['"]([^'"]*)['"]/i.exec(font);
		font=font[1];
	}
	font=ttf.escape(font.toString().replace(/\.ttf/i,''));
	qsa += '&f='+font;
	qsa += '&fs='+size;
	qsa += '&c='+col;
	if (bcol!='transparent') qsa += '&bc='+bcol;
	if(bcol=="transparent"&&!ttf.isIE7&&!cfg.fixTransparency)
	{
		qsa+="&trans=8"
	}
	//now append extra
	if (cfg.imagetype != 'png')
	{
		qsa += '&out='+cfg.imagetype;
	}
	var tmp;
	// add CSS::text-decoration
	if (cfg.textdecoration)
	{
		tmp = ttf.unquote(style.textDecoration);
		if (tmp!='normal' || t!='none')
		{
			qsa += '&textdecoration='+tmp;
		}
	}
	// add CSS::font-style
	if (cfg.fontstyle && style.fontStyle!='normal')
	{
		qsa += '&fontstyle='+style.fontStyle;
	}
	//correct font-weight
	if (cfg.normalheaders && obj.tagName.match(/^H[1-6]$/i))
	{
		style.fontWeight = 'normal';
	}
	//font-weighth
	if (cfg.fontweight)
	{
		tmp = style.fontWeight;
		if (tmp == 'bold') tmp=700;
		else if (tmp == 'bolder') tmp=900;
		if (parseInt(tmp)>600) qsa += '&fontweight='+tmp;
	}
	// add CSS::font-variant
	if (cfg.fontvariant&& style.fontVariant!='normal')
	{
		qsa += '&variant='+style.fontVariant;
	}
	// add CSS::letter-spacing
	if (cfg.letterspacing && style.letterSpacing!='normal')
	{
		tmp = parseInt(ttf.parseFontSize(style.letterSpacing, size));
		if (tmp) qsa += '&spacing='+tmp;
	}

	//if (___config.fontstretch)
	//{
	//	fontstretch = fontstretch || style['font-stretch'] || obj.getAttribute("tff_font-stretch");}
	//	if (fontstretch) {src += "&stretch=" + ttf.unquote(fontstretch);}
	//	for (var i = 0, l = cfg.textprops.length, p, k, v, m, t; i < l; i++) 
	//	{
	//		p = cfg.textprops[i];
	//		k = p.replace(/\-/g, "");
	//		if (___config["text" + k]) 
	//		{
	//			if ((v = ttf.trim(ttf.unquote(_63[p] || (typeof style["text-" + p] == "string" ? style["text-" + p] : 0) || obj.getAttribute("tff_text-" + p)))) && v != "none")
	//			{
	//				if ((m = v.match(/([0-9\.]+)(pt|pc|in|cm|mm|%|em|ex)/i))) {t = parseFontSize(m = m[0]);
	//				if (t.substring(t.length - 2) == "em") {t = parseFontSize(t, parseDefaultFontSize(obj));}
	//				v = v.replace(m, t);
	//			}
	//			v = v.replace(/rgb\(([0-9]+), ([0-9]+), ([0-9]+)\)/gi, "rgb($1,$2,$3)");
	//			if ((m = v.match(/url\(([^\)]+)\)/i))) {
	//				t = v.indexOf(m[0]);
	//				v = v.substring(0, t) + m[1] + v.substring(t + m[0].length);
	//			}
	//			src += "&" + k + "=" + ttf.ttfEscape(v.replace(/#/, ""));
	//		}
	//	}
	//}

	//if (___config.fontface && cachedFonts[font]) {src += "&url=" + escape(cachedFonts[font]).replace(/\//g, "%2F");}

	obj=null;
	return qsa;
}
//verified OK
ttf.adjustFontSize=function(f,s,cfg)
{
	cfg=cfg||window.ttf.config;
	var fa = cfg.fontsize_adjust;
	var extra=(fa?(fa[f]||fa[f.substring(0,f.indexOf("."))]||fa[f.replace(/\.(ttf)/i," $1")]||0):0);
	return Math.max(cfg.minimumfontsize,s+cfg.increasefontsize+extra);
}


ttf._ttfRestore=function()
{
	//this restores failed TTF displays
	cfg = cfg||ttf.window.config;
	var id=this.id;
	var el=this;
	var prev=this.node.before;
	var par = el.parentNode;

	var children = par.childNodes;
	var len = children.length;
	for (i=0; i<len; i++)
	{
		var curr=children[i];
		if (curr.id || curr.nodeName || curr.nodeType)
		{
			//
		}
	}

//NOTW: how do we handle the fac tthat multiple images are made from
// 1 text, and gets split into words... 
// we cann not simply replace all imafges by the text snce this will 
// totally fuck up rendering.

	if (prev.nodeName == "SPAN")
	{
		// check texts
	}

	// now rstore ALL previous texts;
	//               |             0 | 1276089900 | 1276091100 |            0 | TvXvNx
//AyalpLH95e3QkSmk8DagffXn7S | 360 graden feedback | nl_utf8  | 2HmFpjh2L6sBVypHq2
//GsJTGqQ6m5jHrU | http://moodle.rogier.d.sebsoft.nl/mod/avfeedback/templategen.ph
//p?id=2 |     4 |

}
//////////////////////////////////
// UTILITY METHODS
//////////////////////////////////
//verified OK
ttf._url2cache=function(url)
{
	//replace *, / and %
	url = url.replace(/\*/g, "%2A");
	url = url.replace(/\//g, "%2F");
	url = url.replace(/\%/g, "%25");
	var cfg=window.ttf.config;
	if (cfg.encodeurls)
	{
		url=url.replace(/c2=/,"");
		if(cfg.cachedirs)
		{
			url=url.replace(/&c1=/,"/")
		}
	}
	else
	{
		url = url.replace(/f=/,"");
		var pos=url.indexOf("&s=");
		//replace + for %20 (space)
		url=url.substring(0,pos).replace(/\+/g,"%20")+url.substring(pos);
		if(cfg.cachedirs)
		{
			url=url.substring(0,pos).replace(/%252F/g,"/")+url.substring(pos);
			url=url.replace(/&s=/,"/");
			url=url.replace(/&c=/,"/c=");
			// ==>> <cfg.path>/ttf.php?<FAMILY>/<COLOR>/<SIZE>
		}
	}
	url += "&." + cfg.imagetype;
	return url;
}

//verified OK
ttf._cache2url=function(url){
	var cfg=window.ttf.config;
		// url: <config.path>/cache/
		if(cfg.encodeurls)
		{
			//decode encoded url
			if(cfg.cachedirs)
			{
				// mod cache dir
				var pos=url.lastIndexOf("/");
				url=url.substring(0,pos)+"&c1="+url.substring(pos+1);
			}
			//mod /cache/ ref to driver
			url=url.replace(/cache\//,"tff.php?c2=");
			url=url.replace(/%25/g,"%");
			url=cfg.path+url.substring(url.indexOf("tff.php?"));
		}
		else
		{
//if (!XXDBG)
//{
//	//.... /fcache/blamboxcustom?fs=...&...
//alert('[[@_cache2url[[ fail '+url+'');
//XXDBG=1;
//}
			//Default caching
		//	url=url.replace(/cache\//,"tff.php?f=");
		//	if(cfg.cachedirs)
		//	{
		//		//Dir caching: /cache/<font-family>/<font-color>/<font-size>
		//		url=url.replace(/\/c=/,"&c=");
		//		var pos=url.lastIndexOf("/");
		//		url=url.substring(0,pos)+"&s="+url.substring(pos+1);
		//	}
		//	url=url.replace(/%25/g,"%");
		//	url=cfg.path+url.substring(url.indexOf("tff.php?f="));
			//result: <config.path>/ttf.php?f=...&c=...&s=...
			var re=new RegExp(cfg.cache, 'i');
//alert('[[@_cache2url[[ '+url+'\n'+cfg.cache+'\n'+url.indexOf(cfg.cache));
			url = url.replace(''+cfg.cache, '?f=');
			url=url.replace(/%25/g,"%");
			//url=cfg.path+url.substring(url.indexOf("?f="));
			url=ttf.getDriver(true)+url.substring(url.indexOf("?f="));
			url=url.replace(/\?+/i,'?')
//alert('[[@_cache2url[[ NEW '+url+'');
		}
		return url;
}

//verified OK
function encodeCacheUrl(d)
{
	for (var t = "", i = 0, p = document.location.host, l = Math.ceil(d.length / p.length); i < l; i++)
	{
		t += p;
	}
	for (var s = "", i = 0, l = d.length; i < l; i++)
	{
		s += String.fromCharCode(d.charCodeAt(i) ^ t.charCodeAt(i));
	}
	s = s.replace(/\+/g, "%2B");
	s = escape(s);
	return s;
}

//verified OK
ttf.parseColor = function(c)
{
	if (!c)return false;
	c=c.toString();
	//alert('parsing '+c);
	if (c=='transparent' || /\s*rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/g.test(c))
	{
		return 'transparent';
	}
	c = c.replace(/(#|rgb\(|\s|\)|\'|\")/gi,'');
	return c;
}

//verified OK
ttf.parseBackColor = function(obj,cfg)
{
	var cfg=cfg||window.ttf.config;
	if (!obj)return false;
	if (cfg.forcePNGFix) return "transparent";

	var b="transparent",style,tbg=cfg.transparentBackground;
	while (b=="transparent")
	{
		style=ttf.parseStyle(obj);
		//do nothing when background image
		if (tbg && style['backgroundImage']!='none')
		{
			return b;
		}
		//
		b=ttf.parseColor(style["backgroundColor"]);
		if (b!="transparent")
		{
			return b;
		}
		if (obj.tagName == "BODY")
		{
			return 'ffffff';
		}
		//redo loop 1 level up
		obj=obj.parentNode;
	}
	return b;
}

//verified OK
ttf.parseFontSize = function(fs,scale)
{
	if (!fs) return 0;

	if (fs.match(/small|smaller|normal|medium|larger|large/i))
	{
		fs = ttf.defaultSizes[fs]||'100%';
	}
	//mod +/- values
	var fns;
	if (fs.match(/^((\+|\-)*)([0-9])$/g))
	{
		if (fs.match(/^(\+|\-)$/)) fs = 3+parseInt(fs);
		fs = ttf.defaultSizes[Math.min(fs,'7')]||'100%';
	}
	var fsi = parseInt(fs);
	var fss = fs.toString();
	if (ttf.isOpera&&isNaN(fsi))
	{
		fs = ttf.defaultSizes[fsi]||'100%';
	}
	var csize=false;
	var fse=false;
	if (csize=fss.toString().match(/^\s*([0-9\.]+)((px|pt|pc|cm|in|mm|%|em|ex)*)$/i))
	{
		fse = csize[2];
		fsi = csize[1];
		switch (fse)
		{
			case 'px':
				return fs;
			case 'pt':
				return parseInt(ttf.pt2px(fsi));
			case 'pc':
				return parseInt(ttf.pc2px(fsi));
			case 'cm':
				return parseInt(ttf.cm2px(fsi));
			case 'mm':
				return parseInt(ttf.mm2px(fsi));
			case 'in':
				return parseInt(ttf.in2px(fsi));
			case '%':
				fsi = fsi/100+'em';
				break;
			case 'em':
				fsi = fsi/1+'em';
				break;
			case 'ex':
				fsi = fsi/2+'em';
				break;
		}
		return (scale ? Math.round(parseFloat(fsi) * parseInt(scale)) : fsi);
	}
	return fs;
}

//verified OK
ttf.parseDefaultFontSize=function(obj)
{
	var cfg=window.ttf.config;
	if (!obj) return false;

	if (document.getDefaultView && document.getDefaultView.getComputedStyle)
	{
		var fs = document.getDefaultView.getComputedStyle(obj,null).getPropertyValue('font-size').toString();
		if (fs.substring(fs.length-2)=='px')
		{
			return parseInt(fs);
		}
	}

	if (!ttf.bodyFontSize)
	{
		// try to parse a main font size from the body
		if (ttf.isIE||ttf.isOpera)
		{
			ttf.bodyFontSize=parseEmHeight(document.body);
		}
		else
		{
			ttf.bodyFontSize=parseInt(ttf.parseFontSize(ttf.parseStyle(document.documentElement,"fontSize")));
			if(ttf.bodyFontSize)
			{
				ttf.bodyFontSize=parseInt(ttf.parseFontSize(ttf.parseStyle(document.body,"fontSize"),ttf.bodyFontSize));
			}
		}
	}

	if(obj.tagName=="BODY")
	{
		return ttf.bodyFontSize;
	}

	var objFSize=ttf.parseStyle(obj,"fontSize");
	var s=objFSize;
	if((cfg.fixrelativefontsize&&s.match(/(%|em|ex)$/i))||obj.tagName.match(/^H([1-6])$/))
	{
		var ps=ttf.parseStyle(obj.parentNode,"fontSize");
		if(ps==objFSize)
		{
			return parseEmWidth(obj);
		}
	}

	if(ttf.isIE)
	{
		if(cfg.fixsizetags)
		{
			if(obj.tagName=="SMALL"&&ttf.ieCorrectFontSize(obj,s))
			{
				s="89%"
			}
			if(obj.tagName=="BIG"&&ttf.ieCorrectFontSize(obj,s))
			{
				s="120%"
			}
		}
	}

	s=ttf.parseFontSize(s);
	s=s.toString();
	if(s.substring(s.length-2)=="em")
	{
		var m=s.substring(0,s.length-2);
		s=ttf.bodyFontSize;
		s=s*m;
	}
	return parseInt(s)
}

ttf._objGetFont=function(obj,style,cfg)
{
	var font,cfg=cfg||window.ttf.config;
	if ((ttf.isOpera && !cfg.quotesrules) || ttf.isKonquerer)
	{
		font=obj.getAttribute("ttf_font");
	}
	else
	{
		var style=style||ttf.parseStyle(obj);
		font=ttf.parseFontName(style[cfg.quotesrules?"quotes":"fontFamily"]);
	}
	return font;
}
//verified OK
ttf.locateFontName=function(v)
{
	if (!v) {return "";}
	v = v.toString();
	v = v.substring(v.lastIndexOf("font-family"));
	var t;
	if ((t = v.match(/(font|font\-family)([^\-])([^,^;]+)([,;}]+)/i)))
	{
		v = t[3];
		if ((t = v.match(/([\'\"])([^\'^\"]+)([\'\"])/))) {v = t[2];}
		return ttf.trim(v);
	}
	return "";
}

//verified OK
ttf.parseFontName=function(font)
{
ttf._debug('[parseFontName()] -> got '+font);
	if (!font)return false;
	var url,p,f=font;

	if(f.indexOf("://")>-1)
	{
ttf._debug('[parseFontName()] -> :// '+font);
		if(p=f.match(/([\'\"])([^\'^\"]+)([\'\"])/))
		{
			f=p[2]
		}
		url=f;
		p=Math.max(f.lastIndexOf("/"),f.indexOf("?"),f.indexOf("="))+1;
		//p=Math.max(f.lastIndexOf("/"),f.indexOf("?"),f.indexOf("="))+1;
		//f=f.substring(p).replace(/(&([^=]+)=|\.zip)/gi,"");
		if ((p=f.lastIndexOf("/"))>-1) f=f.substring(p+1);
		if ((p=f.lastIndexOf("?"))>-1) f=f.substring(0,p);
		f=f.replace(/(&([^=]+)=|\.zip)/gi,"");
		
		ttf.settings.fontcache[f]=url;
		ttf.settings.fontreg = (ttf.settings.fontreg ?"("+f+"|"+ttf.settings.fontreg.substring(1):"("+f+")");
		
		return f
	}
	if (/[\'\"](([^\'\"]*)[\s\.]ttf)[\'\"]/i.test(f)===true)
	{
ttf._debug('[parseFontName()] -> match ttf|tff '+font);
		f=/[\'\"](([^\'\"]*)[\s\.]ttf)[\'\"]/i.exec(f);
		f=f[1];
		return font.replace(/\.ttf/i,'',f);
	}
	if (/[\'\"]?(([^\'\",]*)[\s\.](ttf|tff|zip))[\'\"]?/i.test(f)===true)
	{
ttf._debug('[parseFontName()] -> 2 match ttf|tff '+font);
		f=/[\'\"]?(([^\'\"]*)[\s\.](ttf|tff|zip))[\'\"]?/i.exec(f);
		f=f[1];
		return font.replace(/\.ttf/i,'',f);
	}
	//if ((p = f.match(/([\"\']*)([^\"^\']+)(\.| )(ttf|tff|zip)/i)))
	//{
	//	return p[2] + "." + p[4];
	//}
	if (ttf.settings && ttf.settings.fontreg)
	{
ttf._debug('[parseFontName()] -> try font reg '+font);
		if (f=f.match(new RegExp(ttf.settings.fontreg)))
		{
			//return font.replace(/\.ttf/i,'',f[1]);
			//return f[1];
			f = ttf.settings.fontcache[f[1]];
			return f.substring(f.lastIndexOf('/')+1);
		}
	}
	return false;//font;
}
//verified OK
ttf.parseFontFaceUrl=function(v)
{
	if (!v) {return "";}
	v=v.toString();
	var match = v.match(/url\(([^\)]+)\)/i);
	if (match && match[1])
	{
		return ttf.trim(ttf.unquote(match[1]));
	}
	var p1 = v.indexOf('src');
	if (p1>-1)
	{
		p1 = v.indexOf(':',p1)+1;
		var p2 = v.indexOf(';',p1);
		if (p2<0)p2=v.length;
		match = v.substring(p1,p2);
		return ttf.trim(ttf.unquote(match));
	}
	return "";
}
//verified OK
ttf.ieCorrectFontSize=function(obj,fontSize)
{
	fontSize=fontSize||ttf.parseStyle(obj,"fontSize");
	var p=obj.parentNode;
	var ps=ttf.parseStyle(p,"fontSize");
	if(fontSize!=ps)
	{
		return false;
	}
	var s=p.style;
	var fs=s.fontSize;
	if(fs&&fontSize!=fs)
	{
		return false;
	}
	s.fontSize="1px";
	var ns=ttf.parseStyle(obj,"fontSize");
	s.fontSize=fs;
	return(ns!=fontSize);
}
//verified OK
function parseEmWidth(obj)
{
	if (!obj || !obj.style)return false;
	var s=obj.style,l=s.left,w;
	s.left='10em';
	w=Math.round(s.pixelLeft/10);
	s.left=l;
	return (!w ? parseEmHeight(obj) : w);
}
//verified OK
function parseEmHeight(obj)
{
	if (!obj || !obj.style)return false;
	var s,w,el;
	el=document.createElement('B');
	s=el.style;
	s.display='block';
	s.lineHeight='1em';
	el.innerHTML='&nbsp;';
	obj.appendChild(el);
	w=(ttf.isOpera ? el.offsetHeight : parseInt(el.offsetHeight*0.88));
	s.display='none';
	return w;
}
//verified OK
function getScriptPath(jsfor)
{
	var src,i,l=jsfor.length,els = document.getElementsByTagName('script');
	for (i=0; i<els.length; i++)
	{
		src = els[i].getAttribute('src');
		if (!src) continue;
		if (src.substring(src.length-l) == jsfor)
		{
			return src.substring(0,src.length-l)
		}
	}
	if(!confirm("Could not detect path for `"+jsfor+"`, continue?")) exit();
	return false;
}

//verified OK
ttf.parseStyle=function(obj,style)
{
	style = (!style?style:style.replace(/-(\D)/g, function(a,b){return b.toUpperCase();}));
	if(!obj)
	{
		return false;
	}
	if(obj.currentStyle)
	{
		return(style?obj.currentStyle[style]:obj.currentStyle);
	}
	else
	{
		if(document.defaultView&&document.defaultView.getComputedStyle)
		{
			return(style?document.defaultView.getComputedStyle(obj,"")[style]:document.defaultView.getComputedStyle(obj,""));
		}
	}
	return(style?"":false);
};


////////////////////////////////////////////
// TTF on_ dispatcher methods [internal only]
////////////////////////////////////////////
ttf.dispatchDelayLoad=function(cfg)
{
	cfg=cfg||window.ttf.config;
	if(cfg.delayedloading)
	{
ttf._debug("[cfg.delayedloading] dispatch delayed loading");
		//if(cfg.sprite)var _2e={};
		var i,im,curr,prev,images=document.tff_inserted_images,l=images.length;
		for(i=0;i<l;i++)
		{
			im=images[i];
			curr=im.node;
			prev=im.before;
			curr.src=im.src;
			if(!cfg.hidetext&&prev.nodeValue!=" ")
			{
				prev.nodeValue=(ttf.isKonqueror?" ":"");
			}
			curr.style.visibility="";
			if(cfg.hidenode)
			{
				prev.parentNode.style.visibility="visible";
			}
			curr=null;
			images[i]=null;
		}
	}
}

ttf.dispatchOnLoad=function(cfg)
{
	cfg=cfg||window.ttf.config;
	if (cfg.onload)
	{
ttf._debug("[cfg.onload] calling onload()");
		if(typeof(cfg.onload)!="function")
		{
			if(cfg.onload.indexOf("(")<0)
			{
				cfg.onload+="()";
			}
			cfg.onload=new Function(cfg.onload);
		}
		var images=document.tff_inserted_images;
		document.tff_inserted_images_loaded=0;
		document.tff_inserted_images_count = images.length;
		var _handled={};
		for(var i=0; i<images.length; i++)
		{
			var im=images[i];
			if (_handled[im.src])
			{
				// unique image already loaded
				document.tff_inserted_images_count--;
			}
			else
			{
				_handled[im.src] = true;
			}
			var curr=im.node;
			curr.prev_onload=im.onload;
			curr.onload = function(){
				if (this.prev_onload)this.prev_onload();
				this.pev_unload=null;
				document.tff_inserted_images_loaded++;
				if (document.tff_inserted_images_loaded == document.tff_inserted_images_count)
				{
					// dispatch onload method; all images loaded
					cfg.onload();
					cfg.onload=null;
					window.ttf.config.onload=null;
				}
			};
		}
		images=null;
	}
}
ttf.dispatchOnComplete=function(cfg)
{
	cfg=cfg||window.ttf.config;
	if(cfg.oncomplete)
	{
ttf._debug("[cfg.oncomplete] calling oncomplete()");
		if(typeof(cfg.oncomplete)!="function")
		{
			if(cfg.oncomplete.indexOf("(")<0)
			{
				cfg.oncomplete+="()";
			}
			cfg.oncomplete=new Function(cfg.oncomplete);
		}
		cfg.oncomplete();
		cfg.oncomplete=null;
		window.ttf.config.oncomplete=null;
	}
}
ttf.dispatchOn=function(on,cfg)
{
	cfg=cfg||window.ttf.config;
	if(cfg[on])
	{
ttf._debug("[ttf.dispatchOn] calling "+on+"()");
		if(typeof(cfg[on])!="function")
		{
			if(cfg[on].indexOf("(")<0)
			{
				cfg[on]+="()";
			}
			cfg[on]=new Function(cfg[on]);
		}
		if(arguments&&arguments[2])cfg[on](arguments[2]);
		else cfg[on]();
		cfg[on]=null;
		window.ttf.config[on]=null;
	}
};

/////////////////////////////////////////////////
// CSS UTILITY
/////////////////////////////////////////////////
(function(){
/**
 * CSSUtil defines some basic CSS utility methods that are used by DSTTF 
 */
CSSUtil = function(doc){
	//public props
	this.doc = doc||document;
	this.linkedstyles = true;
	this.importedstyles = true;
	this.inlinestyles = true;
	this.removeimports = true;
	this.onCleanCss = null;

	//private vars
	var VERSION = '1.0.0';
	var uA=navigator.userAgent;
	var isOpera = uA.match(/opera/i);
	var isOpera8 = isOpera && /opera 8/i.test(uA);
	var isIE = !isOpera && uA.match(/msie/i);
	var isSafari = uA.match(/safari/i);
	var isKonqueror = uA.match(/konqueror/i);
	var isGecko = !isIE && !isOpera && uA.match(/gecko/i);
	var isFireFox = !isIE && !isOpera && uA.match(/firefox/i);
	var isFireFox35 = isFireFox && uA.match(/firefox\/3\.5/i);
	//shortcuts
	var _d=this.doc;
	_d.gt=_d.getElementsByTagName;
	_d.ge=_d.getElementById;
	_d.ce=_d.createElement;

	//private methods
	trim=function(v){return v?v.replace(/^\s*|\s*$/g,''):v;};

	strstrip=function(s,a,b){
		a=a||0;
		if (a<0)a=0;
		if (a>s.length)return s;
		b=b||s.length;
		if (b>s.length)b=s.length; 
		if (b<a)return '';
		return s.substring(0,a)+s.substring(b);
	};

	stripComment=function(src){
		if (!src) {return "";}
		src = src.replace(/(\n|\r|\t)/g, "");
		var p;
		while ((p = src.indexOf("/"+"*")) > -1)
		{
			src = src.substring(0, p) + src.substring(src.indexOf("*"+"/", p) + 2);
		}
		src = src.replace(/\}/gi, "}\n");
		return src;
	};

	matchElement=function(obj, tag, cls, id){
		if (!obj || !obj.tagName) {return false;}
		tag = (tag || "").toUpperCase();
		cls = cls || "";
		id = id || "";
		return (!tag || obj.tagName == tag) && (!cls || obj.className.match(new RegExp("\\b" + cls + "\\b"))) && (!id || obj.id == id);
	};

	flattenStructure=function(){
		var result = new Array(0);
		for (var a = 0, l = arguments.length; a < l; a++) {
			for (var i = 0, al = arguments[a].length; i < al; i++) {
				result[result.length] = arguments[a][i];
			}
		}
		return result;
	};

	getXFer=function(){
		if (window.XMLHttpRequest) return new XMLHttpRequest();
		else if (window.ActiveXObject){
			try{
				return new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e){
				try {return new ActiveXObject("Microsoft.XMLHTTP");}
				catch (e) {}
			}
		}
		return null;
	};

	getXFile=function(url, method){
		method = method || "GET";
		var c=getXFer();
		if (!c) {return "";}
		try
		{
			if (method == "POST")
			{
				url = url.split("?");
				var data = url[1];
				url = url[0];
			}
			c.open(method, url, false);
			if (method == "POST")
			{
				url = data;
				try
				{
					c.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				}
				catch (e) {}
			}
			c.send(url);
			return c.status == 200 || c.status == 304 ? c.responseText : "";
		}
		catch (e) {return "";}
	};

	cleanCss=function(v){
		if (!v) {return "";}
		v = stripComment(v);
		if (this.onCleanCss) v = this.onCleanCss(v);
		return v;
	};

	//public methods
	this.getVersion=function(){return VERSION;};

	this.loadStyleSheet=function(url){
		var head;
		if (!url || typeof(url)!='string') return;
		head = _d.gt('head')[0];
		url = url.split(',');
		for(var i=0; i<url.length; i++)
		{
			var curl=url[i],link;
			link = _d.ce('link');
			link.rel = 'stylesheet';
			link.type = 'text/css';
			link.href = curl;
			//link.media = 'screen';
			// IE 8 produces a '1 item remaining' bug when dynamically loading stylesheets.
			// This nasty 'onload recalc()' hack seems to resolve that issue.
			if (isIE && this.doc.documentMode) {
				link.onload = function() {
					this.doc.recalc();
					link.onload = null;
				};
			}
			head.appendChild(link);
		}
	};

	this.getCssSource=function(){
		var i, p1, p2, str, rawsrc = "";
		if (this.linkedstyles)
			rawsrc += this.getLinkedCSSSource();

		if (this.inlinestyles)
		{
			//opera 8 does not seem to handle STYLE elements?
			if (isOpera8) 
			{
				var html = getXFile(_d.location.toString());
				var styletags;
				if ((styletags = html.match(/<style([^>]*)>([^<]+)<\/style>/gi)))
				{
					for (var i = 0, l = styletags.length; i < l; i++)
					{
						rawsrc += cleanCss(styletags[i].match(/<style([^>]*)>([^<]+)<\/style>/i)[2]);
					}
				}
			}
			//get STYLE elements
			var col = _d.gt("STYLE");
			for (i = 0, l = col.length; i < l; i++)
			{
				if (!col[i].disabled && (str = col[i].innerHTML))
				{
					rawsrc += (rawsrc ? "\n\n" : "") + cleanCss(str);
				}
			}
			col=null;
		}
		if (this.importedstyles)
		{
			while ((p1 = rawsrc.indexOf("@import", p1)) > -1)
			{
				p2 = rawsrc.indexOf(";", p1);
				str = rawsrc.substring(p1, p2);
				p1 = p2;
				str = trim(str.replace(/(@import|url|\(|\)|\{|\}\;|\"|\')/g, ""));
				if ((p2 = str.indexOf(" ")) > -1) {str = str.substring(0, p2);}
				rawsrc += (rawsrc ? "\n\n" : "") + cleanCss(getXFile(str));
			}
		}
		if (this.removeimports)
		{
			while ((p1 = rawsrc.indexOf("@import")) > -1)
			{
				p2 = rawsrc.indexOf(";", p1) + 1;
				rawsrc = strstrip(rawsrc, p1, p2);
			}
		}
		return rawsrc;
	};

	this.getLinkedCSSSource=function(){
		var i, o, v = "", elmts = _d.gt("LINK");
		for (i=0, l=elmts.length; i<l; i++)
		{
			o=elmts[i];
			if (o && !o.disabled && o.rel=="stylesheet" && o.href && o.href!=_d.location && (!o.media || o.media=="screen" || o.media=="all"))
			{
				v += (v?"\n\n":"")+cleanCss(getXFile(o.href));
			}
		}
		col=null;
		return v;
	};

	this.getAllCssMatches=function(obj, tag, cls, id){
		var rs;
		obj=obj||_d;
		if (id)
		{
			rs = _d.ge(id);
			return rs ? new Array(rs) : new Array(0);
		}
		var elmts = (!tag && obj.all) ? obj.all : obj.getElementsByTagName(tag || "*");
		if (!cls && !id)
		{
			return elmts;
		}
		rs = new Array(0);
		for (var i=0, l=elmts.length; i<l; i++)
		{
			if (matchElement(elmts[i], tag, cls, id))
			{
				rs.push(elmts[i]);
			}
		}
		return rs;
	};

	this.findCssClasses=function(src, cssprop){
		var p1,p2,plen=cssprop.length, rawmatch, _cselector, _crule, _cproperty, _cvalue, rawsrc=src||"";
		var result = new Array(0);
		// find cssprop
		while ((p1 = rawsrc.indexOf(cssprop)) > -1)
		{
			//do we have a '-' after the cssCls?
			if (rawsrc.substring(p1 + plen, p1 + plen + 1) == "-")
			{
				if (cssprop != "font" || rawsrc.substring(p1 + plen + 1, p1 + plen + 7) != "family")
				{
					p1 += cssprop.length + 1;
					p2=rawsrc.indexOf("}", p1);
					rawsrc = rawsrc.substring(p2+1);
					continue;
				}
			}
			//seek end of this selector/class
			p2=rawsrc.indexOf("}", p1);
			//set rwa match and chop raw source
			rawmatch = rawsrc.substring(0,p2);
			rawsrc = rawsrc.substring(p2+1);
			//drop junk
			p1=rawmatch.lastIndexOf("}") + 1;
			rawmatch = rawmatch.substring(p1)+'}';

			// parse selector and rule
			_cselector = trim(rawmatch.substring(0, rawmatch.indexOf("{")));
			p1 = rawmatch.indexOf(cssprop);
			p2 = rawmatch.indexOf(";",p1);
			p2 = (p2>-1?p2:rawmatch.length-1);
			_crule = trim(rawmatch.substring(p1, p2));
			// parse css property and value
			p1 = _crule.indexOf(":");
			_cproperty = trim(_crule.substring(0, p1));
			_cvalue = trim(_crule.substring(p1 + 1));
			result[result.length] = {match: rawmatch, selector: _cselector, rule: _crule, property: _cproperty, value: _cvalue};
		}
		return result;
	};

	this.getElementsForCssSelector=function(selectors){
		var els = new Array(0);
		if (!selectors) {return els;}
		selectors = selectors.split(",");
		for (var t = 0, l = selectors.length; t < l; t++)
		{
			var tag = trim(selectors[t]);
			var col = new Array(0);
			var pos = 0;
			if ((pos = tag.lastIndexOf("#")) > -1)
			{
				tag = tag.substring(pos);
			}
			var _dd = tag.split(" ");
			for (var s = 0, sl = _dd.length; s < sl; s++)
			{
				var sel = trim(_dd[s]);
				sel = sel.split(".");
				tag = sel[0];
				var cls = sel.length > 1 ? sel[1] : "";
				sel = cls ? cls : tag;
				sel = sel.split("#");
				var id = sel.length > 1 ? sel[1] : "";
				if (id)
				{
					if (cls)
					{
						cls = sel[0];
					}
					else
					{
						tag = sel[0];
					}
				}
				if (s == 0)
				{
					col = this.getAllCssMatches(_d, tag, cls, id);
				}
				else
				{
					var tmp = col;
					col = new Array(0);
					for (var c = 0, cl = tmp.length; c < cl; c++)
					{
						col = flattenStructure(col, this.getAllCssMatches(tmp[c], tag, cls, id));
					}
				}
			}
			els = flattenStructure(els, col);
		}
		return els;
	};

}
})();

/////////////////////////////////////////////////
// TTF DEBUG UTILITY
/////////////////////////////////////////////////
(function(){
	ttf.Debug = function(){
		var __debug = [];
		this.clear = function(){
			__debug = [];
		};
		this.debug=function(m){
			__debug.push(m);
		};
		this.show=function(ret){
			ret=ret||false;
			if (ret)return this.getAll();
			else alert(this.getAll());
		};
		this.getAll=function(){
			return __debug.join('\n');
			this.clear();
		};
	};
	ttf.Debug = new ttf.Debug();
})();

/////////////////////////////////////////////////
// TTF XHTTP UTILITY
/////////////////////////////////////////////////
(function(){
	ttf.XHttp = function(){
		this.get = function(){
			if (window.XMLHttpRequest) return new XMLHttpRequest();
			else if (window.ActiveXObject){
				try{
					return new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e){
					try {return new ActiveXObject("Microsoft.XMLHTTP");}
					catch (e) {}
				}
			}
			return null;
		};
		this.getFile = function(url, method){
			method = method || "GET";
			var c=ttf.XHttp.get();
			if (!c) {return "";}
			try
			{
				if (method == "POST")
				{
					url = url.split("?");
					var data = url[1];
					url = url[0];
				}
				c.open(method, url, false);
				if (method == "POST")
				{
					url = data;
					try
					{
						c.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					}
					catch (e) {}
				}
				c.send(url);
				return c.status == 200 || c.status == 304 ? c.responseText : "";
			}
			catch (e) {return "";}
		};

		this.fileExists=function(url){
			try
			{
				var c=ttf.XHttp.get();
				c.open("GET", url, false);
				c.send(url);
				return (c.status == 200 || c.status == 304);
			}
			catch (e) {return false;}
		}
	};
	ttf.XHttp = new ttf.XHttp();
})();

/////////////////////////////////////////////////
// TTF FONT CACHE UTILITY
/////////////////////////////////////////////////
(function(){
	/* TTF Cache for storing font references */
	TTFCache = function(){
		var cache = {};
		var keys = [];
		var re=null;

		this.has = function(f,cs){
			if (!re)re=new RegExp();
			re.compile(f, cs?'':'i');
			return re.test('('+keys.join('|')+')');
		},
		this.add = function(f,u){
			if (!this.has(f)){
				keys.push(f);
				cache[f] = u;
			}
		},
		this.get = function(f){
			if (this.has(f))
				return cache[re.exec('('+keys.join('|')+')')];
			return null;
		},
		this.clear=function(){
			cache={};keys=[];re=null;
		}
	}
	ttf.cache = new TTFCache();
})();

/////////////////////////////////////////////////
// MAIN SCRIPT EXECUTION.
// Attach ttf loader to document body's onload()
/////////////////////////////////////////////////
(function attach_ttf(){
	if(/opera 8/i.test(ttf.ua))
	{
		(function() {if(document.body) { ttfu_init(); } else { setTimeout(arguments.callee,1); }})();
	}
	else
	{
		if(ttf.isIE&&!ttf.isOpera)
		{
			if(/Win32/i.test(navigator.platform))
			{
				document.write("<script id=\"__ie_onload\" defer src=\""+((location.protocol=="https:")?"//0":"javascript:void(0)")+"\"></script>");
				document.getElementById("__ie_onload").onreadystatechange=function()
				{
					if(this.readyState=="complete")
					{
						ttfu_init();
					}
				}
			}
			else
			{
				if(window.addEventListener)
				{
					window.addEventListener("load",ttfu_init,false);
				}
				else if(window.attachEvent)
				{
					window.attachEvent("onload",ttfu_init);
				}
			}
		}
		else
		{
			if(/WebKit|khtml/i.test(ttf.ua))
			{
				window.tffTimer=setInterval(function(){
						if(/loaded|complete/.test(document.readyState)){clearInterval(window.tffTimer);delete window.tffTimer;ttfu_init(); } }
						,10
					);
			}
			else
			{
				if(document.addEventListener)
				{
					document.addEventListener("DOMContentLoaded",ttfu_init,false)
				}
			}
		}
	}
}
)();

//-------------------------
/*
ttf.getStyle=function(el,nam,cls)
{
	//Gecko/FF: defaultView, IE/Opera: currentStyle
	if (document.defaultView && cls)
	{
		//modify camel casing to -+lower
		nam = nam.replace(/[A-Z]/g, function(c){ return '-'+c;});
		try
		{
			return document.defaultView.getComputedStyle(el, null).getPropertyValue(nam);
		}
		catch(e) { return null; }
	}

	//camel case if needed
	nam = nam.replace(/-\D/g, function(a,b){return a.toUpperCase();});
	//set correct name for css float property
	if (nam=='float')nam=ttf.isIE?'styleFloat':'cssFloat';

	if (el.currentStyle) 
		return el.currentStyle[nam];
	return el.style[nam];
}
function parseFontSize(fSize,scaling)
{
	if(fSize==null)
	{
		return 0;
	}
	if(fSize.match(/(small|smaller|normal|medium|larger|large)/i))
	{
		fSize=defSizes[fSize];
	}
	if(fSize.match(/^((\+|\-)*)([0-9])$/))
	{
		if(fSize.match(/^(\+|\-)/))
		{
			fSize=3+parseInt(fSize);
		}
		fSize=Math.min(fSize,7);
		fSize=defSizes[fSize]||"100%";
	}
	if(ttf.isOpera&&isNaN(parseInt(fSize)))
	{
		fSize=defSizes[fSize]||"100%";
	}
	var cSize;
	if(cSize=fSize.toString().match(/^([0-9\.]+)((px|pt|pc|in|cm|mm|%|em|ex)*)$/i))
	{
		if(cSize[2]=="px")
		{
			return fSize;
		}
		if(cSize[2]=="pt")
		{
			return parseInt(pt2px(cSize[1]))+"px";
		}
		if(cSize[2]=="pc")
		{
			return parseInt(pc2px(cSize[1]))+"px";
		}
		if(cSize[2]=="in")
		{
			return parseInt(in2px(cSize[1]))+"px";
		}
		if(cSize[2]=="cm")
		{
			return parseInt(cm2px(cSize[1]))+"px";
		}
		if(cSize[2]=="mm")
		{
			return parseInt(mm2px(cSize[1]))+"px";
		}
		if(cSize[2]=="ex")
		{
			fSize=(cSize[1]/2)+"em";
		}
		if(cSize[2]=="%")
		{
			fSize=(cSize[1]/100)+"em";
		}
		return(scaling?Math.round(fSize.substring(0,fSize.length-2)*parseInt(scaling))+"px":fSize);
	}
	return fSize;
}
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}
//addLoadEvent(ttfu_init);

function ttfu_init1(){
  var els=document.getElementsByClassName('ttfu');
//ttf._debug('ttfu_init-> '+els.length);
  for (var i=els.length-1; i>=0; i--)
  {
	  var cel=els[i];
	  var txt = null;
	  if (cel.innerHTML)txt=cel.innerHTML;
	  else if (cel.textContent)txt=cel.textContent;
	  else if (cel.textContents)txt=cel.textContents;
	  //var font = (els[i].style.fontFamily?els[i].style.fontFamily:'Verdana');
	  var font=ttf.parseStyle(cel,'font-family');
	  var fsize=ttf.parseDefaultFontSize(cel);
	  var fbcol=ttf.parseBackColor(cel);
	  var fcol=ttf.parseColor(ttf.parseStyle(cel,'color'));

	  if (/['"]([^'"]*)['"]/i.test(font)===true)
	  {
		  font=/['"]([^'"]*)['"]/i.exec(font);
		  font=font[1];
	  }
	  font=ttf.escape(font.replace(/\.ttf/i,'',font));

	  var img = document.createElement('img');
	  img.src = 'http://127.0.0.1/prot/eszenzz.nl/DSONE_CMS/font.php?s='+txt;
	  //img.src += '&f='+font;
	  //img.src += '&fs='+fsize;
	  //img.src += '&c='+fcol;
	  //img.src += '&r=255&g=0&b=128';

	  img.src += ttf.makeSrcQSA(cel);

	  img.title = img.alt = txt;
	  cel.parentNode.replaceChild(img,cel);
  }
}
*/
