function changeBG(newElement,newImage){
	var theImage = newImage;
	var theElement = document.getElementById(newElement);
	theElement.style.backgroundImage="url(" + theImage + ")";
}

function addedCheckHeights() {
	setTimeout('adjustHeights( "subcontainer1" )',0);
	setTimeout('adjustHeights( "subcontainer2" )',0);
	setTimeout('adjustHeights( "container" )',0);
	//adjustHeights( "subcontainer2" );
	//adjustHeights( "container" );
}

function setHeights()
{
	$(window).load(function()
	{
		var heights = new Array();
		sum_heights = 0;
		var columns = $("#column_1");
		
		jQuery.each($("#column_1").children("div"), function(){
			heights.push($(this).height());
		});
		
		i = 0;
		jQuery.each($("#column_2").children("div"), function(){
			if(heights[i] <= $(this).height())
			{
				heights[i] = $(this).height();
			}
			i = i + 1;
		});
	
		i = 0;
		jQuery.each($("#column_1").children("div"), function(){
			$(this).height(heights[i]);
			if(heights[i] == 0)
			{
				this.style.display = 'none';
				$(this).remove();
			}
			
			i = i + 1;
		});
		
		i = 0;
		jQuery.each($("#column_2").children("div"), function(){
			$(this).height(heights[i]);
			if(heights[i] == 0)
			{
				this.style.display = 'none';
				$(this).remove();
			}
			
			i = i + 1;
		});
		
		var browser, version;
		
		jQuery.each(jQuery.browser, function(i, val) {
			if(val == true)
			{
				browser = i;
			}
			else if(i == "version")
			{
				version = val;
			}
		});
		
		jQuery.each(heights, function(){
			if(browser == "msie")
			{
				sum_heights += this
			}
			else if(this > 0)
			{
				sum_heights += this + 10;
			}
		});
		
		var column_3;
		jQuery.each($("#column_3").children("div"), function(){
			column_3 = this;
		});
		
		if(browser != "msie")
		{
			if($("#column_1").height() - 19 >= $(column_3).height())
			{
				$(column_3).height($("#column_1").height() - 19);
			}
			else
			{
				diff = ($(column_3).height() - $("#column_1").height() + 19)/ $("#column_1").children("div").length;
				
				jQuery.each($("#column_1").children("div"), function(){
					$(this).height($(this).height() + diff);
				});
				
				jQuery.each($("#column_2").children("div"), function(){
					$(this).height($(this).height() + diff);
				});
			}
		}
		else
		{
			if($("#column_1").height() - 19 >= $(column_3).height())
			{
				$(column_3).height($("#column_1").height() - 19);
			}
			else
			{
				diff = ($(column_3).height() - $("#column_1").height() + 19)/ $("#column_1").children("div").length;
				
				jQuery.each($("#column_1").children("div"), function(){
					$(this).height($(this).height() + diff);
				});
				
				jQuery.each($("#column_2").children("div"), function(){
					$(this).height($(this).height() + diff);
				});
			}
		}
	});
}
setHeights();



function resetHeights( classId )
{
	var divs,contDivs,maxHeight,divHeight,d;
	// get all <div> elements in the document
	divs=document.getElementsByTagName('div');
	contDivs=[];
	// initialize maximum height value
	maxHeight=0;
	// iterate over all <div> elements in the document
	for(var i=0;i<divs.length;i++)
	{
		if( classId == divs[i].className)
		{
			divs[i].style.height=0+"px"
		}
	}
}

function adjustHeights( classId ) {
	var divs,contDivs,maxHeight,divHeight,d;
	// get all <div> elements in the document
	divs=document.getElementsByTagName('div');
	contDivs=[];
	// initialize maximum height value
	maxHeight=0;
	// iterate over all <div> elements in the document
	for(var i=0;i<divs.length;i++){
  	// make collection with <div> elements with class attribute 'container'
    if( classId == divs[i].className){
			d=divs[i];
			contDivs[contDivs.length]=d;
			// determine height for <div> element
			if(d.offsetHeight){
				divHeight=d.offsetHeight;
			} 
			else if(d.style.pixelHeight){
					divHeight=d.style.pixelHeight;
				}
			// calculate maximum height
			maxHeight=Math.max(maxHeight,divHeight);
		}
	}
	
	for(var i=0;i<contDivs.length;i++){
		if( classId == contDivs[i].className ) {
			contDivs[i].style.height=(maxHeight-10)+"px";
		}
	}
	// assign maximum height value to all of container <div> elements
	for(var i=0;i<contDivs.length;i++){
		if( classId == "container" ) {
			if( contDivs[i].id == "column_3" ) { contDivs[i].style.height=(maxHeight-15)+"px"; }
			else if ( contDivs[i].id == "column_4" ) { contDivs[i].style.height=(maxHeight-30)+"px"; }
			else { contDivs[i].style.height=(maxHeight-8)+"px"; }
		}
		//contDivs[i].style.maxHeight=maxHeight;
		//contDivs[i].style.minHeight=maxHeight;
	}
} 
