//This makes both the left and right column have the same height, regarding the MainCanvas section
var LColMinH;
var RColMinH;

$(document).ready(function(){
	init_resize();
});

function init_resize()
{
	LColMinH = $('#leftCol').height();
	RColMinH = $('#Sidebar-inside').height();
	resize_columns(true);
}

function resize_columns(sifr)
{
	var RefCol = $('.inside-text');
	var RefCol2 = $('#MainText');
	var RefH = (parseInt(RefCol.height()) + parseInt(RefCol2.height()));
	var RefColMarPad = [
						RefCol.css("padding-top"),
						RefCol.css("padding-bottom"),
						RefCol.css("margin-top"),
						RefCol.css("margin-bottom"),
						RefCol2.css("padding-top"),
						RefCol2.css("padding-bottom"),
						RefCol2.css("margin-top"),
						RefCol2.css("margin-bottom")];
	for(var i in RefColMarPad)
	{
		var v = parseInt(RefColMarPad[i]);
		if(!isNaN(v))
		{
			RefH += v;
		}
	}	
	var LCol = $('#leftCol');
	var LColH = LCol.height();
	LColH += parseInt(LCol.css("padding-top"), 10) + parseInt(LCol.css("padding-bottom"), 10);
	LColH += parseInt(LCol.css("margin-top"), 10) + parseInt(LCol.css("margin-bottom"), 10);
	
	var RCol = $('#Sidebar-inside');
	var RColH = RCol.height();
	RColH += parseInt(RCol.css("padding-top"), 10) + parseInt(RCol.css("padding-bottom"), 10);
	RColH += parseInt(RCol.css("margin-top"), 10) + parseInt(RCol.css("margin-bottom"), 10);
	
	/* Adjust size of columns to the text div */
	if((RefH < LColH || RefH < RColH) && (RefH != LColH && RefH != RColH))
	{
		if(RefH > LColMinH)
		{
			LCol.height(RefH);	
		}
		else
		{
			LCol.height(LColMinH);	
		}
		if(RefH > RColMinH)
		{
			RCol.height(RefH);	
		}
		else
		{
			RCol.height(RColMinH);	
		}
	}
	else if(RefH != LColH && RefH != RColH)
	{
		LCol.height(RefH);
		RCol.height(RefH);
	}
	
	/* Checks if columns have the same height */
	LColH = LCol.height();
	RColH = RCol.height();
	if(LColH != RColH)
	{
		if(LColH > RColH)
		{
			RCol.height(LColH);	
		}
		else
		{
			LCol.height(RColH);
		}
	}
	
	//alert('L Column Height: ' + LCol.height() + '\nR Column Height: ' + RCol.height() + '\nRef Column Height: ' + RefCol.height());
	
	if(sifr)
	{
		//Run resize_columns again after sifr is updating the h2 & h3 tags, changing the columns heights
		setTimeout('resize_columns()',500);	
	}
}
