//FontTool Class v1.01
function FontTool(){
		// BASIC SETTINGS
		//Element settings
		this.elementId = "";
		this.elementTag = "h1";
		
		//Flash Settings
		this.bgColor="ffffff";					// Body background color
		this.frameColor="0x000000";  
		this.frameEnabled = false;
		this.swfWidth;// = 425;					// Swf dimensions
		this.charsPerLine = 20;
		this.swfHeight = 24; 					// Sættes til højden for en enkelt linie
		this.swfName = "B14_Font_Kontrapunkt_16"; 
		this.textX = -3;
		this.textY = 0;
		this.fontSize = 16;
		
		//Debug settings
		this.alertsEnabled = false;
	
	//Flash Variables
	this.swfId = this.swfName;
	this.language = "DA";
	this.testVersion = "";
	this.id = "";
	this.page = "";
	this.swfShortName= this.swfName+this.testVersion; // Test : versionOK.swf
	this.swfFilename = this.swfShortName+".swf";
	this.version = 1171636778;
	this.flashvars = "version="+this.version+"&amp;language="+this.language+"&amp;testVersion="+this.testVersion+"&amp;id="+this.id+"&amp;page="+this.page+"&amp;fontSize="+this.fontSize+"&amp;textX="+this.textX+"&amp;textY="+this.textY;
	if(this.frameEnabled)
		this.flashvars += "&amp;frameColor="+this.frameColor;
}
//FontTool.prototype.testVar;

var fontTool = new FontTool;

//Finds one element by id
FontTool.prototype.masterUpdateById = function(){
	this.showAlert("elementId is ");
	var _element;
	if(this.elementId){
		this.showAlert("elementId is "+this.elementId);
		_element = document.getElementById(this.elementId);
		if(_element)
		{
			this.showAlert("_element is set");
			//sætter indhold i forhold til an attribute
			//_element.innerHTML = embedFlash(title.getAttribute('text'));
			//Replaces element with swf
			_element.innerHTML = _element.innerHTML.toUpperCase();
			this.swfWidth = _element.offsetWidth;
			this.swfHeight = _element.offsetHeight;
			alert("hej" + _element.innerHTML);
			_element.innerHTML = this.embedFlash(_element.innerHTML);			
		}
		else
			this.showAlert("No _element");
	}
	else
		this.showAlert("elementId isnt set "+elementId);
}

FontTool.prototype.masterUpdateByTag = function(){
	
	if(this.elementTag)
		this.showAlert("elementTag is "+this.elementTag);
	var elementsByTagArray = document.getElementsByTagName(this.elementTag);
	
	if(elementsByTagArray)	
		this.showAlert("elementsByTagArray is set");
	else
		this.showAlert("elementsByTagArray isnt set");
	//Loops and replaces all elements with swf		
	for(var elementNo = 0 ; elementNo < elementsByTagArray.length ; elementNo++){
		var _element =  elementsByTagArray[elementNo];
		this.showAlert(elementNo + " / " + _element.innerHTML.toUpperCase());
		_element.innerHTML = _element.innerHTML.toUpperCase();
		this.swfWidth = _element.offsetWidth;
		this.swfHeight = _element.offsetHeight;
		_element.innerHTML = this.embedFlash(_element.innerHTML);
	}
}


FontTool.prototype.occurencesOf = function(string, subStr){
	var count = 0;
	var lastPos = 0;
	while( lastPos != -1 ){
		lastPos = string.indexOf(subStr, lastPos);
		if(lastPos != -1){
			count++;
			lastPos++;
		}
	}
	return count;
}

FontTool.prototype.embedFlash = function( text ){
	//alert(this.swfHeight + " / " + unescape(this.swfHeight) );
	var tempFlashvars = this.flashvars;
	tempFlashvars += "&amp;titleText="+unescape(text)+"&amp;swfWidth="+this.swfWidth+"&amp;swfHeight="+this.swfHeight;
	return '<table cellpadding="0" cellspacing="0"><tr><td align="left" width="'+this.swfWidth+'" height="'+this.swfHeight+'">'
	+ '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width="'+this.swfWidth+'" height="'+this.swfHeight+'"'
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
    + '<param name="movie" value="/'+this.swfFilename+'?version='+this.version+'" /><param name="quality" value="high" /><param name="bgcolor" value="'+this.bgColor+'" />'
    + '<param name="allowScriptAccess" value="sameDomain" /><PARAM NAME="FlashVars" VALUE="'+tempFlashvars+'"/>'
	+ '<embed src="/'+this.swfFilename+'?version='+this.version+'" FlashVars="'+tempFlashvars+'" quality="high" bgcolor="'+this.bgColor+'" '
	+ 'width="'+this.swfWidth+'" height="'+this.swfHeight+'" name="'+this.swfName+'" aligh="left" id="'+this.swfId+'"'
	+ 'play="true"'
	+ 'loop="false"'
	+ 'quality="high"'
    + 'wmode="transparent"'
	+ 'allowScriptAccess="sameDomain"'
	+ 'type="application/x-shockwave-flash"'
	+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
	+ '<\/embed>'
	+ '<\/object>'	
	+ '</td></tr></table>';
	
	}


FontTool.prototype.showAlert = function(alertText){
	if(this.alertsEnabled) alert(alertText);
}	
