// JavaScript Document
doAdjust = true;
previousWidth = 0;

// raise doAdjust flag every time the window width changes

$(window).resize(function() {
        var currentWidth = $(window).width();
        if (previousWidth != currentWidth) {
                doAdjust = true;
        }
        previousWidth = currentWidth;
})

$(function() {
        setInterval('maybeAdjust()', 500);
});

// check the doAdjust flag

function maybeAdjust() {
        if (doAdjust) {
                adjustBoxHeights();
                doAdjust = false;
        }
}
function adjustBoxHeights() {
	if($('div#dkhome1_img').height()<$('div#dkhome1_right').height())
		$('div#dkhome1_img').height($('div#dkhome1_right').height());
	else
		$('div#dkhome1_right').height($('div#dkhome1_img').height());
	$('div#dkhome1').height($('div#dkhome1_img').height());
	$('div#dkwellcome').height($('div#dkhome1').height()+$('div#dkblank').height()+$('div#dkhome4').height()+$('div#dkblank').height()+$('div#dkhome2').height()+$('div#dkblank').height()+$('div#dkhome3').height());
	if($('div#dk__content').height()<$('div#detailnews').height())
		$('div#dk__content').height($('div#detailnews').height()+$('div#dknews_cats_title').height()+$('div#title_detailnews').height()+$('div#time_detailnews').height()+$('div#dkblank').height()+$('div#intro_detailnews').height()+$('div#dkblank').height()+$('div#detailnews').height()+$('div#dkblank').height());
	$('div#dkcontent').height($('div#dkwellcome').height()+$('div#dk__content').height());
	$('div#rcenter').height($('div#banner_top').height()+$('div#dkcontent').height()+$('div#banner_footer').height());
	$('div#rright').height($('div#rcenter').height());
	$('div#contentright').height($('div#rcenter').height());
	$('div#right').height($('div#contentright').height()+$('div#topright').height());
	var maxHeight = $('div#left').height();
	if(maxHeight<$('div#right').height()){maxHeight = $('div#right').height()}
	$('div#left').height(maxHeight+$('div#dkbottom').height());
	$('div#right').height(maxHeight);
	$('div#dkmain').height(maxHeight+$('div#dkbottom').height());
	$('div#dinhkimlayout').height(maxHeight+$('div#dkbottom').height());
}