// Inpact - DHTML library / FileReader - www.inpact.nl
// --------------------------------------------------------

var readContent = "";
var targetDiv = "";
var dynReader = null;

dynProto.read = dynObjectRead;

function dynObjectRead(src) {
	if(!dynLoaded) return;
	if(!parent.bufferFrame && !is.NS4) {
		alert('bufferFrame not found!');
		return;
	}
	
	if(!is.NS4) this.write(' &#187; Loading ... ');
	dynReader.requestFile(src, this.id);
}

function fileReader() {
	this.frame = 'bufferFrame';
	this.files = [];
	this.divs  = [];
	this.pos = 0;
	this.atFile = 0;
	this.busy = false;	
	this.target = null;
}	dynReader = new fileReader();

fileProto = fileReader.prototype;
fileProto.requestFile = fileReaderRequest;
fileProto.sendFile = fileReaderSend;
fileProto.readFile = fileReaderRead;

	function fileReaderRequest(src, div) {
		this.files[this.pos] = src;
		this.divs[this.pos] = div;
		this.pos ++;

		if(!this.busy) {
			this.busy = true;
			this.readFile();			
		}	
	}

	function fileReaderRead() {
		if(is.NS4) {
			targetDiv = this.divs[this.atFile];
			this.target = document.dyn[targetDiv] || attachObject(targetDiv);
			this.target.layer.src = this.files[this.atFile];
		} else {
			parent[this.frame].document.location.replace(this.files[this.atFile]);
		}
	}

	function fileReaderSend() {
		if(!is.NS4) {
			readContent = parent.frames[this.frame].document.body.innerHTML;		
			targetDiv = this.divs[this.atFile];
			this.target = document.dyn[targetDiv] || attachObject(targetDiv);
			if(is.NS6) readContent = unescape(readContent);
			this.target.write(readContent);
		}

		for(var i=0; i<document.bars.length; i++) {
			var dynBar = document.bars[i];
			if(targetDiv == dynBar.currentLyrId) {
				dynBar.setLayer(dynBar.currentLyrId);				
			}			
		}
		
		this.atFile ++;		
		if(this.pos > this.atFile) this.readFile();
		else this.busy = false;
	}

function doneLoading() {	
	if(!dynLoaded) return;
	dynReader.sendFile();
}