/*
	Versión 1.0
*/
/* ELEMENTOS COMUNES */
// Enlace en ventana nueva.
// Quitar el &nbsp; de inputs tipo texto, password y textareas.
$(document).ready( function(){
	// Enlace en ventana nueva.
	$("a[rel='external']").attr("target","_blank");

	// Quitar el &nbsp; de inputs tipo texto, password y textareas.
	$("input[type='text'], input[type='password'], textarea").focus( function() {
		if (($(this).attr("value")) && ($(this).attr("value").charCodeAt(0) == 32 || $(this).attr("value").charCodeAt(0) == 160) && ($(this).attr("value").length == 1)) {
			this.value = "";
			return false;
		}
	});
});

// Resaltar input(text-password)/textarea seleccionado
$(document).ready(function(){
	$("input[type='text'], input[type='password'], textarea").focus( function() {
		if ($(this).attr("readonly")) {
			// Nada
		} else {
			$(this).addClass("enfocado");
		}
		return false;
	});
	$("input[type='text'], input[type='password'], textarea").blur( function() {
		$(this).removeClass("enfocado");
	});
	$("input[type='text'], input[type='password'], textarea").each( function() {
		if ($(this).attr("readonly")) {
			$(this).addClass("solo_lectura");
		}
	});
});

// Enviar formulario
$(document).ready(function(){
	$("a.enviar_formulario").click(function(){
		$(this).parents("form:first").submit();
		return false;
	});
});

// Imprimir página
$(document).ready(function(){
	$("a.imprimir").click( function() {
		window.print();
		return false;
	});
});
/*
	ESPECÍFICOS
*/
// Menú principal
$(document).ready(function(){

/*   INSTRUCCIONES PARA REPRESENTAR LOS ESTADOS OVER/OUT   */

	var primerNivel = $("#menuPrincipal ul.menu > li");

	var representarHover = function(item, index){
		item.children("a").css({"background-color" : "#96776A"});
	}
	
	var representarOut = function(item, index){
		item.children("a").css({"background-color" : "#000000"});
	}
	
	primerNivel.map(function(index){
		$(this).hover(
			function(){
				representarHover($(this), index);
			},
			function(){
				representarOut($(this), index);
			}
		);
		
	});
/*
	$("#menuPrincipal ul.menu > li:last a").hover(
		function(){
			$("#menuPrincipal").css({"background-color":"#96776A"});
		},
		function(){
			$("#menuPrincipal").css({"background-color":"#000000"});
		}
	);
*/
	
	$("#menuPrincipal ul.menu > li a[href='#']").click(function(event){
		event.preventDefault();
	});

	// Comportamiento para el ratón
	$("ul.menu li.parent").mouseover( function() {
		$(this).find("ul").css("left","0px");
	});
	$("ul.menu li.parent").mouseout( function() {
		$(this).find("ul").css("left","-10000px");
	});
	// Comportamiento para el teclado
	$("ul.menu li a").focus( function() {
		$("ul.menu li.parent ul").css("left","-10000px")
	});
	$("ul.menu li.parent a").focus( function() {
		$(this).parents("li.parent:first").find("ul").css("left","0px");
	});
	$("ul.menu li.parent li a").focus( function() {
		$(this).parents("li.parent:first").find("ul").css("left","0px");
	});
	$(".repliegaMenuPrincipal").focus( function() {
		$("ul.menu li.parent ul").css("left","-10000px");
	});
});

$(document).ready(function(){
	$("select#otrasWebs").change(function(){
		if($(this).val() == "#"){
			return;
		}
		window.open($(this).val(),'_blank');
	});
});
