// ADD EVENT ----------------------------------------
function addEvent_ (obj, type, fn)
{
	if (obj.addEventListener)
		obj.addEventListener (type, fn, false);
	else if (obj.attachEvent)
	{
		obj['e' + type + fn] = fn;
		obj[type + fn] = function () { obj['e' + type + fn] (window.event); }
		obj.attachEvent ('on' + type, obj[type+fn]);
	}
}
// --------------------------------------------------
// MENU ACCORDION -----------------------------------
var acco_cur_id = "";
var acco_speed = 0.4;

function menu_acco ()
{
	this.blur();
	var id_nr = this.id.substr(this.id.indexOf("b") + 1);

	if (acco_cur_id != "")
	{
		if (id_nr != acco_cur_id)
		{
			new Effect.SlideUp("acco_c" + acco_cur_id, {duration: acco_speed});
			new Effect.SlideDown("acco_c" + id_nr, {duration: acco_speed});

			$("acco_t" + id_nr).className = "btn_active";
			$("acco_t" + acco_cur_id).className = "btn";

			acco_cur_id = id_nr;
		} 
		else 
		{
			new Effect.SlideUp("acco_c" + acco_cur_id, {duration: acco_speed});
			$("acco_t" + acco_cur_id).className = "btn";

			acco_cur_id = "";
		}
	} 
	else
	{
		new Effect.SlideDown("acco_c" + id_nr, {duration: acco_speed});
		$("acco_t" + id_nr).className = "btn_active";

		acco_cur_id = id_nr;
	}
}
// INIT -------------------------------
function accordion_init ()
{
	if( $('files_container') != undefined )
	{
		var counter = 1;
		var len = $('files_container').childNodes.length;

		for (var i = 0; i < len; i++)
		{
			if ($('files_container').childNodes[i].nodeType === 1)	// Mozilla counts the white spaces
			{
				if ($("acco_t" + counter).className != "btn_active") Element.hide("acco_c" + counter);
				else acco_cur_id = counter;
			
				// Void LI (kill "Effect.SlideDown()" bug)
				var li = document.createElement ('LI');
				li.setAttribute('id', 'li_void' + counter);
				$("acco_c" + counter).insertBefore(li, $("acco_c" + counter).firstChild);
				$('li_void' + counter).className = "li_void";

				// Add onclick-event
				addEvent_ ($("acco_b" + counter), "click", menu_acco);
				counter++;
			}
		}
	}
}
// --------------------------------------------------
// WINDOW ON LOAD -----------------------------------
window.onload = function ()
{ 
	accordion_init ();
}
// --------------------------------------------------



