//free JavaScripts at http://www.ScriptBreaker.com
var height = 150;
var vwidth = 147;
var speed = 2;
var step =3;
var hheight = 22; // heigth of a header item
var iheight = 19; // heigth of a item
var bgc = "#E9E9E9"; // background color of the item
var tc = "#000000"; //"white" // text color of the item
var textdec  =  "none";
var over_bgc = "#CECECE";
var over_tc = "#000000"; //"#FFFFFF";
var over_textdec  =  "none"; // underline 
var opened = -1;
var N = (document.all) ? 0 : 1;
var Link_count = 0;
var ntop = 0;
var items = false;
var z = 0;
var hnr = 1;
var timerID = null;
var link_array = new Array();

//arv2009 - ordenacao de tabulacao
var t_index = 14;
//arv2009 - final ordenacao de tabulacao

/**
 * funcao otimizada e incrementada por mxFerreira
 */
function write_menu(){
	var menu_html = "";
	menu_html = "<div id='main_panel' style='height:";
	if (N) 
		menu_html += height;
	else 
		menu_html += height-2;
	menu_html += ";width:";
	if (N) 
		menu_html += vwidth;
	else 
		menu_html += vwidth-2;
	menu_html += "'>";
	
	var cl =0;
	var la;
	for(i=0;i<Link.length;i++){
		la = Link[i].split("|");
		if(la[0] == "0"){
			if (items == true) {
				menu_html +=  "</div>";
				items = false;
			}
			menu_html += "<div class='head_item' id='move"+cl+"' style='height:"+hheight+";width:"+vwidth+";top:"+(ntop-1)+";z-index:"+z+"' onclick='move("+cl+","+hnr+")'>&nbsp;<span>"+la[1]+"</span></div>";
			link_array[cl] = new Array("up",0,hnr);
			cl++;
			hnr++;
			ntop += hheight-1;
			z++;
		}else{
			cheight = height - ntop + 1;
			if (items == false) {
				menu_html += "<div class='item_panel' id='move"+cl+"' style='height:"+cheight+"px;width:"+vwidth+";top:";
				if (N) 
					menu_html += ntop+2;
				else
					menu_html += ntop;
				menu_html += ";z-index:"+z+"'>";
				z++;
				link_array[cl] = new Array("up",0,"");
				cl++;
			}
			menu_html += "<a href='"+la[2]+"'";
			if (typeof(la[3]) != "undefined") 
				menu_html += " target='" + la[3] + "' ";
			if (typeof(la[4]) != "undefined") 
				menu_html += " title='" + la[4] + "' ";
                        // arv2009 - ordenacao do menu
                        menu_html += " onmouseover=color('item"+i+"') onmouseout=uncolor('item"+i+"') ><div class='item' id='item"+i+"' style='height:"+iheight+";width:"+vwidth+"' tabindex='"+t_index+"'>&nbsp;&nbsp;"+la[1]+"</div></a>";
                        t_index++;
                        // arv2009 - final ordenacao menu;

			items = true;
		}
	}
	menu_html += "</div>";
	if (items == true) {
		menu_html += "</div>";
	}
	document.write(menu_html);
}

function color(obj){
	document.getElementById(obj).style.backgroundColor = over_bgc;
	document.getElementById(obj).style.color = over_tc;
	document.getElementById(obj).style.textDecoration  =  over_textdec;
}

function uncolor(obj){
	document.getElementById(obj).style.backgroundColor = bgc;
	document.getElementById(obj).style.color = tc;
	document.getElementById(obj).style.textDecoration  =  textdec;
}

/**
 * move function with Cookie controller 
 * added by mxFerreira
 */
function move(idnr,hid){
	var down;

	//added by mxFerreira
	setCookie('selected_menu', hid);

	if ((idnr != opened)&& (timerID == null)){
		if(link_array[idnr][0] == "up"){
			down = height - (hid * hheight) - ((hnr -(hid+1))* hheight) + 2;
			if(N) 
				down+=2;
			dmover(idnr+2,down);
		}else{
			up = height - ((hid -1) * hheight) -((hnr - (hid))* hheight) +2;
			if(N) 
				up+=2;
			umover(idnr,up);
		}
		opened = idnr;
	}
}

function dmover(idnr,down){
	var i, txt_obj;
	for (i=idnr;i<link_array.length;i++){
		if(link_array[i][0] == "up"){
			txt_obj = "move" + i;
			document.getElementById(txt_obj).style.top = parseInt(document.getElementById(txt_obj).style.top) + step;
		}
	}
	down-= step;
	if(down > 0)
		timerID = setTimeout("dmover("+idnr+","+down+")",speed);
	else{
		for (i=idnr;i<link_array.length;i++) {link_array[i][0] = "down";}
		timerID = null;
	}
}

function umover(idnr,up){
	var i, txt_obj;
	for (i=0;i<(idnr+2);i++){
		if(link_array[i][0] == "down"){
			txt_obj = "move" + i;
			document.getElementById(txt_obj).style.top = parseInt(document.getElementById(txt_obj).style.top) - step;
		}
	}
	up-=step;
	if(up > 0)
		timerID = setTimeout("umover("+idnr+","+up+")",speed);
	else{
		for (i=0;i<(idnr+2);i++) {
			link_array[i][0] = "up";
		}
		timerID = null;
	}
}

function start(idnr){
	write_menu();
	for(i=0;i<link_array.length;i++){
		if (link_array[i][2] == idnr){
			pull = i;
			i = link_array.length;
		}
	}

	move(pull, idnr);
}

//-------------------------------------------------------
// Funcoes auxiliares
//-------------------------------------------------------

//////////////////////////////////////
// Cookies
/////////////////////////////////////
/**
 * Sets a Cookie with the given name and value.
 *
 * name		 Name of the cookie
 * value		Value of the cookie
 * [expires]	Expiration date of the cookie (default: end of current session)
 * [path]	 Path where the cookie is valid (default: path of calling document)
 * [domain]	 Domain where the cookie is valid
 *				(default: domain of calling document)
 * [secure]	 Boolean value indicating if the cookie transmission requires a
 *				secure transmission
 */
function setCookie(name, value, expires, path, domain, secure){
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name	Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *	 or null if cookie does not exist.
 */
function getCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(nameEQ) == 0) 
		return c.substring(nameEQ.length,c.length);
	}
	return null;
}//end getCookie()

/**
 * Deletes the specified cookie.
 *
 * name		name of the cookie
 * [path]	path of the cookie (must be same as path used to create cookie)
 * [domain]	domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain){
	if (getCookie(name)){
		document.cookie = name + "=" + 
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}//end deleteCookie()