// JavaScript Document
function initTenYears(){
	if(!document.getElementById('tenYears')) return;
	
	var table = document.getElementById('tenYears');
	
	hideCol(table, 5);
	hideCol(table, 6);
	hideCol(table, 7);
	hideCol(table, 8);
	hideCol(table, 9);
	hideCol(table, 10);
	
	table.setAttribute('previousCol', null);
	table.setAttribute('nextCol', 5);
	table.setAttribute('cols', 10);
	
	var caption = document.createElement('caption');
	var captionHTML = '';
		captionHTML += '<div>';
			captionHTML += '<a href="javascript:showPreviousCol(document.getElementById(\'tenYears\'), 4);" class="previous">«</a>';
			captionHTML += '<a href="javascript:showNextCol(document.getElementById(\'tenYears\'), 4);" class="next">»</a>';
		captionHTML += '</div>';
		
	caption.innerHTML = captionHTML;
	table.insertBefore(caption, (table.getElementsByTagName('thead')[0]))
}

function showPreviousCol(table, maxColumns){
	var previousCol = parseInt(table.getAttribute('previousCol'));
	if(isNaN(previousCol)) return;
	
	var cols = parseInt(table.getAttribute('cols'));
	
	showCol(table, previousCol);
	hideCol(table, (previousCol + parseInt(maxColumns)));
	
	if(previousCol > 1){
		table.setAttribute('previousCol', previousCol - 1);
		table.setAttribute('nextCol', previousCol + maxColumns)
	}else{
		table.setAttribute('previousCol', null);
		table.setAttribute('nextCol', previousCol + maxColumns)
	}
}

function showNextCol(table, maxColumns){
	var nextCol = parseInt(table.getAttribute('nextCol'));
	if(isNaN(nextCol)) return;
	
	var cols = parseInt(table.getAttribute('cols'));
	
	showCol(table, nextCol);
	hideCol(table, (nextCol - parseInt(maxColumns)));
	
	if(nextCol < cols){
		table.setAttribute('nextCol', nextCol + 1);
		table.setAttribute('previousCol', nextCol - maxColumns);
	}else{
		table.setAttribute('previousCol', nextCol - maxColumns);
		table.setAttribute('nextCol', null);
	}
}

function showCol(table, colNumber){
	var rows = table.rows;
	
	for(var i = 0; i < rows.length; i++){
		if(document.all){
			rows[i].cells[colNumber].style.display = '';
		}else{
			rows[i].cells[colNumber].style.display = 'table-cell';
		}
	}
}

function hideCol(table, colNumber){
	var rows = table.rows;
	
	for(var i = 0; i < rows.length; i++){
		rows[i].cells[colNumber].style.display = 'none';
	}
}

initTenYears();
