<!--
// Core application scripts =============================
// Following scripts don't require any PHP, so they can
// be in an external file to aid caching.
// ======================================================

// Trap errors:
window.onerror = doNothing;
function doNothing(){
	//return true;
}

// Detect browser type:
// Script from http://www.dynamicdrive.com/dynamicindex9/browsersniffer.htm
var exclude = 1;
var agt = navigator.userAgent.toLowerCase ();
var win = 0; var mac = 0; var lin = 1;
if (agt.indexOf ('win') != -1) { win = 1; lin = 0; }
if (agt.indexOf ('mac') != -1) { mac = 1; lin = 0; }
var lnx = 0; if (lin) { lnx = 1; }
var ice = 0;
var ie = 0; var ie4 = 0; var ie5 = 0; var ie6 = 0; var com = 0; var dcm;
var op5 = 0; var op6 = 0; var op7 = 0;
var ns4 = 0; var ns6 = 0; var ns7 = 0; var mz7 = 0; var kde = 0; var saf = 0;
if (typeof navigator.vendor != "undefined" && navigator.vendor == "KDE") {
	var thisKDE = agt;
	var splitKDE = thisKDE.split ("konqueror/");
	var aKDE = splitKDE[1].split ("; ");
	var KDEn = parseFloat (aKDE[0]);
	if (KDEn >= 2.2) {
		kde = 1;
		ns6 = 1;
		exclude = 0;
	}
} else if (agt.indexOf ('webtv') != -1) { exclude=1; }
else if (typeof window.opera != "undefined") {
	exclude = 0;
	if (/opera[\/ ][5]/.test (agt)) { op5 = 1; }
	if (/opera[\/ ][6]/.test (agt)) { op6 = 1; }
	if (/opera[\/ ][7-9]/.test (agt)) { op7 = 1; }
} else if (typeof document.all != "undefined" && !kde) {
	exclude = 0;
	ie = 1;
	if (typeof document.getElementById != "undefined") {
		ie5 = 1;
		if (agt.indexOf ("msie 6") != -1) {
			ie6 = 1;
			dcm = document.compatMode;
			if (dcm != "BackCompat") { com = 1; }
		}
	} else { ie4 = 1; }
} else if (typeof document.getElementById != "undefined") {
	exclude = 0;
	if (agt.indexOf ("netscape/6") != -1 || agt.indexOf ("netscape6") != -1) { ns6 = 1; }
	else if (agt.indexOf ("netscape/7") != -1 || agt.indexOf ("netscape7") != -1) { ns6 = 1; ns7 = 1; }
	else if (agt.indexOf ("gecko") != -1) { ns6 = 1; mz7 = 1; }
	if (agt.indexOf ("safari") != -1 || (typeof document.childNodes != "undefined" && typeof document.all == "undefined" && typeof navigator.taintEnabled == "undefined")) { mz7 = 0; ns6 = 1; saf = 1; }
} else if ((agt.indexOf ('mozilla') != -1) && (parseInt (navigator.appVersion) >= 4)) {
	exclude = 0;
	ns4 = 1;
	if (typeof navigator.mimeTypes['*'] == "undefined") {
		exclude = 1;
		ns4 = 0;
	}
}
if (agt.indexOf ('escape') != -1) { exclude=1; ns4 = 0; }
if (typeof navigator.__ice_version != "undefined") { exclude = 1; ie4 = 0; }

// Other misc global variables;
var timer = Array();

// Change element colour:
function fadecolour (steps, objid, property, iniR, iniG, iniB, finR, finG, finB) {
	if (!property) property = "backgroundColor";
	obj = document.getElementById (objid);
	if (obj.style) {
		if (timer[objid]) clearTimeout (timer[objid]);
		changecolour (objid, property, 0, steps, iniR, iniG, iniB, finR, finG, finB)
	}
}
function changecolour (objid, property, step, steps, iniR, iniG, iniB, finR, finG, finB) {
	if (step <= steps) {
		step ++;
		obj = document.getElementById (objid);
		obj.style[property] = "rgb(" + Math.round(((finR - iniR) * step) / steps + iniR) + "," + Math.round(((finG - iniG) * step) / steps + iniG) + "," + Math.round(((finB - iniB) * step) / steps + iniB) + ")";
		timer[objid] = setTimeout ("changecolour ('"+objid+"', '"+property+"', "+step+", "+steps+", "+iniR+","+iniG+","+iniB+", "+finR+","+finG+","+finB+")", 5);
	}
}

// Find position of element relative to screen:
function elementPosX (obj) {
  objX = obj.offsetLeft
  objParent = obj.offsetParent;
  while (objParent != null) {
    objX += objParent.offsetLeft 
    objParent = objParent.offsetParent;
  }
 return objX;
}
function elementPosY (obj) {
  objY = obj.offsetTop;
  objParent = obj.offsetParent;
  while (objParent != null) {
    objY += objParent.offsetTop;
    objParent = objParent.offsetParent;
  }
 return objY;
}

// Scrolls content smoothly within DIV:
function scrollwindowto (objid, finX, finY) {
	if (timer[objid]) clearTimeout (timer[objid]);
	var launch = new Date ();
	start = launch.valueOf ();
	iniX = document.getElementById(objid).scrollLeft;
	iniY = document.getElementById(objid).scrollTop;
	movecontent (objid, iniX, iniY, finX, finY, start);
}
function movecontent (objid, iniX, iniY, finX, finY, start) {
	var going = new Date ();
	now = going.valueOf ();
	t = (now - start) / 1000;
	with (Math) {
		offsetX = (iniX -finX) * exp ((-4) * t) * sin (1 * t + (PI / 2));
		offsetY = (iniY -finY) * exp ((-4) * t) * sin (1 * t + (PI / 2));
	}
	if (Math.abs (offsetX) < 1) offsetX = 0;
	if (Math.abs (offsetY) < 1) offsetY = 0;
	newposX = finX + offsetX;
	newposY = finY + offsetY;
	document.getElementById (objid).scrollLeft = newposX;
	document.getElementById (objid).scrollTop = newposY;
	if ((Math.floor (Math.abs (offsetX)) > 0 && Math.floor (Math.abs (offsetY)) > 0 && t > 1) || t < 2) timer[objid] = setTimeout("movecontent ('" + objid + "', " + iniX + ", " + iniY + ", " + finX + ", " + finY + ", " + start + ")", 10);
}

// Fade page element(s) out, swaps them, and fades back in:
function fadeelementsinout (stepin, stepout, steps, elementarray, elementid, specialinstruction) {
	// Works on IE5.5+/Netscape/Mozilla/Firefox (Win), Safari/Firefox (Mac). IE5 (Mac) doesn't support opacity. :(
	
	// elementarray = ['action', 'elementid', 'type', 'img src / new txt', 'extension']
	// Possible actions: fad = fade; chg = change; fnc = fade 'n change
	// Possible types: img = image; bkg = backgroundImage; txt = text

	if (stepin < steps) {
		stepin ++;
		for (i = 0; i < elementarray.length; i++) {
			if (elementarray[i][0] == 'fad' || elementarray[i][0] == 'fnc') {
				obj = document.getElementById (elementarray[i][1]);
				if (win && ie5) obj.filters.alpha.opacity = Math.round (100 * (1 - (stepin / steps)));
				else if (saf || ns7) obj.style.opacity = 1 - (stepin / steps);
				else if (ns6) obj.style.MozOpacity = 1 - (stepin / steps);
				else if (kde) obj.style.KHTMLOpacity = 1 - (stepin / steps);
				else stepin = steps
			}
		}
		recall = 'fadeelementsinout ('+stepin+', '+stepout+', '+steps+', [';
		for (i = 0; i < elementarray.length; i++) {
			recall += '[';
			for (j = 0; j < elementarray[i].length; j++) {
				recall += '"'+elementarray[i][j]+'"';
				if (j + 1 < elementarray[i].length) recall += ', ';
			}
			recall += ']';
			if (i + 1 < elementarray.length) recall += ', ';
		}
		recall += '], '+elementid+', "'+specialinstruction+'")';
		timer[elementarray[0][1]] = setTimeout (recall, 60);
	} else if (stepout == 0) {
		for (i = 0; i < elementarray.length; i++) {
			if (elementarray[i][0] == 'chg' || elementarray[i][0] == 'fnc') {
				obj = document.getElementById (elementarray[i][1]);
				if (elementarray[i][2] == "img") obj.src = elementarray[i][3] + elementid + "." + elementarray[i][4];
				if (elementarray[i][2] == "bkg") obj.style.backgroundImage = "URL(" + elementarray[i][3] + elementid + "." + elementarray[i][4] + ")";
				if (elementarray[i][2] == "txt") obj.innerHTML = elementarray[i][3];
			}
		}
		if (specialinstruction) eval (specialinstruction);
		stepout = 1;
		recall = 'fadeelementsinout ('+stepin+', '+stepout+', '+steps+', [';
		for (i = 0; i < elementarray.length; i++) {
			recall += '[';
			for (j = 0; j < elementarray[i].length; j++) {
				recall += '"'+elementarray[i][j]+'"';
				if (j + 1 < elementarray[i].length) recall += ', ';
			}
			recall += ']';
			if (i + 1 < elementarray.length) recall += ', ';
		}
		recall += '], '+elementid+', "'+specialinstruction+'")';
		timer[elementarray[0][1]] = setTimeout (recall, 60);
	} else if (stepout < steps) {
		stepout ++;
		for (i = 0; i < elementarray.length; i++) {
			if (elementarray[i][0] == 'fad' || elementarray[i][0] == 'fnc') {
				obj = document.getElementById (elementarray[i][1]);
				if (win && ie5) obj.filters.alpha.opacity = Math.round (100 * (stepout / steps));
				else if (saf || ns7) obj.style.opacity = stepout / steps;
				else if (ns6) obj.style.MozOpacity = stepout / steps;
				else if (kde) obj.style.KHTMLOpacity = stepout / steps;
				else stepout = steps
			}
		}
		recall = 'fadeelementsinout ('+stepin+', '+stepout+', '+steps+', [';
		for (i = 0; i < elementarray.length; i++) {
			recall += '[';
			for (j = 0; j < elementarray[i].length; j++) {
				recall += '"'+elementarray[i][j]+'"';
				if (j + 1 < elementarray[i].length) recall += ', ';
			}
			recall += ']';
			if (i + 1 < elementarray.length) recall += ', ';
		}
		recall += '], '+elementid+', "'+specialinstruction+'")';
		timer[elementarray[0][1]] = setTimeout (recall, 60);
	}
}
//-->
