// Default scripts - to be displayed on every page

var doEqualizeColumnHeights = true;

// get the max number from any number of arguments
function getMax() {

	var args = getMax.arguments;
	var maxNumber = 0;
	
	for (i=0; i<args.length; i++) {
		if (args[i] > maxNumber) {
			maxNumber = args[i];
		}
	}

	return maxNumber;

}

/* this function ensures that column heights will not be equalized, in order to allow for proper printing */
function supressColumnEqualization() {
	doEqualizeColumnHeights = false;
}

function equalizeColumnHeights() {
	
	var defaultHeight = 537;
	var maxHeight = parseInt(document.getElementById("centreArea").offsetHeight);
	var borderHeight = 11; // used for calculating changes to the main container
	
	if (doEqualizeColumnHeights) {
			
		/* 
		This would be a good idea under other circumstances, but since only the middle area will stretch, we can confidently use that instead of determining a max */
		
		var maxHeight = parseInt(getMax(document.getElementById("leftArea").offsetHeight, document.getElementById("centreArea").offsetHeight, document.getElementById("rightArea").offsetHeight) + 175);	
		
		maxHeight = maxHeight + 50; // add an extra 50 to make this work right. Note - I have no idea why this is necessary. This code needs to be reexamined.
		maxHeightString = maxHeight + "px";
		
		if (maxHeight > defaultHeight) {
		
			// extend the three columns
			document.getElementById("leftArea").style.height = maxHeightString;
			document.getElementById("centreArea").style.height = maxHeightString;
			document.getElementById("rightArea").style.height = maxHeightString;
			// document.getElementById("calloutArea").style.height = maxHeightString;
			
			// get the different between the default height and the new height
			heightDiff = maxHeight - defaultHeight;
	
			// extend the main container
			newMainContainerHeight = document.getElementById("mainContainer").offsetHeight + heightDiff - borderHeight;
			newMainContainerHeightString = newMainContainerHeight + "px";		
			document.getElementById("mainContainer").style.height = newMainContainerHeightString;
	
			document.getElementById("mainContainer").style.overflow = "hidden";
	
		}
	
	}
		
}

function restoreColumnHeights() {
	
	// alert('restoring height');
	
	restoredHeight = 537;
	restoredHeightString = restoredHeight + "px";
	
	document.getElementById("leftArea").style.height = restoredHeightString;
	document.getElementById("centreArea").style.height = restoredHeightString;
	document.getElementById("rightArea").style.height = restoredHeightString;	
	
	document.getElementById("mainContainer").style.height = "801px";
	document.getElementById("mainContainer").style.overflow = "visible";
	
}

function newSizedNamedWindow(url, windowName, width, height) {

		newWindow = window.open(url, windowName, 'menubar=no,status=no,scrollbars=auto,resizeable=no,width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,top=0,left=0,screenX=0,screenY=0'); 
			newWindow.focus();
			
}

function newSizedScrollingWindow(url, windowName, width, height) {

		newWindow = window.open(url, windowName, 'menubar=no,status=no,scrollbars=yes,resizeable=no,width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,top=0,left=0,screenX=0,screenY=0'); 
			newWindow.focus();
			
}

function imageSwap(theImage, newSRC) {
	theImage.src = newSRC;
}


function simplePreload() { 

  var args = simplePreload.arguments;

  document.imageArray = new Array(args.length);

  for(var i=0; i<args.length; i++) {

    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];

  }

}
