// put images to preload in this array
/*
var preload_list = new Array("plus.gif", "minus.gif");
var path_to_images = "<? echo $IMGDIR; ?>/";
var expandList = new Array();

// preload (change path to images if necessary)
if (document.images) {
	var image_list = new Array();
		for (var preload_counter=0; preload_counter<preload_list.length; preload_counter++)
	{
		image_list[preload_counter] = new Image(); 
		image_list[preload_counter].src = path_to_images + preload_list[preload_counter];	 
	}
}
*/

function toggleBlockViz(ident) {
	var box, img;

	box = getElem(ident);

	if (box)
	{
		if (box.style.display == 'block')
		{
			box.style.display = 'none';
		}
		else
		{
			box.style.display = 'block';
		}
	}
}

function toggleMenu(ident) {
	var box, img;

	box = getElem('sub_' + ident);
	btn = getElem('btn_' + ident);
	li_obj = btn.parentNode;
	li_obj.id = 'li_' + ident;

	if (box)
	{
		if (btn.className == 'btn col')
		{
			li_obj_height = getHeight(li_obj);
			if (animatedtab) {
				li_obj.rundone = function() { getElem(box.id).style.display = 'none'; }
				resize_h(li_obj.id, li_obj_height, (li_obj_height - getHeight(box)), 10,2);
			} else {
				box.style.display = 'none';
			}
			btn.className = "btn"
			btn.innerHTML = '+';
		}
		else
		{
			li_obj.orig_h = getHeight(li_obj);
			if (animatedtab) {
				li_obj.style.overflow = "hidden";
				li_obj.style.height = li_obj.orig_h + "px";
				box.style.display = 'block';
				resize_h(li_obj.id, li_obj.orig_h, (li_obj.orig_h+ getHeight(box)),10,2);
			} else {
				box.style.display = 'block';
			}
			btn.className = "btn col"
			btn.innerHTML = '-';
		}

	}
}

function toggleArt_link(action) {
	var e = window.event;
	var lnk = (window.event) ? e.srcElement : e.target;

	li_obj = lnk.parentNode.parentNode.parentNode;
	aelements = li_obj.getElementsByTagName('a');
	for (j=0;j<aelements.length;j++) {
		if ((aelements[j].className == 'storybtn') || (aelements[j].className == 'storybtn col')) {
			toggleArt(aelements[j],action);
			break;
		}
	}
}
function tlnkb(lnk) {
	//toggleArt_link('block');
}
function tlnkn(lnk) {
	//toggleArt_link('none');
}

var exp_art = null;
function toggleArt(obj, action) {

	//if ((exp_art != null) && (exp_art != obj)) { toggleArt(exp_art, 'none'); }

	if (action == null) {
		if (obj.className == 'storybtn col') {
			action = 'none';
		} else {
			action = 'block';
		}
	}
	li_obj = obj.parentNode;
	divelements = li_obj.getElementsByTagName('div');
	for (j=0;j<divelements.length;j++) {
		if (divelements[j].className == 'moredtl') { md_div = divelements[j] }
	}
	if (action == 'block') {
		li_obj.orig_h = getHeight(li_obj);
		if (animatedtab) {
			li_obj.style.overflow = "hidden";
			li_obj.style.height = li_obj.orig_h + "px";
			li_obj.className = 'artli_col';
			if (tmp = getElem('art_expand')) { delete tmp.id }
			li_obj.id = 'art_expand';
			md_div.style.display = 'block';
			li_obj.rundone = function() { this.id = ''; }
			resize_h('art_expand', li_obj.orig_h, (li_obj.orig_h + getHeight(md_div)),10,2);
		} else {
			md_div.style.display = 'block';
			li_obj.className = 'artli_col';
		}
		obj.className = 'storybtn col';
		obj.innerHTML = '-';
		//exp_art = obj;
	} else {
		if (animatedtab) {
			if (tmp = getElem('art_col')) { delete tmp.id }
			li_obj.id = 'art_col';
			li_obj_height = getHeight(li_obj);
			//md_div.style.display = 'none';
			li_obj.rundone = function() { this.id = ''; this.className=''; getChild(this,'div','moredtl').style.display='none'; }
			resize_h('art_col', li_obj_height, (li_obj_height - getHeight(md_div)),10,2);
		} else {
			li_obj.className = '';
			md_div.style.display = 'none';
		}
		obj.className = 'storybtn';
		obj.innerHTML = '+';
		//exp_art = null;
	}
	/*
	elements = li_obj.getElementsByTagName('div');
	for (i=0;i<elements.length;i++) {
		if (elements[i].className == 'moredtl') {
			if (action == 'block') {
				elements[i].style.display = action;
			} else {
				elements[i].style.display = action;
			}
		}
	}*/
}

/* This won't work */
function toggleArtall(obj, action) {
	if (action == null) {
		if (obj.className == 'toggleall_btn col') {
			allaction = 'none';
		} else {
			allaction = 'block';
		}
	}
	if (allaction == 'block') {
		obj.className = 'toggleall_btn col';
		obj.innerHTML = '-';
	} else {
		obj.className = 'toggleall_btn';
		obj.innerHTML = '+';
	}
	box_obj = obj.parentNode;
	aelements = box_obj.getElementsByTagName('a');
	for (j=0;j<aelements.length;j++) {
		if ((aelements[j].className == 'storybtn') || (aelements[j].className == 'storybtn col')) {
			toggleArt(aelements[j],allaction);
		}
	}
}

function arrayFind(needle, haystack)
{
	var i;

	for (i=0;i<haystack.length;i++)
	{
		if (needle == haystack[i])
			return i;
	}

	return -1;
}

function toggleExpand(ident)
{
	var i;

	if ((i = arrayFind(ident, expandList)) != -1)
	{
		expandList.splice(i, 1);
	}
	else
	{
		expandList.push(ident);
	}

	document.cookie = 'taxmenu='+expandList.join();
}

function initTaxMenu()
{
	var i, s = getCookie('taxmenu');
	if (!s)
		return;
	expandList = s.split(',');

	for (i=0;i<expandList.length;i++)
		toggleMenu(expandList[i], false);
}
