// JavaScript Document

var intId;
var savedBarH = null;
var savedAndBarH = null;
var navPadding = 20; //Copy from CSS .sectionPanel paddings
var andinatelPadding = 18; //Copy from CSS .andinatelBarContent paddings

function resizeNavigation(){
	var navbar = document.getElementById("mainNavigation");
	var container = document.getElementById("mainIntContent");
	
	if(savedBarH == null){
		savedBarH = navbar.clientHeight;
	}
	
	var newHeight = container.clientHeight - 3;
	
	/* If content is larger than side menu */
	if(newHeight > savedBarH) {
		newHeight = newHeight - navPadding;
		
		if (newHeight % 2 != 0){
			newHeight++;
		}
	}
	else {
		newHeight = savedBarH - navPadding;
	}
	
	navbar.style.height = newHeight + "px";
	
	var andinatelBar = document.getElementById("andinatelBarContent");
	
	/* If there is an Andinatel bar */
	if(andinatelBar != null){
		if(savedAndBarH == null){
			savedAndBarH = andinatelBar.clientHeight;
		}
		
		var headerH = document.getElementById("headerBar").clientHeight;
		newHeight = newHeight - headerH - 2;
		
		if (newHeight % 2 != 0){
			newHeight++;
		}
		
		/* If Andinatel bar larger than side menu */
		if(newHeight < savedAndBarH) {
			/* re-adjust the side menu height */
			newHeight = savedAndBarH - navPadding;	
			
			var tempHeight = newHeight + headerH + 2;
			
			if (tempHeight % 2 != 0){
				tempHeight++;
			}
			
			navbar.style.height = tempHeight + "px";
		}

		andinatelBar.style.height = newHeight + "px";
		
		document.getElementById("bar_bl").style.bottom = null;
		document.getElementById("bar_br").style.bottom = null;
		
		document.getElementById("bar_bl").style.bottom = "-1px";
		document.getElementById("bar_br").style.bottom = "-1px";
	}
	
	document.getElementById("nav_bl").style.bottom = null;
	document.getElementById("nav_br").style.bottom = null;
	
	document.getElementById("nav_bl").style.bottom = "-1px";
	document.getElementById("nav_br").style.bottom = "-1px";
}

function resizeHome(){
	var maxHeight = 0;
	var panelPadding = 14; //Copy from CSS .sectionPanel paddings
	var panel;
	
	for(var i = 0; i < 3; i++){
		panel = document.getElementById("sectionPanel" + (i + 1));
		if(panel.clientHeight > maxHeight){
			maxHeight = panel.clientHeight;
		}
	}
	
	if(maxHeight % 2 != 0) maxHeight++;
	
	for(var i = 0; i < 3; i++){
		panel = document.getElementById("sectionPanel" + (i + 1));
		panel.style.height = (maxHeight - panelPadding) + "px";
		document.getElementById("p" + (i + 1) + "_bl").style.bottom = "-1";
		document.getElementById("p" + (i + 1) + "_br").style.bottom = "-1";
	}
	
	var contentHeight = document.getElementById("mainHomeContent").clientHeight;
	var menuHeight = document.getElementById("mainNavigation").clientHeight;
	
	if(contentHeight > menuHeight){
		contentHeight = contentHeight - navPadding - 2;
		
		if(contentHeight % 2 != 0) contentHeight++;
	
		document.getElementById("mainNavigation").style.height = contentHeight + "px";
		document.getElementById("nav_br").style.bottom = "-1px";
		document.getElementById("nav_bl").style.bottom = "-1px";
	}
}