/*
	autoslide.js

	License: New BSDL
*/

var AutoSlide = function() {
}

$_ = AutoSlide.prototype;

$_.run = function(interval) {
	this.offset = 0;
	this.source = document.getElementById('source');
	this.target = document.getElementById('target');
	this.cell = document.getElementById('cell');
	this.show();
	setInterval( 'autoslide.show()', interval );
}

$_.show = function() {
	with (this) {
		var page = source.value.split("----");
		with (target.style) {
			fontSize = "10px";
			display  = "inline";
		}
		target.innerHTML = page[offset].replace(/^[\r\n]+/g,"").replace(/[\r\n]+$/g,"").replace(/(\r\n|[\r\n])/g,"<br>");

		offset++;
		if (!page[offset])
			offset = 0;

		var body_w = document.body.offsetWidth;
		var body_h = document.body.offsetHeight;
		var output_w = target.offsetWidth;
		var new_fs = Math.ceil((body_w/output_w) * 9);
		if (new_fs > 10000)
			return;

		cell.style.height = body_h;

		with (target.style) {
			fontWeight = "900";
			fontSize = new_fs + "px";
			display  = "block";
		}
		var output_h = target.offsetHeight;
		if (output_h > body_h) {
			var new_fs = Math.ceil((body_h/output_h) * new_fs * 1.0);
			with (target.style) {
				fontSize = new_fs + "px";
			}
		}
	}
}

autoslide = new AutoSlide();

