//--------------------------------------------------------------------------
//	Quick browser detect v0.01 Kirk Bentley [kbentley@datalink.net.au]
//--------------------------------------------------------------------------
var saf 	= (navigator.userAgent.indexOf("Safari") >= 0) ? 1 : 0;		//<--	Safari.
var mozMac	= (navigator.userAgent.indexOf("Gecko") >= 0 && navigator.userAgent.indexOf("Mac") >= 0) && !saf ? 1 : 0;
var ieMac	= (navigator.userAgent.indexOf("MSIE") >= 0 && navigator.userAgent.indexOf("Mac") >= 0) ? 1 : 0;
var gecko	= (navigator.userAgent.indexOf('Gecko') >= 0) ? 1 : 0;		//<--	Gecko based browser.
var ie55	= (navigator.userAgent.indexOf("MSIE") >= 0 && navigator.userAgent.indexOf("Win") >= 0) && !document.documentElement.clientHeight ? 1 : 0; //<-- IE 5.5 and below

//--------------------------------------------------------------------------
//	Movement Core v0.01 Kirk Bentley [kbentley@datalink.net.au]
//--------------------------------------------------------------------------
//	Copyright 2004 Datalink.net.au
//--------------------------------------------------------------------------
var moveAr = new Array(); //<-- Create storage for all animated objects.
	

moveFn	= function(el,speed,xPos,yPos,moveIndex,endFn){
	moveIndex	= 0;
	endFn		= null;
	
	typeof(el) == 'string' ? el = document.getElementById(el):'';
	//--> Store currently animated object.
	if (el.moveIndex == null) { el.moveIndex = moveAr.length; }
	moveAr[el.moveIndex]	= el;
	//--> Convert speed scale to decimal.
	speed 			= '0.' + speed;
	//--> Call recal function.
	el.moveTimer ? clearTimeout(el.moveTimer):'';
	window.setTimeout('moveRecalFn(' + el.moveIndex + ',' + speed + ',' + xPos + ',' + yPos + ',' + endFn + ')',0);
}

moveRecalFn	= function(moveIndex,speed,xPos,yPos,endFn){
	el		= moveAr[moveIndex];
	floatDisX	= Math.round(xPos - parseInt(el.offsetLeft));
	(parseInt(el.offsetLeft) < xPos) ? floatVelX = Math.ceil(floatDisX * speed):floatVelX = Math.floor(floatDisX * speed);
	el.style.left	= Math.ceil(parseInt(el.offsetLeft) + floatVelX) + 'px';
	floatDisY	= Math.round(yPos - parseInt(el.offsetTop));
	(parseInt(el.offsetTop) < yPos) ? floatVelY = Math.ceil(floatDisY * speed):floatVelY = Math.floor(floatDisY * speed);
	el.style.top	= Math.ceil(parseInt(el.offsetTop) + floatVelY) + 'px';
	el.moveTimer	= window.setTimeout('moveRecalFn(' + el.moveIndex + ',' + speed + ',' + xPos + ',' + yPos + ',' + endFn + ')',40);
	if(floatDisX == 0 && floatDisY == 0){
		clearTimeout(el.moveTimer);
		el.moveTimer	= null;
		endFn ? endFn():'';
	}
}

//--------------------------------------------------------------------------
//	Movement v0.06 [HACKED]	Kirk Bentley [kbentley@datalink.net.au]
//--------------------------------------------------------------------------
//	Copyright 2004 Datalink.net.au
//--------------------------------------------------------------------------
function moverFn(){
	aniObjAr	= [document.getElementsByName('tnAcctuator')];	//<-- Actuators
	aniInSpeedAr	= [4];		//<--	Slide in speed.
	aniOutSpeedAr	= [4];		//<--	Slide out speed.
	xCurAr		= [1];		//<--	Boolean. Use current x position.
	xDynHeightAr	= [0]		//<--	Boolean. Dynamically calculate x target with parent height.
	xTargetAr	= [0];		//<--	X Destination.
	yCurAr		= [0];		//<--	Boolean. Use current y position.
	yDynHeightAr	= [1]		//<--	Boolean. Dynamically calculate y target with parent height.
	yTargetAr	= [0];		//<--	Y Destination.
	killAr		= [500];	//<--	Delay used to slide out on mouse out.
	isMenuAr	= [1];		//<--	Boolean. When obj is animating will kill all others within group.
	parentDepthAr	= ['next'];	//<--	Node depth of Object you want to move. If 0 assume obj has an ID and use objIdAr. If set to 'next' assume parentNode.nextSibling.
	objIdAr	= [0];		//<--	If 0 use parentDepthAr, else provide object ID.
	eventAr	= ['over'];	//<--	Either set to 'over' (onMouseOver) or 'click' (onClick).

	//-->	Find parent object and store in objAr
	objAr	= [];
	for(i = 0; i < aniObjAr.length; i++){
		objAr[i]	= [];
		for(j = 0; j < aniObjAr[i].length; j++){
			if(parentDepthAr[i] && parentDepthAr[i] != 'next'){
				tempParent	= aniObjAr[i][j];
				for(k = 0; k < parentDepthAr[i]; k++){
					tempParent	= tempParent.parentNode;
				}
			}else if(parentDepthAr[i] && parentDepthAr[i] == 'next'){
				tempParent	= aniObjAr[i][j].parentNode.nextSibling;
				while(tempParent.nodeType != 1){
					tempParent	= tempParent.nextSibling;
				}
			}else if(objIdAr[i]){
				tempParent	= document.getElementById(objIdAr[i]);
			}
			objAr[i][j]	= tempParent.firstChild;
		}
	}
	
	//-->	Find parent x & y target.
	dynTargetAr	= [];
	for(i = 0; i < aniObjAr.length; i++){
		dynTargetAr[i]	= [];
		for(j = 0; j < aniObjAr[i].length; j++){
			dynTargetAr[i][j]	= [];
			if(xDynHeightAr[i]){
				dynTargetAr[i][j][0]	= ((parseInt(objAr[i][j].style.left) + objAr[i][j].offsetWidth));
			}else if(xCurAr[i]){
				dynTargetAr[i][j][0]	= parseInt(objAr[i][j].style.left);
			}else{
				dynTargetAr[i][j][0]	= 0;
			}
			if(yDynHeightAr[i]){
				dynTargetAr[i][j][1] = (((parseInt(objAr[i][j].style.top) + objAr[i][j].offsetHeight)) + aniObjAr[i][j].offsetHeight);
			}else if(yCurAr[i]){
				dynTargetAr[i][j][1] = parseInt(objAr[i][j].style.top);
			}else{
				dynTargetAr[i][j][1] = 0;
			}
		}
	}
	
	killFn	= function(arId,objId){	//<-- Used to return object to start position.
		var killObj	= aniObjAr[arId][objId]
		moveFn(killObj.P,aniOutSpeedAr[arId],killObj.startX,killObj.startY);
	}
	
	//-->	Kills all animated objects in current group [Returns object to start position.].
	killAllFn = function(arId,objId){
		for(var x = 0; x < aniObjAr[arId].length; x++ ){
			var killObj	= aniObjAr[arId][x];
			if(x != objId){
				killObj.P.style.top	= killObj.startY + 'px';
				killObj.P.style.left	= killObj.startX + 'px';
				clearTimeout(killObj.P.killTimer)
				clearTimeout(killObj.P.moveTimer);
			}
		}
	}

	for(var i = 0; i < aniObjAr.length; i++){
		for(x = 0; x < aniObjAr[i].length; x++){
			var aniObj		= aniObjAr[i][x];		//<--	Child
			aniObj.arId		= i;				//<--	Key in aniObjAr.
			aniObj.objId		= x;				//<--	Key in aniObjAr[i]
			aniObj.P		= objAr[i][x];		//<--	Reference to parent object.
			aniObj.P.C		= aniObj;			//<--	Reference to child.
			aniObj.P.Kill		= killAr[i] ? 1:0;		//<--	Kill animation. Bollean.
			aniObj.P.isMenu	= isMenuAr[i];		//<--	Is object to behave like a menu or not.
			aniObj.startX		= aniObj.P.offsetLeft;	//<--	Start X position.
			aniObj.startY		= aniObj.P.offsetTop;	//<--	Start Y position.
			aniObj.endX		= dynTargetAr[i][x][0] ? dynTargetAr[i][x][0]:xTargetAr[aniObj.arId];	//<--	Start X position.
			aniObj.endY		= dynTargetAr[i][x][1] ? dynTargetAr[i][x][1]:yTargetAr[aniObj.arId];	//<--	Start X position.
			
			switch(eventAr[i]){
				case 'over':
					aniObj.onmouseover	= function(){	//<--	Move object.
						this.P.isMenu ? killAllFn(this.arId,this.objId):'';
						moveFn(this.P,aniInSpeedAr[this.arId],this.endX,this.endY);
						this.P.Kill ? clearTimeout(this.P.killTimer):'';
					}
					break;
				case 'click':					
					aniObj.onclick	= function(){	//<--	Move object.
						this.P.isMenu ? killAllFn(this.arId,this.objId):'';
						moveFn(this.P,aniInSpeedAr[this.arId],this.endX,this.endY);
						this.P.Kill ? clearTimeout(this.P.killTimer):'';
					}
					break;
			}
			
			aniObj.onmouseout	= function(){	//<--	Return object to start position.
				this.P.Kill ? this.P.killTimer = window.setTimeout('killFn(' + this.arId + ',' + this.objId + ')',killAr[this.arId]):'';
			}
			
			aniObj.P.onmouseover	= function(){	//<--	Keep object alive.
				this.Kill ? clearTimeout(this.killTimer):'';
				this.isMenu ? killAllFn(this.C.arId,this.C.objId):'';
			}
			
			aniObj.P.onmouseout	= function(){	//<--	Return object to start position.
				this.Kill ? this.killTimer = window.setTimeout('killFn(' + this.C.arId + ',' + this.C.objId + ')',killAr[this.C.arId]):'';
			}
		}
	}
}

//--------------------------------------------------------------------------
//	initTopNavFn v0.01	Kirk Bentley [kbentley@datalink.net.au]
//--------------------------------------------------------------------------
function initTopNavFn(){
	tn	= document.getElementById('topNav');
	spanAr	= tn.getElementsByTagName('SPAN');
	//-->	Correct Mac IE issue with floated elements requiring width.
	if(ieMac){
		for(x = 0; x < spanAr.length; x++){
			spanAr[x].firstChild.style.display		= 'inline';
			spanAr[x].parentNode.style.width = spanAr[x].firstChild.offsetWidth + 'px';
			spanAr[x].firstChild.style.display		= 'block';
		}
	}	
	//-->	Move menu items out of view.
	ulAr	= tn.getElementsByTagName('UL');	
	for(x = 0; x < ulAr.length; x++){
		ulAr[x].style.top	= (0 - (ulAr[x].offsetHeight)) + 'px';
	}
}

//--------------------------------------------------------------------------
//	newsTicker v0.01	Kirk Bentley [kbentley@datalink.net.au]
//--------------------------------------------------------------------------
//	Requires Move core functions...
//	scrollAr is defined in parent document.
//--------------------------------------------------------------------------
function initNewsTickerFn(){
	var c	= document.getElementById('newsTickerCon');
	var cl	= document.getElementById('clip');
	c.innerHTML	= scrollAr[1];
	//c.style.background	= '#FFF';
	
	var direction	= 0;
	var killSpeed	= 4000;
	var count = 0;
	var ticker;
	
	c.onmouseover	= function(){
		this.parentNode.style.cursor	= 'default';
		ticker ? window.clearTimeout(ticker):'';
		initTicker ? window.clearTimeout(initTicker):'';
	}
	
	c.onmouseout	= function(){
		this.parentNode.style.cursor	= 'default';
		ticker = window.setTimeout('moveTickerRecallFn("newsTickerCon")',0);
	}
	
	moveTickerFn = function(obj){
		t	= document.getElementById(obj);
		if(!direction){
			direction	= 1;
			killSpeed	= 1000;
			moveFn(obj,6,310,0);
		}else{
			count == scrollAr.length ? count = 0:'';
			t.innerHTML	= scrollAr[count];
			direction	= 0;
			killSpeed	= 4000;
			moveFn(obj,6,0,0);
			count++;
		}
	}
	
	moveTickerRecallFn = function(obj){
		moveTickerFn(obj);
		ticker = window.setTimeout('moveTickerRecallFn("' + obj + '")',killSpeed);
		
	}
	var initTicker	= window.setTimeout('moveTickerRecallFn("newsTickerCon")',killSpeed);
}

//--------------------------------------------------------------------------
//	CSS Color Switch init v0.01	Kirk Bentley [kbentley@datalink.net.au]
//--------------------------------------------------------------------------
function initColBoxFn(){
	var cBoxAr	= document.getElementsByName('cBox');
	
	for(x = 0; x < cBoxAr.length; x++){
		var cBox	= cBoxAr[x];
		cBox.col	= cBox.className;
		
		cBox.onclick	= function(){
			changeCol(this.col);
			return false;
		}
	}
}

// -------------------------------------------------------------------------
// StyleSwitcher functions
// -------------------------------------------------------------------------

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  //var title = cookie ? cookie : getPreferredStyleSheet();
  var title = cookie ? cookie : 'green';
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

function changeCol(color) {
	setActiveStyleSheet(color);
	location.reload();
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// -------------------------------------------------------------------------
//	Base functions
// -------------------------------------------------------------------------
function printIt(){
	if (window.print) {
		window.print() ;
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box  WebBrowser1.outerHTML = "";
	}
}

function DOMCall(name) {
	if (document.layers) 
		return document.layers[name];
	else if (document.all)
		return document.all[name];
	else if (document.getElementById)
		return document.getElementById(name);
}

function showPic (whichpic) {
	DOMCall('placeholder').src = whichpic.href;
	if (whichpic.title) {
		DOMCall('imageCaption').innerHTML = whichpic.title;
		DOMCall('imageCaption').className = "";
	} else {
		DOMCall('imageCaption').className = "hidden";
	}
 	return false;
}

function toolTipFn(){
	//-->	User defined variables.
	var mousePad	= 10;		//<--	Offset too keep toolTip clear of mouse. NOTE: Do not set below 10.
	var tipMaxStr	= 70;		//<--	String count (Limit how many characters before toolTip width is enforced.
	var tipMaxWidth	= 200;		//<--	toolTip width to be applied if 'tipMaxStr' is exceeded.
	
	//-->	Quick Browser Detection.
	var saf = (navigator.userAgent.indexOf("Safari") >= 0) ? 1 : 0;		//<--	Safari.
	var ie6	= document.documentElement.clientHeight && document.all ? 1:0;	//<--	Internet Explorer 6.
	var moz	= !saf && document.getElementById && !document.all ? 1:0;	//<--	Mozilla.

	//-->	Constant variables. DO NOT EDIT.	
	var linkAr	= document.getElementsByTagName('A');			//<-- Collection of all 'A' tags on current page.
	var T		= document.getElementById('toolTip');			//<-- Reference to div to be used as toolTip.
	var cWidth	= ie6 || moz ? document.documentElement.clientWidth:document.body.offsetWidth;		 //<-- Quick test for IE 5.5 and below. IE6:IE5.5.
	var cHeight	= ie6 || moz ? document.documentElement.clientHeight:document.body.offsetHeight;	 //<-- Quick test for IE 5.5 and below. IE6:IE5.5.
	
	var mX,mY,xDiff,yDiff;							//<--	Mouse X & Y positions.
	var D		= document.getElementById('debug');
	
	//-->	Traces mouse position and stores in mX & mY.
	mousePos = function(e){
		
		mX	= moz || saf ? e.clientX:event.clientX;
		mY	= moz || saf ? e.clientY:event.clientY;
		
		if(ie6 || saf || moz){						//<-- Create toolTip offSet for IE6, Mozilla and Safari.
			xDiff	= document.documentElement.scrollLeft;
			yDiff	= document.documentElement.scrollTop;
		}else if(!ie6){							//<-- Create toolTip offSet for IE 5.5 <.
			xDiff	= document.body.scrollLeft;
			yDiff	= document.body.scrollTop;
		}
		
		if(T){
			if(mY < (cHeight / 2)){
				T.style.top	= ((mY + yDiff)  + mousePad) + 'px';
			}else{
				T.style.top	= ((mY + yDiff) - (T.offsetHeight + mousePad)) + 'px';
			}
			
			if(mX < (cWidth / 2)){
				T.style.left	= ((mX + xDiff) + mousePad) + 'px';
			}else{
				T.style.left	= ((mX + xDiff) - T.offsetWidth) + 'px';
			}
		}
	}
	
	document.onmousemove	= mousePos;					//<--	Registers event.
	
	//-->	Loop through all links.	
	for(x = 0; x < linkAr.length; x++){
		A	= linkAr[x];
		
		if(A.title && (A.name != 'noTip' && A.name != 'tnAcctuator')){				//<-- If 'A' has title proceed and no name of 'noTip'.
			A.innerTITLE	= A.title;				//<-- Store 'A' title.
			A.title	= '';						//<-- Strip current title to obstruct standard browser behaviour.
			A.onover	= A.onmouseover;
			A.onout	= A.onmouseout;
			
			A.onmouseover = function(){
				T		= document.getElementById('toolTip');
				T.innerHTML	= this.innerTITLE;		//<--	Convert 'A' title to toolTip contents.

				if(this.innerTITLE.length > tipMaxStr){		//<-- If 'tipMaxStr' is exceeded enforce 'tipMaxWidth'.
					T.style.width = tipMaxWidth + 'px';
				}else{
					T.style.width	= 'auto';
				}
				
				T.style.display	= 'block';			//<-- Make toolTip visible.
				this.onover ? this.onover():'';
			}
			
			A.onmouseout = function(){				//<-- Reset and hide toolTip.
				T.innerHTML	= '';
				T.style.width	= 'auto';
				T.style.display	= 'none';
				T.style.top	= -1000 + 'px';
				T.style.left	= 0;
				T	= null;
				this.onout ? this.onout():'';
			}
		}
	}
}

var initPop = 0;

//--------------------------------------------------------------------------
//	initTopNavFn v0.01	Kirk Bentley [kbentley@datalink.net.au]
//--------------------------------------------------------------------------
window.onload = function(){
	initTopNavFn();
	!ieMac ? moverFn():'';
	initNewsTickerFn();
	initColBoxFn()
	initPop ? init():'';	//<-- Init popcalendar if included.
	!mozMac && !ieMac && contentClass != 'FLASHPAGE' ? toolTipFn():'';
}