/* Set page and column widths and margins based on browser window size; set a minimum page width. */
function setWidth(col2Width,col3Width,borderW,bodyP,minWidth)
{
	var totalW = totalWidth(col2Width,col3Width,borderW,bodyP,minWidth);
	
	if (document.getElementById) /* W3 standard DOM */
  { 	
		document.getElementById('box-wrap').style.width=totalW + "px";
		document.getElementById('columns-float').style.width=totalW-col3Width + "px";
		document.getElementById('column-one').style.width=totalW-col2Width-col3Width + "px";
 		document.getElementById('column-two').style.marginRight=totalW-col2Width-col3Width + "px";
		if (col3Width > 0) {
			document.getElementById('column-three').style.marginLeft=totalW-col3Width + "px";
		}
  }

  else if (document.all) /* IE4 DOM */
  {
		document.all['box-wrap'].style.width=totalW + "px";
		document.all['columns-float'].style.width=totalW-col3Width + "px";
		document.all['column-one'].style.width=totalW-col1Width-col3Width + "px";
		document.all['column-two'].style.marginRight=totalW-col2Width-col3Width + "px";
		if (col3Width > 0) {
			document.all['column-three'].style.marginLeft=totalW-col3Width + "px";
		}		
  }

  else return false;
}

/* Set page and floating column widths based on browser window size; set a minimum page width. */
function setFloatingColWidth(col2Width,col3Width,borderW,bodyP,minWidth)
{
	var totalW = totalWidth(col2Width,col3Width,borderW,bodyP,minWidth);
	
	if (document.getElementById) /* W3 standard DOM */
  { 	
		document.getElementById('box-wrap').style.width=totalW + "px";
		document.getElementById('columns-float').style.width=totalW-col3Width + "px";
		document.getElementById('column-one').style.width=totalW-col2Width-col3Width + "px";
  }

  else if (document.all) /* IE4 DOM */
  {
		document.all['box-wrap'].style.width=totalW + "px";
		document.all['columns-float'].style.width=totalW-col3Width + "px";
		document.all['column-one'].style.width=totalW-col1Width-col3Width + "px";
  }

  else return false;
}

/* Set fixed column 2 margin based on browser window size. */
function setCol2Margin(col2Width,col3Width,borderW,bodyP,minWidth)
{
	var totalW = totalWidth(col2Width,col3Width,borderW,bodyP,minWidth);
	
	if (document.getElementById) /* W3 standard DOM */
  { 	
		document.getElementById('column-two').style.marginRight=totalW-col2Width-col3Width + "px";
  }

  else if (document.all) /* IE4 DOM */
  {
		document.all['column-two'].style.marginRight=totalW-col2Width-col3Width + "px";
  }

  else return false;
}

/* Set fixed column 3 margin based on browser window size. */
function setCol3Margin(col2Width,col3Width,borderW,bodyP,minWidth)
{
	var totalW = totalWidth(col2Width,col3Width,borderW,bodyP,minWidth);
	
	if (document.getElementById) /* W3 standard DOM */
  { 	
		document.getElementById('column-three').style.marginLeft=totalW-col3Width + "px";
  }

  else if (document.all) /* IE4 DOM */
  {
		document.all['column-three'].style.marginLeft=totalW-col3Width + "px";
  }

  else return false;
}

/* Determine total page width based on browser window size and minimum page width. */
function totalWidth(col2Width,col3Width,borderW,bodyP,minWidth)
{
	var viewportWidth = getViewport();
	var totalW;
	
	if (viewportWidth>=minWidth)
	{
		totalW = viewportWidth-2*(borderW+bodyP);
	}
	
	else
	{
		totalW = minWidth-2*(borderW+bodyP);
	}
	
	return totalW;
}

/* Determine viewport width. Inspired by: Peter-Paul Koch -- http://www.quirksmode.org/viewport/compatibility.html. */
function getViewport()
{
	var viewportWidth;
	
	if (self.innerWidth && document.body.ScrollWidth)
		// Sorts out all IE, then NN4, matches all others.
	{
		viewportWidth = document.body.ScrollWidth;
	}
	else if (document.body)
		// Sorts out NN4, matches all IE.
	{
		viewportWidth = document.body.clientWidth;
	}
	else
		// Default fixed width for NN4 and anything else that didn't match . . . 
	{
		viewportWidth = 748;
	}
	
	return viewportWidth;
}

/* Smoothly rescale images when columns shrink. */
function rescaleImage(col2Width,col3Width,borderW,bodyP,minWidth,imgWidth,heightRatio,totalGutterWidth,totalBoxPadding)
{
	var totalW = totalWidth(col2Width,col3Width,borderW,bodyP,minWidth);
	var col1Width = totalW-col2Width-col3Width;
	
	if (imgWidth >= col1Width-totalGutterWidth-totalBoxPadding)
	{
		if (document.getElementById) /* W3 standard DOM */
		{
			document.getElementById('image1').style.width=col1Width-totalGutterWidth-totalBoxPadding + "px";
			document.getElementById('image1').style.height=(col1Width-totalGutterWidth-totalBoxPadding)*heightRatio + "px";
		}
		
		else if (document.all) /* IE4 DOM */
	  {
			document.all['image1'].style.width=col1Width-totalGutterWidth-totalBoxPadding + "px";
			document.all['image1'].style.height=(col1Width-totalGutterWidth-totalBoxPadding)*heightRatio + "px";
	  }

	  else return false;
	}
	
	else
	{
		if (document.getElementById) /* W3 standard DOM */
		{
			document.getElementById('image1').style.width=imgWidth + "px";
			document.getElementById('image1').style.height=imgWidth*heightRatio + "px";
		}
		
		else if (document.all) /* IE4 DOM */
	  {
			document.all['image1'].style.width=imgWidth + "px";
			document.all['image1'].style.height=imgWidth*heightRatio + "px";
	  }

	  else return false;
	}
}