/* Accordion menu script * www.pimpmyforum.nl */

/* Create a menu like this, links and lists:
	<div class="acc_menu">
		<p><a href="http://...">Dynamic Drive</a></p>
		<p><a href="#" [id="some_id"]>Submenu header</a></p>
    <ul>
			<li><a href="http://...">Submenu item 1</a></li>
      <li><a href="http://...">Submenu item 2</a></li>
    </ul>
		<p><a href="http://...">Next menu item</a></p>
	</div>

	Assumes that if href==#, that it is a submenu header and not a link.
	<ul> ... will be turned into submenu

	You can open/close submenu's using a link like this:
	<a href="#" onclick="acc_menu_open(document.getElementById('some_id'));">Click!</a>
	in order to draw attention to it. You cannot control whether it opens or closes, that depends.
*/
var acc_next_click = '';
var acc_open = ''
var acc_open_parent = '';
var acc_dir = 1;
var acc_busy = 0;
var acc_href = '';

//Click on normal menu item: open in iframe directly
function acc_click(o)
{
	document.getElementById('iframe').contentWindow.location=o.href.replace(/(\w)[\/]/, "$1/iframe_");
}
//Click on submenu header: animate
function acc_menu_click(o)
{
	if (acc_busy) return;
	acc_busy = 1;
	//acc_menu_click('', url): Call to close current menu and possibly execute an url
	if (o == undefined) {acc_animate(-1); return;}
	var p = o.parentNode.nextSibling; while(p && p.tagName != 'UL') {p = p.nextSibling;}
	//Clicked on the current open menu header: close current menu
	if (p == acc_open) {acc_animate(-1); return;}
	//Clicked on another menu header: close current first
	if (acc_open)	{acc_next_click = o; acc_animate(-1); return;}
	//Clicked on a menu header, everything is closed:
	acc_open = p; acc_open_parent = o;
	acc_open.style.display = 'block';
	if (!acc_open.name) acc_open.name = acc_open.offsetHeight;
	acc_open.style.height = '0px';
	acc_animate(1);
}

function acc_animate(dir)
{
//Starting call: open or close current
	if (dir) acc_dir = dir;

//If have acc_open then continue
	var h = 0;
	var hmax = 0; //h == 0 specifies 'finished closing' and applies if there is no acc_open too
	if (acc_open)
	{	//Get current and max height * name tag is used to store max height
		h = parseInt(acc_open.offsetHeight);
		hmax = parseInt(acc_open.name);
		h = h + 20 * acc_dir; if(h > hmax) h = hmax; if (h < 0) h = 0;
		acc_open.style.height = h + 'px'; //animate
		//Finished opening or closing: alter the [+] [-] image
		if (h==0 || h==hmax)
		{
			var child = acc_open_parent.getElementsByTagName('img');
			var image = "url(" + (h == 0 ? 'images/plus.gif' : 'images/minus.gif') + ")";
			child[0].style.backgroundImage = image;
		}
	}
//Finished closing (or nothing to close)? Start opening next, if any
	if (h==0)
	{
	  if (acc_open) {acc_open.style.display='none';}
		acc_open = ''; acc_open_parent = '';
		var o = acc_next_click; acc_next_click = '';
		if (o) {acc_busy=0;acc_menu_click(o);return;} //setTimeout("acc_animate(1)",30); return;}
		acc_busy = 0; //All finished
		//No menu to open, execute url if any
		if (acc_href) {document.getElementById('iframe').contentWindow.location=acc_href; acc_href = '';}
		return;
	}
//Finished opening a menu
	if (h == hmax)
	{
	  acc_busy = 0; //Allow a new sequence, keep acc_open
		return; //no further action
	}
//Continue animation
	setTimeout("acc_animate()",30);
}

