/////////////////////////////////////////////////////////////////////////////////////////////
// inicio del $(document).ready( function()
$(document).ready( function() {
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// activar las galerias de prettyphoto
//normal
//$("a[rel^='prettyPhoto']").prettyPhoto(); 
//con configuraciones (controlar las comas)
$("a[rel^='prettyPhoto']").prettyPhoto({
  //animationSpeed: 'normal', // fast/slow/normal 
  //padding: 40, // padding for each side of the picture 
  opacity: 0.8 // Value betwee 0 and 1 
  //showTitle: false, // true/false 
  //allowresize: true, // true/false
  //counter_separator_label: '/', // The separator for the gallery counter 1 "of" 2 
  //theme: 'light_rounded', // light_rounded / dark_rounded / light_square / dark_square 
  //callback: function(){}
});
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// acordeones de contenido a mano
// mandan bien el foco en acordeones largos si se cierran de golpe en el caso indicado

var acordeon_abierto = "ninguno";//para recoger el acordeon abierto en todo momento
$(".acordeon_publica").hide();//ocultar todos los acordeones inicialmente

$(".tit_acordeon_publica").hover(function() {//funcion para poner el cursor adecuado en los titulos
 $(this).css("cursor","pointer");		            
});

$(".tit_acordeon_publica").click(function() {//funcion para abrir el que se pinche

 if (acordeon_abierto != "ninguno") {//si hay un acordeon abierto
  if ($(this).attr("id") == acordeon_abierto) {//si es este mismo
   $("#" + acordeon_abierto).next().hide("fast");//lo cierro animando
  } else {//si no es este mismo
   $("#" + acordeon_abierto).next().hide("fast");//lo cierro animando (NO manda bien el foco en acordeones largos)
   //$("#" + acordeon_abierto).next().hide();//o lo cierro de golpe (SI manda bien el foco en acordeones largos)
  }
 };
 
 if ($(this).attr("id") != acordeon_abierto) {//si no es el mismo que acabo de cerrar
  $(this).next().show("slow");//mostrar el acordeon
 } 
 
 if ($(this).attr("id") == acordeon_abierto) {//si he cerrado el que estaba abierto
  acordeon_abierto = "ninguno";//reseteo la variable
 } else {
  acordeon_abierto = $(this).attr("id");//guardo el id del acordeon abierto
 }
 
});
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// mostrar/ocultar politicas de privacidad en los formularios
$(".privacidad").toggle();//ocultar todas inicialmente
$(".bot_privacidad").click(function() {
  $(this).parent().next().slideToggle("normal");
  return false;
} );
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// abrir enlaces de clase 'externo' en ventana nueva 
$(".externo").click(function(){
 this.target = "_blank";
});
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// desactivar el estilo
var estado_estilo = true;
$(".quitar_estilo").click(function(){
	if (estado_estilo) {
    for(i=0;i<document.styleSheets.length;i++) {
      document.styleSheets[i].disabled=true;
      window.location = "#web";
    }
		estado_estilo = false;
	} else {
    for(i=0;i<document.styleSheets.length;i++) {
      document.styleSheets[i].disabled=false;
      window.location = "#web";
    }
		estado_estilo = true;
	}
});
//-------------------------------------------------------------------------------------------



/////////////////////////////////////////////////////////////////////////////////////////////
// animando el logo
$("#enlace_logo").hover(function() {
  $(this).animate({ left: 405 }, 75).animate({ left: 395 }, 50).animate({ left: 405 }, 50).animate({ left: 400 }, 75);
});
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// manejo del texto del input del buscador
var contenido_searchcadena = $("#searchcadena").attr("value");
$("#searchcadena").focus(function() {//al hacer foco 
  if ($(this).attr("value") == contenido_searchcadena) {//si su valor es el inicial
    $(this).attr("value","");//borramos
	}
});

$("#searchcadena").blur(function() {//al quitar foco 
  if ($(this).attr("value") == "") {//si esta vacio
	  $(this).attr("value",contenido_searchcadena);//ponemos el texto inicial
	} 
});
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// acordeon de noticias
var noticia_abierta = "ninguno";//recogera el acordeon abierto en todo momento
if ( $("#noticias .titulo_noticia").size() > 1 ) {//variable en true en caso de que haya solo una noticia
  var solo_una_noticia = false;
} else {
  var solo_una_noticia = true;
}

$("#noticias h3:first").removeClass("abrir_noticia");// modificar el estilo del primer titulo             
$("#noticias h3:first").addClass("desplegada");
$("#noticias .acordeon_noticias").hide();// ocultar todos los acordeones inicialmente
$("#noticias .acordeon_noticias:first").show();// mostrar el primero
noticia_abierta = $("#noticias h3:first").attr("id");// guardar su id			

// interactividad en los titulos
$("#noticias .titulo_noticia").hover(
  function () {
	  if ( !solo_una_noticia ) {//si hay mas de una noticia
      $(this).css("cursor","pointer");
      $(this).addClass("titulo_noticia_over");
		}
  }, 
  function () {
	  if ( !solo_una_noticia ) {//si hay mas de una noticia
      $(this).css("cursor","normal");
      $(this).removeClass("titulo_noticia_over");
		}
  }																 
);
$("#noticias .desplegada").hover(
  function () {
	  if ( !solo_una_noticia ) {//si hay mas de una noticia
      $(this).css("cursor","pointer");
      $(this).addClass("titulo_noticia_over");
		}
  }, 
  function () {
	  if ( !solo_una_noticia ) {//si hay mas de una noticia
      $(this).css("cursor","normal");
      $(this).removeClass("titulo_noticia_over");
		}
  }																 
);

//funcion para abrir el acordeon seleccionado
$("#noticias .titulo_noticia").click(function() {
	if ( !solo_una_noticia ) {//si hay mas de una noticia
	  $("#noticias .titulo_noticia").removeClass("desplegada");// modificar el estilo del titulo          
	  $("#noticias .titulo_noticia").addClass("abrir_noticia");

    if (noticia_abierta != "ninguno") {//si hay un acordeon abierto
      $("#" + noticia_abierta).next().hide("fast");//lo cierro animando
    };
 
    if ($(this).attr("id") != noticia_abierta) {//si no es el mismo que acabo de cerrar
      $(this).next().show("slow");//mostrar el acordeon
      noticia_abierta = $(this).attr("id");//guardo el id del acordeon abierto
		  $(this).removeClass("abrir_noticia");// modificar el estilo del titulo              
	  	$(this).addClass("desplegada");
    }  else {//si es el que acabo de cerrar
      noticia_abierta = "ninguno";//reseteo la variable, no hay ninguno abierto
    }
	//} else {//si solo hay una noticia
    //$(this).next().hide("fast");//cerrar y abrir de seguido
    //$(this).next().show("slow");
	}
});
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// boton de cerrar resultados de busqueda
$(".cerrar_search_results").click(function() {
  $("#search_results").hide("normal");
	return false;
});
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// fin del $(document).ready( function()
} ); 
//-------------------------------------------------------------------------------------------



/////////////////////////////////////////////////////////////////////////////////////////////
// funciones anteriores al Jquery 

// Envia un formulario
function enviar_form(nombreform){
 document.getElementById(nombreform).submit();		
}

// Envia un comentario
function enviar_comentario(){
 document.getElementById('comentario').submit();		
}
//-------------------------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////////////////////////////////
// pruebas




/*
/////////////////////////////////////////////////////////////////////////////////////////////
// acordeones de contenido con toggle
// no mandan bien el foco en acordeones largos
var acordeon_abierto = "ninguno";//para recoger el acordeon abierto en todo momento

$(".acordeon_publica").hide();//ocultar todos los acordeones

$(".tit_acordeon_publica").click(function() {//funcion para abrir el que se pinche

 if (acordeon_abierto != "ninguno") {//si hay un acordeon abierto
  if ($(this).attr("id") != acordeon_abierto) {//y no es el que acabo de pinchar
   $("#" + acordeon_abierto).next().slideToggle("fast");//cierro el que este abierto
   //$("#" + acordeon_abierto).next().toggle();//cierro el que este abierto
  };
 };
 
 $(this).next().slideToggle("fast");//toggle del acordeon
 //$(this).next().toggle();//toggle del acordeon
 
 if ($(this).attr("id") == acordeon_abierto) {//si he cerrado el que estaba abierto
  acordeon_abierto = "ninguno";//reseteo la variable
 } else {
  acordeon_abierto = $(this).attr("id");//guardo el id del acordeon abierto
 }
 
} );
//-------------------------------------------------------------------------------------------
*/

