var static_prefix = '';
var div = document.getElementById('lovetree_image');
var min_y = 50;
var offset = 120;

var items = new Array();
var branches = new Array();

function i(code, x, y)
{
	items.push([ code, x, y ]);

	if (y < min_y)
		min_y = y;
}

function b(x, y, angle, variant)
{
	branches.push([ x, y, angle, variant ]);

	if (y < min_y)
		min_y = y;
}

function render()
{
	var height = offset - min_y + 290;
	div.style.height = height + 'px';

	for (var i = 0; i < branches.length; i++) {

		var branch = branches[i];
		var x = branch[0];
		var y = branch[1];
		var angle = branch[2];
		var variant = branch[3];

		var age = branches.length - i;

		var thickness1 =
			(age > 25000) ? 16 :
			(age > 15000) ? 15 :
			(age > 10000) ? 14 :
			(age > 4000) ? 13 :
			(age > 2000) ? 12 :
			(age > 1000) ? 11 :
			(age > 500) ? 10 :
			(age > 300) ? 9 :
			(age > 200) ? 8 :
			(age > 150) ? 7 :
			(age > 120) ? 6 :
			(age > 70) ? 5 :
			(age > 50) ? 4 :
			(age > 20) ? 3 :
			(age > 5) ? 2 :
			1;

		var thickness2 = Math.round((branches.length - i) * 16 / branches.length);

		if (thickness2 < 1)
			thickness2 = 1;

		var thickness = (thickness1 < thickness2) ? thickness1 : thickness2;

		var el = document.createElement('IMG');
		el.src = static_prefix + '/st/branches/' + angle + '-' + thickness + '-' + variant + '.gif';
		el.style.position = 'absolute';
		el.style.left = (x + 135) + 'px';
		el.style.top = (y + offset - min_y) + 'px';
		div.appendChild(el);
	}

	for (var i = 0; i < items.length; i++) {

		var item = items[i];
		var code = item[0];
		var x = item[1];
		var y = item[2];

		var el = document.createElement('IMG');
		el.src = static_prefix + '/st/loveitems/' + code + '.gif';
		el.style.position = 'absolute';
		el.style.left = (x + 135) + 'px';
		el.style.top = (y + offset - min_y) + 'px';
		div.appendChild(el);
	}
}
