var window_onresize = function () {
	var height = blockDecoration.offsetHeight;
	var documentHeight = blockContent.offsetHeight + 155;
	var k = 400;
	var newHeight = documentHeight + k;
	
	if (newHeight < 900) {
		newHeight = 900;
	}
	
	blockDecoration.style.height = newHeight + 'px';
	if (typeof document.recalc != 'undefined') {
		document.recalc();
	}
}

var window_onload = function () {
	blockDecoration = document.getElementById('block-decoration'); 
	blockContent    = document.getElementById('block-content');
	tableProducts   = document.getElementById('table-products');
	
	if (tableProducts) {
		window.productsRows = tableProducts.getElementsByTagName('TBODY')[0].getElementsByTagName('TR');
		window.productsRowsCount = productsRows.length;
		window.productsIterator = 0;
		
		var buttons = tableProducts.getElementsByTagName('THEAD')[0].getElementsByTagName('A');
		
		buttons[0].onclick = buttonPreviousProducts_onclick;
		buttons[1].onclick = buttonNextProducts_onclick;
	} 
}


var buttonNextProducts_onclick = function (event) {
	++ productsIterator; 
	
	if (productsIterator == productsRowsCount) {
		productsIterator = 0;
	}
	
	_setProductsRows();
	
	
	return false;
}

var buttonPreviousProducts_onclick = function (event) {
	-- productsIterator; 
	
	if (productsIterator == -1) {
		productsIterator = productsRowsCount - 1;
	}

	_setProductsRows();
	
	return false;
}

var _setProductsRows = function () {
	for (var i = 0; i < productsRowsCount; ++ i) {
		productsRows[i].className = 'hidden';
	}
	
	productsRows[productsIterator].className = '';
	productsRows[productsIterator].style.display = '';
}

if (typeof(window.addEventListener) != 'undefined') {
	
	window.addEventListener('resize', window_onresize, false);
	window.addEventListener('load',   window_onload,   false);
	window.addEventListener('load',   window_onresize, false);
	
} else if (typeof(window.attachEvent) != 'undefined') {

	window.attachEvent('onresize', window_onresize);
	window.attachEvent('onload',   window_onresize);
	window.attachEvent('onload',   window_onload);
	
} else {

	window.onresize = window_onresize;
	window.onload   = function () {
		window_onload();
		window_onresize();
	}
	
}
