window.onload = function( ){
	sidebar.adjust_height( );
}

var sidebar = {

	/*
	** Adjusts the Height using the Prototype API (tested and developed with version 1.6)
	**
	** TODO
	**	- If sidebar content is larger than main content; look at adjust_height for code.
	*/
	adjust_height_using_prototype : function( ){
		var column_set = $$( "#content div.container" );
		for( var i = 0; i < column_set.length; i++ ){
			var gradient		= column_set[ i ].select( "div.gradient" );
			gradient[ 0 ].setStyle( { height: "0px" } ); //reset height of sidebar so we do not affect the content height.
			var content_height 	= column_set[ i ].getHeight( );
			gradient[ 0 ].setStyle( { height: content_height + "px" } );
			gradient[ 0 ].firstDescendant( ).setStyle( { height: content_height + "px" } );
		}
	},
	
	/*
	** Adjusts the Height using only the DOM
	*/
	adjust_height : function( ){
		var divisions = document.getElementsByTagName( "div" );
		var sidebar_content;
		var sidebar_container;
		var gradient;
		
		for( var  i = 0; i  < divisions.length; i++ ){
			if( String( divisions[ i ].className ).match( new RegExp( "left_sidebar" ) ) ){	
				sidebar_container = divisions[ i ];
			}
			if( String( divisions[ i  ].className ).match( new RegExp( "sidebar_content"  ) ) ){
				sidebar_content = divisions[ i ];	
			}
			if( String( divisions[ i ].className ).match( new RegExp( "gradient" ) ) ){	
				gradient = divisions[ i ];
				break;
			}
		}

		var main_content = document.getElementById( "content" );
	
		gradient.style.height = "0px";
		if( sidebar_content.offsetHeight > main_content.offsetHeight ){
			gradient.style.height =  ( Number( sidebar_content.offsetHeight ) + 40 )  + "px";
		}
		else{
			gradient.style.height = main_content.offsetHeight + "px";
		}
		sidebar_container.style.height = "100%";
	}

}
