// JavaScript Document

// Once the web page has been rendered then execute this function
window.onload = function( ){
	setNavbarHeight( );
};

// Draw vertical lines in navigation bar

// To add height to the navigation bar so that the left and right veritacal line
// go all the way down to the top of the footer when the context part of the page
// is longer then the navigation bar.
function setNavbarHeight( ){
	// Get the height of the navigation bar and context of the page
	var styles = document.styleSheets[0];
	var main2Context = document.getElementById('main2');
	var m2Height = main2Context.offsetHeight;
	var navbar = document.getElementById('sidebar-nav');
	var navbarHeight = navbar.offsetHeight;
	// If context part of the page is longer in height then make the navigation 
	// bar just as long.
	if( m2Height > navbarHeight) {
		// Call the function to do this.
		addStyleRule( styles, "#sidebar-nav", "height: " + m2Height + "px", 0);
	};
};

// Set the height of the navigation bar
function addStyleRule( styleSheet, selector, properties, index ) {
	// Because Internet Explorer does this different then other browsers first
	// check if this is Intenet Explorer browser
	if( typeof styleSheet.addRule != "undefined" ) {
		// This is an Internet Explorer Browser. Adjust the CSS for the new height
		styleSheet.addRule( selector, properties, index );	
	}
	else if( typeof styleSheet.insertRule != "undefined" ) {
		// It is another browser such as FireFox. Adjust the CSS for the new height
		if( typeof index == "undefined" ) { 
			index = styleSheet.cssRules.length;
		}
		styleSheet.insertRule( selector + " {" + properties + "}", index );
	}
	return true;
};
