function showMenu(titulo,id){
	if ($('cont-opc-' + id).style.display != "none") {
		Effect.BlindUp('cont-opc-' + id, {
			duration: 0.3
		});
		$(titulo).removeClassName("active");
		$("opcInf-"+id).addClassName("close");
		return;
	}
		
	var secciones = $$(".cont-opc");	
	secciones.each(function(seccion){
		if (seccion != $('cont-opc-' + id)) {
			Effect.BlindUp(seccion, {
				duration: 0.3
			});
		}
	});
	
	var mgBtm=$$(".opcInf");
	mgBtm.each(function(mg){
		mg.addClassName("close");
	});
	
	var activos=$$(".active");
	activos.each(function(activo){
		activo.removeClassName("active");
	});
	
	if ($('cont-opc-' + id).style.display == "none") {
		Effect.BlindDown('cont-opc-' + id, {
			duration: 0.3
		});
		$(titulo).addClassName("active");
		$("opcInf-"+id).removeClassName("close");		
	}		
}

function popupMapa(){
	var bkgr = new Element("div", {
		'class': 'bkgr'
	});
	bkgr.setStyle({
		height: $$("body")[0].getHeight() + "px",
		width: $$("body")[0].getWidth() + "px"
	});
	
	var cont = new Element("div", {
		'class': 'cont'
	});
	
	$$("body")[0].insert(bkgr);
	$$("body")[0].insert(cont);
	var direccion = "/php/codes/scripts.php";
	var parametros = "action=verMapa";
	var funcion = function(resp){
		var res = resp.responseText.trim();
		cont.update(res);
		var cerrar = function(){
			bkgr.remove();
			cont.remove();
		}
		$("tache").observe("click", function(){
			cerrar();
		});
		Event.observe(document, "keyup", function(e){
			if (!bkgr) {
				return;
			}
			var tecla = teclas(e);
			if (tecla == 27) {
				cerrar();
			}
		});		
		agregarTolTipis("ac","Aguascalientes");
		agregarTolTipis("bc","Baja California Norte");
		agregarTolTipis("cla","Coahuila");
		agregarTolTipis("df","Distrito Federal");
		agregarTolTipis("em","Estado de México");
		agregarTolTipis("gto","Guanajuato");
		agregarTolTipis("gro","Guerrero");
		agregarTolTipis("hgo","Hidalgo");
		agregarTolTipis("jal","Jalisco");
		agregarTolTipis("mls","Morelos");
		agregarTolTipis("nyt","Nayarit");
		agregarTolTipis("nl","Nuevo León");
		agregarTolTipis("pba","Puebla");
		agregarTolTipis("qro","Querétaro");
		agregarTolTipis("qroo","Quintana Roo");
		agregarTolTipis("slp","San Luis Potosí");
		agregarTolTipis("sla","Sinaloa");
		agregarTolTipis("tbc","Tabasco");
		agregarTolTipis("vz","Veracruz");
		agregarTolTipis("ytn","Yucatán");		
	}
	new Ajax.Request(direccion, {
		method: 'post',
		parameters: parametros,
		onSuccess: funcion
	});
}

function agregarTolTipis(id,titulo){	
	new Tip(id,getContenidos(id),{
		title: titulo,
		style: 'protogrey',
		stem: 'topLeft'		
	});	
	new Tip("l"+id,getContenidos(id),{
		title: titulo,		
  		style: 'protogrey',
  		stem: 'leftTop'  		  		
	});	
}

function getContenidos(id){
	var contenidos= new Array();
	var head=
		"<table class='toltiptbl'>" +
			"<tr class='titletbl'>" +
				"<th>Localidad</th>" +
				"<th>Trabajadores</th>" +
			"</tr>" +
			"<tr>";
	var foot="</tr></table>";
			
	contenidos["bc"] = 
		head +
		"<th>Mexicali</th>" +
		"<td>1</td>" +
		foot;
				
	contenidos["ac"] = 
		head +
		"<th>Aguascalientes</th>" +
		"<td>4</td>" +
		foot;
		
	contenidos["cla"] = 
		head +
		"<th>Ramos Arizpe</th>" +
		"<td>117</td>" +
		"</tr></tr>" + 
		"<th>Saltillo</th>" +
		"<td>4</td>" +
		foot;
	
	contenidos["df"] = 
		head +
		"<th>Ajusco</th>" +
		"<td>1</td>" +
		"</tr></tr>" + 
		"<th>Oriente</th>" +
		"<td>2</td>" +
		"</tr></tr>" + 
		"<th>Vallejo</th>" +
		"<td>0</td>" +
		"</tr></tr>" + 
		"<th>San Antonio</th>" +
		"<td>1</td>" +
		"</tr></tr>" + 
		"<th>Santa Fé</th>" +
		"<td>6</td>" +
		foot;
		
	contenidos["df"] = 
		head +
		"<th>Ajusco</th>" +
		"<td>1</td>" +
		"</tr></tr>" + 
		"<th>Oriente</th>" +
		"<td>2</td>" +
		"</tr></tr>" + 
		"<th>Vallejo</th>" +
		"<td>0</td>" +
		"</tr></tr>" + 
		"<th>San Antonio</th>" +
		"<td>1</td>" +
		"</tr></tr>" + 
		"<th>Santa Fé</th>" +
		"<td>6</td>" +
		foot;
	
	contenidos["em"] = 
		head +
		"<th>Atlacomulco</th>" +
		"<td>15</td>" +
		"</tr></tr>" + 
		"<th>Cuatitlán</th>" +
		"<td>5</td>" +
		"</tr></tr>" + 
		"<th>Macro</th>" +
		"<td>3</td>" +
		"</tr></tr>" + 
		"<th>Naucalpan</th>" +
		"<td>2</td>" +
		"</tr></tr>" + 
		"<th>Toluca</th>" +
		"<td>584</td>" +
		"</tr></tr>" + 
		"<th>Tultitlán</th>" +
		"<td>2</td>" +
		"</tr></tr>" + 
		"<th>Valle de Bravo</th>" +
		"<td>7</td>" +
		foot;
	
	contenidos["gto"] = 
		head +
		"<th>Irapuato</th>" +
		"<td>18</td>" +
		"</tr></tr>" + 
		"<th>León</th>" +
		"<td>4</td>" +
		foot;
	
	contenidos["gro"] = 
		head +
		"<th>Acapulco</th>" +
		"<td>5</td>" +		
		foot;
		
	contenidos["hgo"] = 
		head +
		"<th>Pachuca</th>" +
		"<td>15</td>" +		
		foot;
	
	contenidos["jal"] = 
		head +
		"<th>Guadalajara</th>" +
		"<td>15</td>" +
		"</tr></tr>" + 
		"<th>Puerto Vallarta</th>" +
		"<td>2</td>" +		
		foot;
	
	contenidos["mls"] = 
		head +
		"<th>Cuernavaca</th>" +
		"<td>4</td>" +
		foot;
		
	contenidos["nyt"] = 
		head +
		"<th>Tepic</th>" +
		"<td>2</td>" +
		foot;
	
	contenidos["nl"] = 
		head +
		"<th>Monterrey</th>" +
		"<td>126</td>" +
		foot;
		
	contenidos["pba"] = 
		head +
		"<th>Puebla</th>" +
		"<td>4</td>" +
		foot;
	
	contenidos["qro"] = 
		head +
		"<th>Querétaro</th>" +
		"<td>3</td>" +
		foot;
		
	contenidos["qroo"] = 
		head +
		"<th>Cancún</th>" +
		"<td>1</td>" +
		foot;
		
	contenidos["slp"] = 
		head +
		"<th>San Luis Potosí</th>" +
		"<td>3</td>" +
		foot;
	
	contenidos["sla"] = 
		head +
		"<th>Los Mochis</th>" +
		"<td>1</td>" +
		foot;
		
	contenidos["tbc"] = 
		head +
		"<th>Villahermosa</th>" +
		"<td>2</td>" +
		foot;
		
	contenidos["vz"] = 
		head +
		"<th>Poza Rica</th>" +
		"<td>4</td>" +
		"</tr></tr>" + 
		"<th>Veracruz</th>" +
		"<td>1</td>" +
		foot;
	
	contenidos["ytn"] = 
		head +
		"<th>Mérida</th>" +
		"<td>2</td>" +		
		foot;
		
	return contenidos[id]; 
}

Event.observe(document,"mousemove",function(e){
	var elemento = Event.element(e);
	if (!$$(".bkgr")[0]) {
		return;
	}
	var regiones = $$(".region");
	regiones.each(function(region){
		region.hide();
	});
	if (elemento.className != "estado") {
		return;
	}
	var idEstado = elemento.id;
	var aux = idEstado.substring(0,1);
	idEstado= aux=="l"?idEstado.substring(1):idEstado;
	$("region-" + idEstado).show();
});

function enviarContacto(formu){
	if (!validarFormulario(formu)) {
		return;
	}
	formu.submit();
}

var time=0;
function cambiarFoto(sentido, total){
	if (time == 1) {
		return;
	}	
	var actual = parseInt($("numFoto").innerHTML);
	var x = 0;
	if (sentido < 0) {
		if (actual == 1) {
			return;
		}
		x = 494;
	}
	if (sentido > 0) {
		if (actual == total) {
			return;
		}
		x = -494;
	}
	time = 1;
	if ((actual + sentido) == 1) {
		$$(".fIzq")[0].addClassName("none");
	}
	else {
		$$(".fIzq")[0].removeClassName("none");
	}
	if ((actual + sentido) == total) {
		$$(".fDer")[0].addClassName("none");
	}
	else {
		$$(".fDer")[0].removeClassName("none");
	}
	var table = $("fotosNoticia");
	$("numFoto").innerHTML = actual + (sentido);
	new Effect.Move(table, {
		x: x,
		y: 0,
		afterFinish: function(){
			time=0;
		}
	});
}

Event.observe(window,"load",function(){
	var total=$F("ttlimgs")
	setTimeout(function(){cambiarPatrocinadores(10,total,1);},1000);
});

function cambiarPatrocinadores(imagen, total,inicio){	
	if(total<=9){
		return;
	}
	if(!$("imgPt_" + imagen)){
		imagen=1;
		inicio=1;
	}
	inicio = inicio>9?1:inicio;	
	$("imgPt_" + imagen).appear();	
	$$(".cte_activo_"+inicio)[0].fade({
		afterFinish: function(){
			setTimeout(function(){cambiarPatrocinadores(parseInt(imagen + 1),total,inicio+1);},1000);							
			$$(".cte_activo_"+inicio)[0].removeClassName("cte_activo_"+inicio);
			$("imgPt_" + imagen).addClassName("cte_activo_"+inicio);	
		}
	});
}

function postularVacante(vacante,informacion){
	if(!confirm("¿Esta seguro que desea aplicar a esta vacante?")){
		return;
	}
	var direccion="/php/codes/scripts.php";	
	var parametros="action=postularVacante&vacante=" + vacante + "&info=" + informacion;	
	var funcion=function(resp)
	{
		var res=resp.responseText.trim();
		if(res=="error"){
			alert("Ya estas postulado para esta vacante");
			return;
		}
		$("msgRes").show();			
	}
	new Ajax.Request(direccion,{method:'post',parameters:parametros,onSuccess:funcion});
}
///*****////

/*Event.observe(window,"load",function(){
	var certificaciones=$("certificaciones");
	if(!certificaciones)
	{
		return;
	}
	var logos=certificaciones.select(".certificacion");
	if(logos.length<=1)
	{
		return;
	}
	var slide=function(callback)
	{
		var item=certificaciones.down(".certificacion");
		new Effect.Move(item,{y:0,x:-255});
		new Effect.Fade(item,{duration:.5,afterFinish:function(){
			var lista=certificaciones.down(".listaCertificaciones");
			logos.invoke("setStyle",{left:'auto'});			
			lista.insert({bottom:item});			
			item.show();						
			if(callback!=null)
			{
				callback();
			}
		}});
	}
	var autoslide=function()
	{
		var ciclo=function()
		{
			setTimeout(function(){slide(autoslide)},5000);
		}
		ciclo();
	}
	autoslide();
});

function slides(){
	var certificaciones=$("certificaciones");
	if(!certificaciones)
	{
		return;
	}
	var logos=certificaciones.select(".certificacion");
	if(logos.length<=1)
	{
		return;
	}
	var slide=function(callback)
	{		
		var item=certificaciones.down(".certificacion");
		new Effect.Move(item,{y:0,x:-255});
		new Effect.Fade(item,{duration:.5,afterFinish:function(){
			var lista=certificaciones.down(".listaCertificaciones");
			logos.invoke("setStyle",{left:'auto'});			
			lista.insert({bottom:item});			
			item.show();						
			if(callback!=null)
			{
				callback();
			}
		}});
	}
	var autoslide=function()
	{
		var ciclo=function()
		{
			setTimeout(function(){slide(autoslide)},3000);
		}
		ciclo();
	}
	//autoslide();
	slide();
}

Event.observe(window,"load",function(){
	var listaPatrocinadores=$("listaPatrocinadores");
	if(!listaPatrocinadores)
	{
		return;
	}
	var intervalo=3000;
	var animacion=function(){
		var activo=listaPatrocinadores.down(".activo");
		var siguiente=activo.next()?activo.next():listaPatrocinadores.down(".contenedorLogos");
		var tds=siguiente.select(".tablaPrincipalLogos td.tdLogo");
		if(tds.length<12)
		{
			var tablaPrincipal=siguiente.down(".tablaPrincipalLogos");
			for(var i=tds.length;i<12;i++)
			{				
				var trs=tablaPrincipal.select("tr.trLogo");
				var ultimoTr=trs[trs.length-1];
				var td=new Element("td",{'class':'tdLogo'});
				td.insert(new Element("div",{'class':'logo'}));
				if(ultimoTr.select(".tdLogo").length<4)
				{
					ultimoTr.insert(td);
				}
				else
				{
					var nuevoTr=new Element("tr",{'class':'trLogo'});
					nuevoTr.insert(td);
					ultimoTr.insert({after:nuevoTr});
				}
			}
		}
		siguiente.show();
		var logos=activo.select(".logo");
		if(logos.length>0)
		{
			var n=0;
			var fade=function(item)
			{
				new Effect.Fade(item,{duration:.5,dalay:1,afterFinish:function(){
					n++;
					if(n<logos.length)
					{
						fade(logos[n]);
					}				
					else
					{
						activo.hide();
						logos.invoke("show");
						activo.removeClassName("activo");
						siguiente.addClassName("activo");
						setTimeout(function(){animacion()},intervalo);
					}
				}});
			}		
			fade(logos[n]);		
		}
	}
	setTimeout(function(){animacion()},intervalo);
});*/

