/// <reference path="json2.js" />
/// <reference path="date.format.js" />
/// <reference path="jquery.intellisense.js" />
/// <reference path="jquery.ajaxdotnet.intellisense.js" />
/// <reference path="google-intellisense.js" />

$(document).ready(function() {
	setTreeSize();
});

$(window).resize(function() {
	var tree = $('#homepageContainer .left');
	var timer = Number(tree.attr('timer'));
	
	if (!isNaN(timer))
		clearTimeout(timer);
		
	tree.attr('timer', setTimeout(function() {
		setTreeSize();
	}, 500));
});


function setTreeSize() {
	var ratio = 1.052;
	var tree = $('#homepageContainer .left');
	var height = tree.height();
	var width = tree.width();
	var minWidth = Math.round(height * ratio);
	width = width < minWidth ? minWidth : width;
	
	height = Math.ceil(height / 50) * 50;
	width = Math.ceil(width / 50) * 50;
	
	var src = 'hp.ashx?h=' + height + '&w=' + width +'&d=2';
	
	tree.css({
		'background-image': 'url(images/ldr.gif)'
	});
	
	var img = new Image();
	img.onload = function() {
		tree.css({
			'background-image': 'url(' + src + ')'
		});
	}
	img.src = src;
}