// Dependencies - path.js, divfx.js

// Retro demofx

function createBar(id, top, height, colors, transparent, pos) {
	bar = document.createElement("div");
	if (pos == 'undefined')
	{
		bar.style.position = "relative";
	}
	else
	{
		bar.style.position = pos;
	}
	bar.style.top = top;
	bar.style.left = "0px";
	bar.id = id;
	bar.style.width = scrollwidth;
	body.appendChild(bar);
	bar = document.getElementById(id);
	var h = parseInt(height);
	cl = (colors.length) / h;
	for(var j = 0; j < h; j+=2) {
		c = colors[parseInt(cl * j)];
		if (c == transparent) continue;
		for(var i = 0; i < scrollwidth; i+=4) {
			d = addPixel(j+"px", i+"px", c, bar);
			d.style.height = "2px";
		}
	}
	bar.style.height = "2px";
	bar.style.fontSize = "2px";
	return bar;
}

// Make a few bars (3 seems to be the limit on moz) using barpath as the path
function makeBars(barpath, bars) {
	var barheight = "16px";

	var bcolors = new Array();
	bcolors[0] = new Array();
	bcolors[0][0] = '#BBFFBB';
	bcolors[0][1] = '#88BB88';
	bcolors[0][2] = '#448844';
	bcolors[0][3] = '#004400';
	bcolors[0][4] = '#004400';
	bcolors[0][5] = '#448844';
	bcolors[0][6] = '#88BB88';
	bcolors[0][7] = '#BBFFBB';

	bcolors[1] = new Array();
	bcolors[1][0] = '#FFBBBB';
	bcolors[1][1] = '#BB8888';
	bcolors[1][2] = '#884444';
	bcolors[1][3] = '#440000';
	bcolors[1][4] = '#440000';
	bcolors[1][5] = '#884444';
	bcolors[1][6] = '#BB8888';
	bcolors[1][7] = '#FFBBBB';

	bcolors[2] = new Array();
	bcolors[2][0] = '#BBBBFF';
	bcolors[2][1] = '#8888BB';
	bcolors[2][2] = '#444488';
	bcolors[2][3] = '#000044';
	bcolors[2][4] = '#000044';
	bcolors[2][5] = '#444488';
	bcolors[2][6] = '#8888BB';
	bcolors[2][7] = '#BBBBFF';

	bcolors[3] = new Array();
	bcolors[3][0] = '#FFFFBB';
	bcolors[3][1] = '#BBBB88';
	bcolors[3][2] = '#888844';
	bcolors[3][3] = '#444400';
	bcolors[3][4] = '#444400';
	bcolors[3][5] = '#888844';
	bcolors[3][6] = '#BBBB88';
	bcolors[3][7] = '#FFFFBB';

	bp = barpath.points();
	for(i = 0; i < bars; i++) {
		createBar('bar'+i, 0, barheight, bcolors[i & 3]);
		switch(i & 3) {
			case 0:
				barpath.addIndex(i, i, 1);
				break;
			case 1:
				barpath.addIndex(i, i, -1);
				break;
			case 2:
				barpath.addIndex(i, bp-i, 2);
				break;
			case 3:
				barpath.addIndex(i, bp-i, -2);
				break;
		}
	}
}

