/*Script para generar el menu lateral.
Primero se encuentran las funciones y hasta abajo el menu en si.

*/

var height = 30; // height of the menu headers (size of the image)
var iheight = 15; // height of the menu_items 
var bgc = "FFFFFF" // background color of the item
var tc = "999999" // text color of the item 
var over_bgc = "FFFFFF";
var over_tc = "999999"; 
var speed = 0; 
var timerID = "";
var N = (document.all) ? 0 : 1;
var width = 171;
var self_menu = new Array();

/*This function breaks every element in the array, using the '|' as separator and stores
the element in the array la

la[0] contains the type
	0 -> Top Menu
	1 -> Item
	2 -> Item continuation
	3 -> Item, but shows as menu (doesn't contains items)
la[1] contains the Description (what will be output)
la[2] contains the link
la[3] contains the target modifiers (like new for new window)
*/

function write_menu()
{
	smc = 0; // count the position of the self_menu
	document.write("<div style='position:absolute'>");
	mn = 0;
	mni = 1;
	start = -1;

	for(i=0;i<Link.length;i++)
	{
		la = Link[i].split("|");
		if (la[0] == "0" || la[0] == "3")
		{
			if(start == 0) 
			{
				document.write("</div>");
				h = csmc * iheight;
				tmn = mn; //-h
				self_menu[smc] = new Array(tmn,h,0,-2);
				smc++;
				mn--;
			}
			csmc = 0;

			if (la[0] == "3")
			{

				document.write("<div class='menu' style='top:"+mn+";height:"+height+"' id='down"+smc+"' style='width:174'>");
				document.write("<a href='"+la[2]+"' ");
				if (la[3] != "") document.write(" target='" + la[3] + "' ");
				document.write(" style='text-decoration:none;'> "+ la[1] + "</a></div>");
			}
			else
			{
				document.write("<div class='menu' style='top:"+mn+";height:"+height+"' id='down"+smc+"' style='width:174' onclick='pull_down("+smc+","+mni+")'><a style='text-decoration:none;'>"+ la[1] + "</a></div>");
			}

			self_menu[smc] = new Array(mn,height,0,mni);
			smc++;
			mni++;
			mn+=height;
			start = 1;
		}
		else /*type is not 0 or 3*/
		{
			if(start == 1) 
			{
				if(N)mn+=2;
				document.write("<div class='item_panel' id='down"+smc+"' style='width:177;top:"+mn+"'>");
				start = 0;
			}
			document.write("<a href='"+la[2]+"'");
			if (la[3] != "") document.write(" target='" + la[3] + "' ");
			document.write("><div class='item' id='d"+i+"' style='height:"+iheight);
			if (N) document.write(";width:177");
			var bullet=">";
			if (la[0] == 2) bullet="&nbsp;&nbsp;";
			
			document.write("' >&nbsp;&nbsp;&nbsp;&nbsp;"+bullet+"&nbsp;"+ la[1] + "</div></a>");

			csmc++;
		}
	}

	if (start == 0) 
	{
	  document.write("</div>");
	  h = csmc * iheight;
	  tmn = mn + 5; //-h
	  self_menu[smc] = new Array(tmn,h,0);
	  name = "down" + (self_menu.length-1);
	  obj = document.getElementById(name);
	  obj.style.borderBottomColor = "darkblue";
	  obj.style.borderBottomWidth = 1;
	  obj.style.borderBottomStyle = "solid";
	}

	document.write("</div>");
}
 
function pull_down(nr,c)
{
	if (timerID == "")
	{
		to = self_menu[nr+1][1]
		begin = nr + 2;
		if (timerID != "") clearTimeout(timerID);
		if (self_menu[nr+1][2] == 0)
		{
			self_menu[nr+1][2] = 1;
			if(nr == self_menu.length-2) {to++;}
			epull_down(begin,to,0);
		}
		else
		{
			to = 0;
			self_menu[nr+1][2] = 0;
			name = "down"+(nr+2);
			open_item = 0;
			for(i=0;i<nr;i++)
			{
				if(self_menu[i][2] == 1) 
				{
				open_item += self_menu[i][1];
				}
			}

			if (N == false) {open_item-= (c*1)};
			if (nr== self_menu.length-2)
			{
				val = self_menu[self_menu.length-1][1];to=-1;
			}
			else val = parseInt(document.getElementById(name).style.top) -(open_item)-(c*height);
			
			epull_up(begin,to,val);
		}
	}
}

 

function epull_down(nr,to,nowv)
{
	name = "down" + (nr-1);
	obj = document.getElementById(name).style.clip = "rect(0,"+width+","+(nowv+1)+",0)";
	for (i=nr;i<self_menu.length;i++)
	{
		name = "down" + i;
		obj = document.getElementById(name);
		obj.style.top = parseInt(obj.style.top)+1;
	}
	nowv++;
	if(nowv < to) timerID = setTimeout("epull_down("+nr+","+to+","+nowv+")",speed);
	else timerID = "";
}

function epull_up(nr,to,nowv)
{
	name = "down" + (nr-1);
	obj = document.getElementById(name).style.clip = "rect(0,"+width+","+nowv+",0)";
	for (i=nr;i<self_menu.length;i++)
	{
		name = "down" + i;
		obj = document.getElementById(name);
		obj.style.top = parseInt(obj.style.top)-1;
	}
	nowv--;
	if(nowv > to) timerID = setTimeout("epull_up("+nr+","+to+","+nowv+")",speed);
	else timerID = "";
}

function startup(nr)
{
	write_menu();
	if (nr != 0)
	{
		for(i=0;i<self_menu.length;i++)
		{
			if(self_menu[i][3] == nr) pull_down(i,nr)
			i==self_menu.length;
		}
	}
} 


/*Aqui declaramos el arreglo de items y links:

	0 -> Top Menu
	1 -> Item
	2 -> Item continuation
	3 -> Item, but shows as menu (doesn't contains items)
*/
var Link = new Array();
Link[0] = "0|<img src='http://elmarques.gob.mx/imagenes/MenuSim.jpg' border='0' >";
Link[1] = "1|Historia|http://elmarques.gob.mx/historia.htm|";

Link[2] = "0|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/MenuTransparencia.jpg' border='0' >";
Link[3] = "1|Ley Estatal de Acceso|http://elmarques.gob.mx/transparencia/index.htm|";
Link[4] = "2|a la Informacion|http://elmarques.gob.mx/transparencia/index.htm|";
Link[5] = "2|Gubernamental en |http://elmarques.gob.mx/transparencia/index.htm|";
Link[6] = "2|el Estado de Quer&eacute;taro|http://elmarques.gob.mx/transparencia/index.htm|";
Link[7] = "1|Solicita Informaci&oacute;n|http://elmarques.gob.mx/formulario_mail_solicitud.html|";
Link[8] = "1|Danos tu opini&oacute;n|http://elmarques.gob.mx/formulario_mail_solicitud.html|";

Link[9] = "3|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menuDenuncia.png' border='0' >|http://elmarques.gob.mx/formulario_mail_solicitud.html|";

Link[10] = "3|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menu_boletines.png' border='0' >|http://elmarques.gob.mx/boletines.htm|";

Link[11] = "0|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menuTyS.png' border='0' >";
Link[12] = "1|Tr&aacute;mites y Servicios|http://elmarques.gob.mx/transparencia/serv_tramites.htm|";
Link[13] = "1|Cartilla Militar|http://elmarques.gob.mx/transparencia/serv_tramites.htm#cartilla_militar|";
Link[14] = "1|.|";
Link[15] = "1|.|";

Link[16] = "0|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menuAyuntamiento.png' border='0' >";
Link[17] = "1|Regidores y Comisiones|http://elmarques.gob.mx/admon2009_2012/inf_consulta/ayuntamiento/regidores.pdf|";

Link[18] = "0|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menuServFedEst.gif' border='0' >";
Link[19] = "1|Tr&aacute;mites Estatales|http://www.queretaro.gob.mx/|";
Link[20] = "1|Seguro Popular|http://www.seguropopularqueretaro.gob.mx|";

Link[21] = "3|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menuDif.jpg' border='0' >|http://elmarques.gob.mx/transparencia/dif.html|";
Link[22] = "3|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menuEventos.png' border='0' >|http://elmarques.gob.mx/eventos.htm|";
Link[23] = "3|<img src='http://elmarques.gob.mx/admon2009_2012/imagenes/menu1er_informe.png' border='0' >|http://elmarques.gob.mx/inf_consulta/admin_2009_2012/informes/1er_informe_gobierno.html|";

