var T = new Array();
window.onload = function () {  startMenu("mainMenu"); startSubMenu("sectionMenu"); startMenu("language"); startMenu("service"); startMenu("noticeboard"); startGallery("gallery", "galleryPix")  };


//--------------------------------------------------------------##


function reset() { // reset screen widgets
	for (var t in T) {
		clearTimeout(t);
	}
}

function browserTest () {
	return document.getElementById || document.all;
}

function init () {
	startSideStory();
}

function displayBlockz(o, tag) {
	var p = o.parentNode;
	var navList = p.getElementsByTagName(tag);
	if (navList) {
		var L;
		var S = o.id.slice(0,-1);
		for (var i=0; i<navList.length; i++) {
			L=  navList[i].id.slice(0,-1);
			if (L != S) shideDisplay(L, 'none');
		}
		shideDisplay(S, 'block');
	}
}

function shideDisplay(elemID, state) { // create / destroy display blocks
	var LmNt = document.getElementById?document.getElementById(elemID):document.all?document.all(elemID):"";
	if ( LmNt ) {
		if ( state == 'toggle') {
			 if (LmNt.style.display != 'block') {LmNt.style.display = 'block'}
			 else LmNt.style.display = 'none';
		} else
			if (LmNt.style.display != state) LmNt.style.display = state ;
		}
}

function startMastHead () {
	var node = document.getElementById?document.getElementById("mastLeft"):document.all?document.all("mastLeft"):"";
	if (node) {
		node.onmouseover=function() { window.clearTimeout(T[this.id]);}
		node.onmouseout=function() { ssb(this, 0, -2) }
		ssb(node, 0, -2);
	}
}

function startMenu (id) {
	this.navRoot = document.getElementById?document.getElementById(id):document.all?document.all(id):"";
	this.oldStyle = "";
	if (navRoot) {
		var navList = navRoot.getElementsByTagName("LI");
		var node;
		for (var i=0; i<navList.length; i++) {
			node = navList[i];
			node.onmouseover=function() { this.className="over"}
			node.onmouseout=function() { this.className="" }
			node.onclick=function() { getLocation( this.getElementsByTagName('A')[0].getAttribute('href') ) }
		}
	}
}
startMenu.prototype.over = function() { this.oldStyle=this.className="over"}
startMenu.prototype.out = function() { this.className=this.oldStyle}
startMenu.prototype.click = function() { getLocation( this.getElementsByTagName('A')[0].getAttribute('href') ) }

function startSubMenu (id) {
	var navRoot = document.getElementById?document.getElementById(id):document.all?document.all(id):"";
	if (navRoot) {
		var navList = navRoot.getElementsByTagName("LI");
		var node;
		for (var i=0; i< navList.length; i++) {
			node = navList[i];
			node.onmouseover=function() { this.className ="over" }
			node.onmouseout=function() { this.className=""}
			if (node.id.substr(-1,1)=="_") {
				node.onclick = function() { displayBlockz( this, "LI"); return false }
				}
			shideDisplay(node.id.slice(0,-1), "none");
		}
		shideDisplay(navList[0].id.slice(0,-1), "block");
	}
}

function startGallery (gid, pid) {
	var thumbRoot = document.getElementById?document.getElementById(gid):document.all?document.all(gid):"";
	var largePix = document.getElementById?document.getElementById(pid):document.all?document.all(pid):"";
	if (thumbRoot) {
		var pix = thumbRoot.getElementsByTagName("IMG");
		var thumbList = thumbRoot.getElementsByTagName("LI");
		var node;
		for (var i=0; i< thumbList.length; i++) {
			node = thumbList[i];
			node.onmouseover=function() { this.className ="over" }
			node.onmouseout=function() { this.className=""}
			node.onclick = function() { swapPix( this.getElementsByTagName("IMG")[0], largePix); return false };
		}
	}
}
function swapPix(x, y) {
	y.style.backgroundImage = "url("+x.src+")";
	return true
}
function getLocation (d) {
	var regexp = /^\w*:\/\//
	if (regexp.test(d) ) { // ie mac does the work for us, pity it's the only one...
		document.location.href = d;
	} else {
		var y = d.split("../").length;
		d = d.split("../")[y-1];
		var l = document.location.href;
		var x = l.split("/");
		x.length -= y;
		x[x.length] = d;
		document.location.href =x.join("/");
	}
}