var x= $(document);
x.ready (inicializarEventos);

function inicializarEventos (){

		$("a[id^='idioma_']").click (cambio_idioma).mouseover (function (){$(this).css ("cursor","pointer");});

		$("a[id^='letra_']").click (cambio_letra).mouseover (function (){$(this).css ("cursor","pointer");});
		
		//$("#menu_desplegable").show();
		$("div[id^='desplegable_']").mouseover(desplegarMenu);
	
		$("#homeMenu").find("div").hover(fondo_naranja2,fondo_normal2);
		//$("#homeMenu").find("div").ready(fondo_normal);

		$("#homeMenuLeft").find("div").hover(fondo_naranja,fondo_normal);
		//$("#homeMenuLeft").find("div").ready(fondo_normal);

		if (parseInt( $("#content").css("height") ) >700){
			$("#sub_content").append("<p style='text-align:center;font-size:1.5em;height:0em'><a href='javascript:subirArriba()' style='text-decoration:none;color:#406E8D;' id='textoPujar'></a></p>")

		$.ajax ({
			async:true,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded;charset=utf-8",
			url:"/funciones/funjquery.php",
			data:"opcion=poner_pujar",
			success: function (valor){
				$("#textoPujar").html(valor);
			},
			timeout: 40000,
			error: problemas
		});

		}
		
		if (parseInt( $("#content").css("height")) < parseInt( parseInt($("#homeMenuLeft").css("height"))+170) ) 
			$("#sub_content").css("height",  parseInt($("#homeMenuLeft").css("height")) - parseInt($("#sub_line").css("height")) - parseInt($("#sup_line").css("height"))*2+(170));

		$("#content").mouseover (function (){$("#menu_desplegable").hide();});
	 

}

function cambio_idioma (){
		
		var cadena= $(this).attr ("id");
		var vector= cadena.split ("_");
		var idioma= vector[1];
		
		$.ajax ({
			async:true,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded;charset=utf-8",
			url:"/funciones/eventos.php",
			data:"opcion=cambiar_idioma&idioma="+idioma,
			success: function (){
				document.location.replace (document.location);
			},
			timeout: 40000,
			error: problemas
		});

		return false;

}
function fondo_naranja (){

	$("div[class*=fondoNaranja]").find(".colorea").removeClass("fondoNaranja").addClass("fondoNormal");

	
	
	$(this).removeClass("fondoNormal");
	$(this).find(".colorea").addClass("fondoNaranja");
	$(this).find ("a").removeClass("fondoNormal");
	$(this).find ("a").addClass("fondoNaranja");
	$(this).find ("a").css("color","#003F69");
	
	
}	


function fondo_naranja2 (){

	$("div[class*=fondoNaranja]").find(".colorea").removeClass("fondoNaranja").addClass("fondoNormal");

	$(this).removeClass("fondoNormal");
	$(this).find(".colorea").addClass("fondoNaranja");
	$(this).find ("a").removeClass("fondoNormal");
	$(this).find ("a").addClass("fondoNaranja");
	
	$(this).find ("a").css("color","#003F69")

	
}	

function fondo_normal2 (){
	$("div[class*=fondoNaranja]").removeClass("fondoNaranja").addClass("fondoNormal");
	
	$(this).removeClass("fondoNaranja");
	$(this).addClass("fondoNormal");
	$(this).find ("a").removeClass("fondoNaranja");
	$(this).find ("a").addClass("fondoNormal");
	$(this).find ("a").css("color","white")
}


function fondo_normal (){

	$("div[class*=fondoNaranja]").removeClass("fondoNaranja").addClass("fondoNormal");
	
	$(this).removeClass("fondoNaranja");
	$(this).addClass("fondoNormal");
	$(this).find ("a").removeClass("fondoNaranja");
	$(this).find ("a").addClass("fondoNormal");
	$(this).find ("a").css("color","white");
}

function desplegarMenu (){

	var posicion= $(this).offset();
	var idx = $(this).attr ("id");
	var arrayId= new Array ();
	
	arrayId= idx.split ("_");
	
	var ide= arrayId[1];

	var contenido= $("#submenu_"+ide).html();
	
	//alert (posicion.top); alert (posicion.left);

	if (contenido.length >35 ){

		$("#cuadro").html (contenido);

		$("#menu_desplegable").css("margin-left",($(this).width()) + (posicion.left));
		$("#menu_desplegable").css("margin-top",(posicion.top - "20") );
		$("#menu_desplegable").show();

	}
	else $("#menu_desplegable").hide();

	
	
}
function problemas (){
	
	alert ("Hubo problemas con el ajax.\nContacte con el administrador.");

}

function cambio_letra (){

		var cadena= $(this).attr ("id");
		var vector= cadena.split ("_");
		var letra= vector[1];
		$.ajax ({
			async:true,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded;charset=utf-8",
			url:"/funciones/eventos.php",
			data:"opcion=cambiar_fuente&tipo="+letra,
			success: function (){
				document.location.replace (document.location);
			},
			timeout: 40000,
			error: problemas
		});

		return false;
}


function subirArriba(){
	

	$('html, body').animate({scrollTop:0}, 'fast');
}
