/*
Click-Stack 1.3
Developed by Bogart Salzberg, InkFist.Com, 2003
Modified Sept. 24, 2003

Click-Stack may be used, distributed and modified freely
for any purpose while this comment block is enclosed and intact.
Please note modifications in a seperate comment block.

Visit http://inkfist.com/karma_korner/ for more details.
*/

//////////////////////////  GLOBAL VARIABLES  ///////////////////////////////

var default_menu = main_menu;
var xorigin = 8;
var yorigin = 0;
var vis_string = "";
var undefined;
var div_height = 14;
var indent = 8;
var target = "top.frames['body']";
var over_string = "";
var out_string = "";

/////////////////////////////////////////////////////////////////////////////

function getLeft(i) {
	gs = document.getElementById(i).style;
	return gs.left;
}

function getTop(i) {
	gs = document.getElementById(i).style;
	return gs.top;
}

function switchIt(i) {
	if (i.indexOf('plus') != -1) {
		return 'images/minus.gif';
	}
	else {
		return 'images/plus.gif';
	}
}

function start() {
	for (n = 0; n < all_arrays.length; n++) {
		for (m = 0; m < all_arrays[n].length; m++) {
			str = all_arrays[n][m];
			chunks = str.split("|");
			document.write("<DIV class=\"nav_div\" id=\"" + chunks[0] + "\" " +
			over_string +
			out_string +
			"><IMG class=\"expander\" height=\"" + div_height + "\" ");
			if (chunks[3]) {
				document.write("id=\"" + chunks[0] + "_b\" " +
				"src=\"images/plus.gif\" " +
				"onclick=\"move(this.src, " +
				"getLeft('" + chunks[0] + "'), " +
				"getTop('" + chunks[0] + "'), " +
				chunks[3] + "); " +
				"show(this.src, "  +
				"getLeft('" + chunks[0] + "'), " +
				"getTop('" + chunks[0] + "'), " + 
				chunks[3] + "); " +
				"this.src = switchIt(this.src);\">");
			}
			else {
				document.write("src=\"images/spacer.gif\">");
			}
			document.write("<A href=\"#\" class=\"mini\" " +
			"onclick=\"move(1, 0, " +
			"getTop('" + chunks[0] + "'), " + 
			chunks[3] + "); " +
			"show(1, " +
			"getLeft('" + chunks[0] + "'), " +
			"getTop('" + chunks[0] + "'), " + 
			chunks[3] + ", '" + 
			chunks[0] + "'); " +
			target + ".location='" + chunks[2] + "'; " +
			"return false;\">" + chunks[1] + "</A></DIV>");
		}
	}
}

function move(u, xoffset, yoffset, ref) {
	if ((ref == undefined) || (ref == null)) {return}
	if (u != (1 || -1)) {
		if (u.indexOf('plus') != -1) {u = 1}
		else if (u.indexOf('minus') != -1) {u = -1}
		}
	if (u == -1) {return}
	if (u == 1) {
		spl = ref[0].split("|");
		if (document.getElementById(spl[0]).style.visibility == 'visible') {
			return;
		}
	}
	vis_string = vis_string.substring(0, (vis_string.length - 1));
	vis_divs = vis_string.split("|");
//alert("move vis_divs = " + vis_divs);
	vis_string += "|";
	low_divs = [];
	for (q = 0; q < vis_divs.length; q++) {
		cs = document.getElementById(vis_divs[q]).style;
		if (parseInt(cs.top) > parseInt(yoffset)) {
		cs.top = parseInt(cs.top) + (ref.length * div_height);
		} 		
	}
}

function show(u, xoffset, yoffset, ref, call_id) {
	xoffset = parseInt(xoffset);
	yoffset = parseInt(yoffset);
	if ((ref == undefined) || (ref == null)) {return}
	if (u != (1 || -1)) {
		if (u.indexOf('plus') != -1) {u = 1}
		else if (u.indexOf('minus') != -1) {u = -1}
	}
	if (u == -1) {
		vis_string = vis_string.substring(0, (vis_string.length - 1));
		vis_divs = vis_string.split("|");
//alert("show vis_divs = " + vis_divs);
		vis_string += "|";
		cutoff = vis_divs.length * div_height;
		for (q = 0; q < vis_divs.length; q++) {
			cs = document.getElementById(vis_divs[q]).style;
			ttop = parseInt(cs.top);
			left = parseInt(cs.left);
			if (((ttop > yoffset) && (left <= xoffset)) && (ttop < cutoff)) {
				cutoff = ttop;
			}
		}
		low_divs = [];
		side_divs = [];
		for (q = 0, s = 0, t = 0; q < vis_divs.length; q++) {
			cs = document.getElementById(vis_divs[q]).style;
			ttop = parseInt(cs.top);
			left = parseInt(cs.left);
			if ((ttop > cutoff) || ((ttop > yoffset) && (left <= xoffset))) {
				low_divs[s] = vis_divs[q]; s++;
			}
			else if (((ttop > yoffset) && (left > xoffset)) && ttop < cutoff) {
				side_divs[t] = vis_divs[q]; t++;
			}
		}
//alert("show low_divs = " + low_divs);
		for (r = 0; r < low_divs.length; r++) {
			cs = document.getElementById(low_divs[r]).style;
			cs.top = parseInt(cs.top) - (side_divs.length * div_height);
		}
//alert("show side_divs = " + side_divs);
		for (p = 0; p < side_divs.length; p++) {
			cs = document.getElementById(side_divs[p]).style;
			cs.visibility = 'hidden';
			vis_string = vis_string.replace((side_divs[p] + "|"), "");
		}
	}
	else if (u == 1) {
		if (call_id == null) {}
		else {document.getElementById(call_id + "_b").src = 'images/minus.gif'}
		for (n = 0; n < ref.length; n++) {
			str = ref[n];
			chunks = str.split("|");
			if (document.getElementById(chunks[0]).style.visibility == 'visible') {
				return;
			}
			if (chunks[3]) {
				document.getElementById(chunks[0] + "_b").src = 'images/plus.gif';
			}
			cs = document.getElementById(chunks[0]).style;
			cs.left = (xoffset + indent);
			cs.top = (yoffset + ((n + 1) * div_height));
			cs.visibility = 'visible';
			vis_string += (chunks[0] + "|");
		}
	}
}
