/*
	script by Warwick Adderley: warwick@pretzel.com.au
*/

var lformat = true;

var isNav = (!(!document.layers));
var version = parseFloat(navigator.appVersion);
var isIE = (!(!document.all));
var isMac = (navigator.platform.indexOf("Mac") != -1)
var hasLayers = ((isNav && version >= 4.08) || isIE);
var windowX = null;
var windowY = null;

function checkSize() {
	if (isNav) {
		windowX = window.innerWidth ;
		windowY = window.innerHeight;
		}
	else if (document.body) {
		windowX = document.body.clientWidth;
		windowY = document.body.clientHeight;
		}
	}

checkSize();

//call nsresize in IE4 Mac
if (isMac && isIE)
		window.onresize = function reload() { history.go(0) };

//centre horizontally in frame

function centreX() {
	if (hasLayers) {
		checkSize();
		for (var i = 0; i < arguments.length; i += 2) {
			if (isNav) {
				document.layers[arguments[i]].left = (windowX / 2) + arguments[i + 1];
				}
			else {
				document.all[arguments[i]].style.pixelLeft = (windowX / 2) + arguments[i + 1];
				}
			}
		}
	}

//hug bottom of frame

function hugheight() {
	if (hasLayers) {
		checkSize();
		for (var i = 0; i < arguments.length; i += 2) {
			if (isNav) {
				document.layers[arguments[i]].top = windowY - document.layers[arguments[i]].document.height + arguments[i + 1] + 4;
				}
			else {
				document.all[arguments[i]].style.top = windowY - document.all[arguments[i]].clientHeight + arguments[i + 1];
				}
			}
		}
	}

//hug width of frame

function hugwidth() {
	if (hasLayers) {
		checkSize();
		for (var i = 0; i < arguments.length; i += 2) {
			if (isNav) {
				document.layers[arguments[i]].left = windowX - document.layers[arguments[i]].document.width + arguments[i + 1] + 4;;
				}
			else {
				document.all[arguments[i]].style.pixelLeft = windowX - document.all[arguments[i]].clientWidth + arguments[i + 1];
				}
			}
		}
	}

//fill width of frame

function fillwidth() {
	if (hasLayers) {
		checkSize();
		for (var i = 0; i < arguments.length; i += 2) {
			if (isNav) {
				document.layers[arguments[i]].right = windowX - document.layers[arguments[i]].left + arguments[i + 1] + 4;
				document.layers[arguments[i]].clip.right = windowX - document.layers[arguments[i]].left + arguments[i + 1] + 4;
				}
			else {
				document.all[arguments[i]].style.pixelWidth = windowX - document.all[arguments[i]].style.pixelLeft + arguments[i + 1];
				}
			}
		}
	}

//fill height of frame

function fillheight() {
	if (hasLayers) {
		checkSize();
		for (var i = 0; i < arguments.length;  i += 2) {
			if (isNav) {
				document.layers[arguments[i]].document.height = windowY - document.layers[arguments[i]].top + arguments[i + 1] + 4;
				document.layers[arguments[i]].clip.bottom = windowY - document.layers[arguments[i]].top + arguments[i + 1] + 4;
				}
			else {
				document.all[arguments[i]].style.pixelHeight = windowY - document.all[arguments[i]].style.pixelTop + arguments[i + 1];
				}
			}
		}
	}

//deal with navigator shit resize code
	
	function nsresize() {
		if (isNav && (windowX != window.innerWidth || windowY != window.innerHeight))
			history.go(0);
		}
		
//enable 'nesting' of elements without navigator screwing everything up

var _definedNests = new Array();
var _definedNests_count = 0;

function getPercentagePos(theString, axis) {
	var retVal = null;
	var page = null;
	
	if (axis == 'x') {
		if (isNav) page = window.innerWidth;
		else page = document.body.clientWidth;
		}
	else if (axis == 'y') {
		if (isNav) page = window.innerHeight;
		else page = document.body.clientHeight;
		}
	
	theString = String(theString);
	
	if (theString.indexOf("%") != -1)
		retVal = parseInt(theString) * (page/100);
	else if (theString == "")
		retVal= 0;
	else
		retVal= parseInt(theString);
	
	return retVal;
	}
	
function _position() {
	
	for (var i in this.children) {
		this.theChild = null;
		
		if (isNav) {
			this.theChild = document[this.children[i]];
			this.theChild.top += getPercentagePos(this.yNest, 'y');
			this.theChild.left += getPercentagePos(this.xNest, 'x');
			}
		else {
			this.theChild = this.children[i];
			
			this.theChild[0].style.pixelTop = getPercentagePos(this.yNest, 'y') + this.theChild[1];
			this.theChild[0].style.pixelLeft = getPercentagePos(this.xNest, 'x') + this.theChild[2];
			}
		}
	}

function positionall() {
	if (hasLayers) {
		for (var i in _definedNests) {
			_definedNests[i].position();
			}
		}
	}

function parentdiv() {
	if (hasLayers) {
		this.layer = null;
		this.children = new Array();
		this.theParent = null;
		this.theChild = null;
		
		this.xNest = arguments[0];
		this.yNest = arguments[1];
		
		for (var i = 2; i < arguments.length; i++) {
				this.children[i - 2] = arguments[i];
				}
		
		if (!isNav) {
			for (var i = 0; this.children[i]; i++) {
				var chLeft = null;
				var chTop = null;
				
				this.theChild = document.all[this.children[i]];
				
				chLeft = parseInt(this.theChild.style.left);
				chTop = parseInt(this.theChild.style.top);
				
				this.children[i] = new Array(this.theChild, chTop, chLeft);
				} 
			}
		
		_definedNests[_definedNests_count] = this;
		_definedNests_count ++;
		
		parentdiv.prototype.position = _position;
		parentdiv.prototype.positionall = positionall;
		}
	}
	
