var fudgeFactor = 28;

MakeLayout("wrap",800-fudgeFactor,1024-fudgeFactor,1024-fudgeFactor);

function MakeLayout(id,minr,maxw,maxr) {
	if(document.getElementById) {
		SetWidth(id,minr,maxw,maxr);
		window.onresize = function() { 
			SetWidth(id,minr,maxw,maxr); 
		}
	}
}

function SetWidth(id,a,b,c) {
	var w=getBrowserWidth();
	if(w==0) return;
	var el=document.getElementById(id);
	el.style.margin="0 auto";
	var d=el.style;
	if(w<=a) {
		d.width=a+"px";
		d.height="100%";
	}
	else if(w>=c) {
		d.width=b+"px";
		d.height="100%";
	}
	else {
		var m=(b-a)/(c-a);
		d.width=parseInt(m*w+a*(1-m))+"px";
		d.height="100%";
	}
}

function getBrowserWidth() {
	if (window.innerWidth) { // ff
		//return window.innerWidth;
		return document.body.clientWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth!=0) {
		return document.documentElement.clientWidth;
	}
	else if (document.body) { // ie
		return document.body.clientWidth;
	}
	return 0;
}
