/* 
 * custom.js
 */

/*jslint undef: true, browser: true */
/*global jQuery, $ */

$( function() {

	var iTextBackgroundHeight = 380;

	// Content size fix to match text background image size
	if (typeof iTextBackgroundHeight != "undefined") {
		if ( $("#TextContent").height() < iTextBackgroundHeight ) {
			$("#TextContent").height(iTextBackgroundHeight);
		}
	}


	// Sidebar and Content height synchronization
	var iSidebarHolderHeight = $(".SidebarHolder").height();
	var iSidebarHolderOuterHeight = $(".SidebarHolder").outerHeight(true) - $(".SidebarHolder").height();
	var iMainBlockHeight = $("#yui-main").height();
	var iBottomLinkFullHeight = $(".Column0 .BottomLink").outerHeight(true);
	var iSidebarHeight = iSidebarHolderHeight + iSidebarHolderOuterHeight + iBottomLinkFullHeight;
	var iTextContentHeight = $("#TextContent").height();
	
	/*
	// Debug
	alert(
		"Main block height: " + iMainBlockHeight + "\n" +
		"Sidebar holder height: " + iSidebarHolderHeight + "\n" +
		"Sidebar holder outer height: " + iSidebarHolderOuterHeight + "\n" +
		"Bottom link full height: " + iBottomLinkFullHeight + "\n" +
		"Sidebar sum: " + iSidebarHeight
		);
	*/

	if (iSidebarHeight < iMainBlockHeight) {
		// Set Sidebar to be as high as the Content
		$(".SidebarHolder").height(iSidebarHolderHeight + iMainBlockHeight - iSidebarHeight);
	}
	else if (iSidebarHeight > iMainBlockHeight) {
		// Set Content to be as hight as Sidebar
		$("#TextContent").height(iTextContentHeight + (iSidebarHeight - iMainBlockHeight) + 1);
	}
	
	
});

