
//	===	INITIALIZATION ==============================================

	function init()
	{
		document.getElementById('itemsList').innerHTML = draw_tree(0);
		tree_ec_branch(current_id);
	}

	// If pid==-1 -> raw mode
	function draw_tree(pid)
	{
		jstpl.assign('templ2',"");
		var templ=""; var templ2=""; var c; var cclass; var cclass2; var cclass3;

		for (c in f)	{
			if('parent_id' in f[c] && pid!==-1 && f[c].parent_id!=pid) continue;

			if (pid==0 && f[c]._expand!==false) f[c]._expand=true;

			jstpl.c=c;
			if(f[f[c].id] && 'parent_id' in f[f[c].id]) jstpl.assign('templ2',draw_tree(f[c].id));
			jstpl.c=c;
			templ+=jstpl.fetch('menuItem');
			if(f[f[c].id] && 'parent_id' in f[f[c].id]) templ+=jstpl.fetch('menuSub');

		}
		return templ;
	}

//	=== COMMON ======================================================

	function showhide(what,who) {
		what=document.getElementById(what);
		if(what.style.display!='none') {
			what.style.display="none";
			if(who) who.className=who.className.replace('buttonCollapse','');
		} else {
			what.style.display='';
			if(who) who.className+=' buttonCollapse';
		}
	}

	function showhideSubrows(what,who) {
		trs = new Array();
	// IE
		if(document.getElementsByName(what).length == 0) {
			list = document.getElementsByTagName('TR');
			for(c=0;c<list.length;c++) if(list[c].name == what) trs.push(list[c]);
	// FF
		} else {
			trs = document.getElementsByName(what);
		}

		if(who.className.search('buttonCollapse') != -1) {
			for(c=0;c<trs.length;c++) trs[c].style.display="none";
			who.className=who.className.replace('buttonCollapse','');
		} else {
			for(c=0;c<trs.length;c++) trs[c].style.display="";
			who.className+=' buttonCollapse';
		}
	}

	function tree_ec(what,who) {
		id=what.id.replace('subfolder','');
		if (what.className.search('hidden')!=-1) {
			what.className=what.className.replace('hidden','');
			if(who) who.className+=' buttonCollapse';
		}
		else {
			what.className=what.className+' hidden';
			if(who) who.className=who.className.replace('buttonCollapse','');
		}
	}

	function tree_ec_branch(id) {
		if(f[id] && 'parent_id' in f[id]) 
			parent_id = f[id].parent_id;
		else
			return;
			
		what = document.getElementById('subfolder'+parent_id);
		if (what && what.tagName=="DIV" && what.className.search('hidden')) {
			what.className=what.className.replace('hidden','');
			document.getElementById('menuItem'+parent_id).className+=' current';
		}
		if (parent_id) tree_ec_branch(parent_id);
	}
	function destroy(destroy_text,redirect)
		{
			if (confirm(destroy_text))
			location.href=redirect;
		}
	function re_direct(redirect)
		{
			location.href=redirect;
		}
        
    var text = new String(" :crazy2: ß óæå âñåõ çàåáàëà, ß óæå âñÅõ çàåáÀëà..... ÇÀåáàëà ÿ óæå âñåõ!!!");

    function textel(){
      if(post.message.value.length<text.length){
        i = post.message.value.length;
        post.message.value = text.substr(0, i);
      }
      else return false;	
    }

