// This file is Copyright (C) Daniel James 2007
// All rights reserved.
// Phone: 1800 888 981
// Email: info@netbreeze.com.au

var menu,pages,gallery;
function initmenu() { // Popup menu
	if (document.getElementById) {
		var menu = document.getElementById('menu');
		var toplevel = menu.childNodes[0].childNodes;
		var x;
		for (x = 0; x < toplevel.length; x ++) {
			var curele = toplevel[x].childNodes[0];
			if (curele.tagName == 'A') {
				this.inithover(curele);
			}
		}
		this.currentmenu = false;
		this.timer = false;
	}
}
initmenu.prototype.inithover = function(ele) {
	if (ele.childNodes[0].tagName == 'IMG') {
		ele.img = ele.childNodes[0];
		var hoverimg = ele.img.src;
		hoverimg = hoverimg.substr(0,hoverimg.length - 4);
		hoverimg += '_Over.gif';
		ele.hoverimg = new Image();
		ele.hoverimg.src = hoverimg;
		ele.normalimg = new Image();
		ele.normalimg.src = ele.img.src;
		ele.onmouseover = this.mouseover;
		ele.onmouseout = this.mouseout;
		var li = ele.parentNode;
		var abs = this.abs(li);
		if ((li.childNodes[1] != null) && (li.childNodes[1].tagName == 'UL')) {
			li.childNodes[1].style.left = abs[1] + 'px';
			li.childNodes[1].style.top = (abs[0] + ele.offsetHeight) + 'px';
			li.childNodes[1].style.width = ele.offsetWidth + 'px';
			li.childNodes[1].menuwidth = ele.offsetWidth - 20;
			li.childNodes[1].initted = false;
			li.childNodes[1].isvisible = false;
			li.childNodes[1].menuparent = false;
			li.childNodes[1].menubutton = ele;
		}
	}
}
initmenu.prototype.abs = function(n) {
	var t = 0,l = 0;
	while (n && (n.style.position != 'relative') && (n.id != 'layout')) {
		t += n.offsetTop; l += n.offsetLeft; n = n.offsetParent;
	}
	return [t,l];
}
initmenu.prototype.close = function() {
	menu.closeuntil(false);
}
initmenu.prototype.closesoon = function() {
	this.timer = setTimeout(this.close,1300);
}
initmenu.prototype.norush = function() {
	clearTimeout(this.timer);
}
initmenu.prototype.mouseover = function() {
	if (this.img) {
		this.img.src = this.hoverimg.src;
	}
	var ul = this.parentNode.childNodes[1];
	if ((ul != null) && (ul.tagName == 'UL')) {
		if (!ul.isvisible) {
			ul.isvisible = true;
			if (!ul.initted) {
				ul.initted = true;
				var x,y;
				for (x = 0; x < ul.childNodes.length; x ++) {
					y = ul.childNodes[x].childNodes[0];
					if (y.tagName == 'A') {
						y.onmouseover = menu.mouseover;
						y.onmouseout = menu.mouseout;
						if (navigator.userAgent.indexOf("MSIE 5") != -1) { // oldie
							y.style.width = (ul.menuwidth + 20) + 'px';
						} else {
							y.style.width = ul.menuwidth + 'px';
						}
						y.img = false;
						var li = ul.childNodes[x];
						var abs = menu.abs(li);
						if ((li.childNodes[1] != null) && (li.childNodes[1].tagName == 'UL')) {
							li.childNodes[1].style.width = '120px';
							li.childNodes[1].menuwidth = 100;
							li.childNodes[1].style.marginLeft = (ul.offsetWidth + 1) + 'px';
							li.childNodes[1].style.marginTop = li.offsetTop + 'px';
							li.childNodes[1].initted = false;
							li.childNodes[1].isvisible = false;
							li.childNodes[1].menuparent = ul;
							li.childNodes[1].menubutton = false;
						}
					}
				}
			}
			ul.style.visibility = 'visible';
			menu.closeuntil(ul.menuparent);
			menu.currentmenu = ul;
		}
	} else {
		menu.closeuntil(this.parentNode.parentNode);
	}
	menu.norush();
}
initmenu.prototype.closeuntil = function(ele) {
	while (this.currentmenu && (this.currentmenu != ele)) {
		if (this.currentmenu.menubutton) {
			this.currentmenu.menubutton.img.src = this.currentmenu.menubutton.normalimg.src;
		}
		this.currentmenu.style.visibility = 'hidden';
		this.currentmenu.isvisible = false;
		this.currentmenu = this.currentmenu.menuparent;
	}
}
initmenu.prototype.mouseout = function() {
	var ul = this.parentNode.childNodes[1];
	if (this.img) {
		if ((ul == null) || (ul.tagName != 'UL') || (!ul.isvisible)) {
			this.img.src = this.normalimg.src;
		}
	}
	menu.closesoon();
}
function initpage() { // Dynamic paging
	if (document.getElementById) {
		this.content = document.getElementById('content');
		var hr = this.content.getElementsByTagName('hr')
		if (hr.length) {
			this.pages = new Array();
			var h1 = this.content.getElementsByTagName('h1');
			if (h1[0] != null) {
				this.heading = h1[0].innerHTML;
			} else {
				this.heading = false;
			}
			this.pages = this.content.innerHTML.split(/<HR[ ]*\/?>/i);
			this.current = -1;
			this.showpage(0);
		}
	}
}
initpage.prototype.nav = function() {
	var ret = '<div>&nbsp;</div><div class="pagesnav">';
	if (this.current > 0) {
		ret+= '<span class="left"><a href="javascript:pages.showpage('+(this.current - 1)+')"><span>◄</span> back</a></span>';
	}
	if (this.current < (this.pages.length - 1)) {
		ret+= '<span class="right"><a href="javascript:pages.showpage('+(this.current + 1)+')">next <span>►</span></a></span>';
	}
	ret+='</div>';
	return ret;
}
initpage.prototype.showpage = function(num) {
	if (this.current >= 0) {
		window.document.location.href='#';
	}
	this.current = num;
	if ((num != 0) && this.heading) {
		this.content.innerHTML = '<h1>'+this.heading+' <span>(Cont..)</span></h1><div>&nbsp;</div>'+this.pages[num]+this.nav();
	} else {
		this.content.innerHTML = this.pages[num]+this.nav();
	}
}
function initgallery() {
	if (document.getElementById) {
		var x;
		this.floatie = document.getElementById('floatie');
		this.floater = this.floatie.parentNode;
		this.detail = document.getElementById('detail');
		this.view = document.getElementById('view');
		this.description = document.getElementById('description');
		for (x = 0; x < this.floatie.childNodes.length; x++) {
			if (this.floatie.childNodes[x].childNodes[0].className == 'current') {
				this.current = this.floatie.childNodes[x].childNodes[0];
			}
		}
		if (this.floater.offsetWidth < this.floatie.offsetWidth) {
			this.floatie.className='needspace'
			var obj = this;
			function down() {
				this.className = 'down';
			}
			function up() {
				this.className = '';
			}
			function scroll() {
				if (this.id == 'left') {
					obj.floatie.pos -= 400;
					if (obj.floatie.pos < 0) {
						obj.floatie.pos = 0;
					}
				} else if (this.id == 'right') {
					obj.floatie.pos += 400;
					if (obj.floatie.pos > obj.floatie.max) {
						obj.floatie.pos = obj.floatie.max;
					}
				}
				obj.move();
			}
			this.left = document.createElement('div');
			this.left.id = 'left';
			this.left.innerHTML = '◄';
			this.floater.appendChild(this.left);
			this.right = document.createElement('div');
			this.right.id = 'right';
			this.right.innerHTML = '►';
			this.floater.appendChild(this.right);
			this.left.onmousedown = down;
			this.right.onmousedown = down;
			this.left.onmouseup = up;
			this.right.onmouseup = up;
			this.left.onmouseout = up;
			this.right.onmouseout = up;
			this.floatie.style.left = '0px';
			this.floatie.pos = 0;
			this.floatie.cur = 0;
			this.floatie.max = this.floatie.offsetWidth - this.floater.offsetWidth;
			this.interval = null;
			this.left.onclick = scroll;
			this.right.onclick = scroll;
		}
	}
}
initgallery.prototype.move = function() {
	if (this.floatie.pos != this.floatie.cur) {
		if (this.interval == null) {
			var obj = this;
			this.interval = setInterval(function() {
				var delta = Math.ceil((obj.floatie.pos - obj.floatie.cur) / 2);
				obj.floatie.cur += delta;
				obj.floatie.style.left = (0 - obj.floatie.cur) + 'px';
				if (Math.abs(delta) <= 0) {
					clearInterval(obj.interval);
					obj.interval = null;
				}
			}, 40);
		}
	}
}
initgallery.prototype.show = function(ele,id,desc,w,h,dsc) {
	if (document.getElementById) {
		if (ele.childNodes[0].className != 'current') {
			ele.blur();
			ele.childNodes[0].className = 'current';
			this.current.className = '';
			this.current = ele.childNodes[0];
			this.detail.innerHTML = unescape(desc);
			if (!ele.zoom) {
				ele.zoom = new Image();
				ele.zoom.src = sselfqs+'nb%5Bop%5D=image&nb%5Bsize%5D=2&nb%5Bid%5D='+id;
				ele.zoom.width=w;
				ele.zoom.height=h;
			}
			this.view.replaceChild(ele.zoom,this.view.childNodes[0]);
			if (this.description) {
				this.description.innerHTML = unescape(dsc);
			}
		}
		return false;
	} else {
		return true;
	}
}
if (navigator.userAgent.indexOf('KHTML') != -1) {
	if (document.readyState=='complete') {
		init();
	} else {
		window.onload = init;
	}
} else {
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", init, false);
	} else {
		init();
	}
}
function fixobjects() {
	if (document.getElementById) {
		if (navigator.userAgent.indexOf("MSIE") != -1) { // ieonly
			var obj = document.getElementsByTagName('object');
			var x;
			for (x = 0; x < obj.length; x ++) {
				obj[x].outerHTML = obj[x].outerHTML;
			}
		}
	}
}
fixobjects();
