var vars = {
	preOpenPos: 0, // index of the one to open on start	
	lastSelected: null,
	sliders: new Array()
};

function init() {	
	if (!document.getElementById || !document.getElementsByTagName) {
		return;
	}
	
	var s = document.getElementById('sliders');
	if (!s) return;
	var tmp = s.getElementsByTagName('DIV');
	var reIsSlider = /sliderset/;
	vars.sliders = new Array();
	var count = 0; // separate counter for just the divs we care about
	for (var i = 0; i < tmp.length; i++) {
		var t = tmp[i];
		if (t && t.className && reIsSlider.test(t.className)) {
			if (count != vars.preOpenPos) {
				t.className += ' closed';
			} else {
				vars.lastSelected = t;
			}
			vars.sliders.push(t);
			count++;
		}
	}
}

function openSlider(self) {
	// find the parent container div of the <A> tag
	var parent = self;
	while (parent && parent.nodeName.toLowerCase() != 'div') {
		parent = parent.parentNode;
	}
	
	// if we couldn't find it, or if init didn't run, or it's the open one, return
	if (!vars.lastSelected || !parent || parent == vars.lastSelected) return true;
	
	// locked tab... link probably leads outside
	if (/locked/.test(parent.className)) return true;
	
	// close the old one
	vars.lastSelected.className += ' closed';

	// scan the sliders to find the one that got clicked
	var i = 0;
	while (i < vars.sliders.length && vars.sliders[i] != parent) i++;

	// select the new one
	vars.lastSelected = vars.sliders[i];
	vars.lastSelected.className = vars.lastSelected.className.replace(' closed', '');

	// remove unsightly focus rect
	self.blur();

	return true;
}

function clearbox(box) {
	if (!box) {
		return;
	}
	if (box.value == 'Search') {
		box.style.color = '#445';
		box.value = '';
	} else if (box.value == '') {
		box.style.color = '#ccc';
		box.value = 'Search';
	}
}

function openLabSlider(self) { 
	window.setTimeout(function() {
		document.getElementById('labframe').src='map.html';
	}, 250);
	return openSlider(self);
}

window.onload = init;
