KoMObject=new Object();

KoMObject.ReplaceManager=function(arrElements,width, backgroundColor){
	this.elements=arrElements;
	//alert(this.elements.toString());
	this.params=new Array();
	this.pointer=0;
	//alert("Width:"+width);
	//this.setParam("elementTagName",elementTagName);
	//this.setParam("flashMovie",flashMovie);
	this.setParam("width",width);
	this.setParam("backgroundColor",backgroundColor);
}

KoMObject.ReplaceManager.prototype={
	process: function (){
		this.getHeadersCollection();
		this.processNextElement();	
	},
	getHeadersCollection: function (){
		this.finalElements=new Array();
		for (var i in this.elements){
			for (j=0; j<this.elements[i].length; j++){
				this.elements[i][j].id=i+"_"+j;
				this.finalElements[this.finalElements.length]=new Array(i,this.elements[i][j]);
				
			//	alert(i+":"+this.elements[i][j].innerHTML)
			}
		}
	},
	addElement: function (element){
		this.elements.push(element);	
	},
	getNextElement: function(){
		if(this.pointer<(this.finalElements.length+1)){
			var myElement= this.finalElements[this.pointer];
			this.pointer++;	
			//alert(myElement.id);
			return myElement;
			
		} else return null;
	},
	replaceHeader: function(element){
		
		if((element[1].childNodes[0].nodeValue)!=null){
			var myText=element[1].childNodes[0].nodeValue;			
		} else {
			var myText=escape("<a href='"+element[1].childNodes[0].getAttribute("href")+"'>"+element[1].childNodes[0].childNodes[0].nodeValue+"</a>");
			//alert("Mytext:"+myText);
		}
		
		
		
		var so = new SWFObject(element[0], element[1].id+"_", this.getParam('width'), '60', '7', this.getParam('backgroundColor'));
		//alert(this.getParam('width'));
		so.addParam("wmode","transparent");		
		so.addVariable("textcontent", myText); // this line is optional, but this example uses the variable and displays this text inside the flash movie
		so.addVariable("id", element[1].id); // this line is optional, but this example uses the variable and displays this text inside the flash movie
		so.addVariable("textwidth", this.getParam('width')); 
		so.write(element[1].id);	
		
		
	},
	setParam: function (name, value){
		this.params[name]=value;	
	},
	getParam: function (name){
		return this.params[name];	
	},
	setElementSize: function (id, width, height){
		//alert("SetElementSize:"+id+","+width+","+height);
		width=parseInt(width);
		height=parseInt(height);
		if(document.all && !document.getElementById) {
			//document.all[id].style.pixelWidth = datoX;
			document.all[id].style.pixelHeight = height+"px";
			document.all[id+"_"].style.pixelHeight = height+"px";
			document.all[id+"_"].height = height;
		}else{
		//	document.getElementById(id).style.width = datoX;
			//document.getElementById(id).style.height = height+"px";
			//document.getElementById(id+"_").style.height = height+"px";
			document.getElementById(id+"_").height = height;
		}
		//alert(document.getElementById(id+"_").height);
		this.processNextElement();
		
	},
	processNextElement: function (){
		var myNextElement=this.getNextElement();
		if(myNextElement!=null) this.replaceHeader(myNextElement);
	}
}


if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
var ReplaceManager=KoMObject.ReplaceManager;




function setNewSize(id, width,height) {
	//alert("Global setNewSize:"+id+","+width+","+height);
	myReplaceManager.setElementSize(id, width, height);
}
