window.onresize = SetPageWidth;
window.onload = SetPageWidth;

function SetPageWidth(){
	document.getElementById('pagesizer').style.width = ""; //reset so that page can shrink
	var PageWidthElement = document.getElementById('pagesizer_getwidth');
	var PageWidth = PageWidthElement .offsetWidth;
	if(!PageWidth) {PageWidth = getElementWidth(PageWidthElement ); }
	//alert(PageWidth);
	//the boxes are 240 in width
	//the right image is 256 in width
	//so, let's see how many we can fit in one row
	var BoxWidth = 285; //about this in width plus margin
	var ImageWidth = 256;
	var WidthFilled = ImageWidth + BoxWidth; //start with one box and the image
	var MaxBoxes = 1;
	
	while(WidthFilled <= PageWidth){
		MaxBoxes += 1;
		WidthFilled += BoxWidth;
	}
	MaxBoxes -=1;
	WidthFilled -= BoxWidth;
	
	//alert(MaxBoxes + " boxes will fit, taking up " + WidthFilled + " of an available " + PageWidth);
	document.getElementById('pagesizer').style.width = WidthFilled + 'px';
}

