//Todas las funciones han sido creadas por
//Enrique Oropeza Poppe utilizando la libreria
//jquery, 
//-------------enrique_oropeza@sendavisual.com---------------
$(document).ready(function() { 
   // Muestra y oculta los menús 
   $('ul li:has(ul)').hover( 
      function(e) 
      { 
         $(this).find('ul').css({display: "block"}); 
      }, 
      function(e) 
      { 
         $(this).find('ul').css({display: "none"}); 
      } 
   ); 
   slideShow(); 
}); 
//galeria
function slideShow() {  
  
    //Set the opacity of all images to 0  
    $('#gallery a').css({opacity: 0.0});  
      
    //Get the first image and display it (set it to full opacity)  
    $('#gallery a:first').css({opacity: 1.0});  
      
     
      
    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds  
    setInterval('gallery()',6000);  
      
}  
  
function gallery() {  
      
    //if no IMGs have the show class, grab the first image  
    var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));  
  
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image  
    var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));     
      
      
      
    //Set the fade in effect for the next image, show class has higher z-index  
    next.css({opacity: 0.0})  
    .addClass('show')  
    .animate({opacity: 1.0}, 1000);  
  
    //Hide the current image  
    current.animate({opacity: 0.0}, 1000)  
    .removeClass('show');  
      
             
} 
//prepara login para el envio

//carga conenidos en contenido.php
function cargaContenido(pag, contenedor)
{
	$.ajax({
           async:true,
           type: "GET",
           dataType: "html",
           url:"../paginas/"+pag,
           beforeSend:cargando($("#"+contenedor+"")),
           success:function(data) {
						$("#"+contenedor+"").html(data);						
  					},
           timeout:4000,
           error:function() {
						$("#"+contenedor+"").html("error al cargar la pagina, porfavor intentelo de nuevo");						
  					}
         }); 
	return false;
}
function borraContenido(contenedor)
{
	$("#"+contenedor+"").html("&nbsp;");						
}
function eliminaContenido(pagina,id,retorno)
{
	if(confirm("Esta seguro de borrar este elemento?"))
		location.href=pagina+"?id="+id+"&re="+retorno;
}
//cargador
function cargando(objeto)
{
	$(objeto).html("<img src='../imagenes/cargando.gif'>");	
}

//comprueba mail
function validaMail(mail)
{
	m=$(mail).attr("value");
	if(m.match(/^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,4}$/i))
	{
		$("#comprobacion_mail").text(" ");
		return true;
	}
	else
		$("#comprobacion_mail").html("<span class='error'>direcci&oacute;n no valida</span>");
}
//Enviar formulario de registro
function validaFormContacto()
{
	return false;
	/*if($("#nombre")!="" && $("#apellido")!="" && $("#ciudad")!="" && $("#pais")!="" && $("#asunto")!="" && $("#mensaje")!="" && validaMail($("#email")))
		$("#form_registro").submit;
	else {
		return false;
	}*/
}
//contraer paneles
function reducePanel(panel,boton)
{
	var x=$("#"+panel+"");
	var y=$('#'+boton+'');
	if(y.text()=="-")
	{
		y.text("+");
		x.slideUp();
	}
	else
	{
		y.text("-");
		x.slideDown();
	}
}
function muestra(objeto)
{
	$("#"+objeto+"").show();
}
function oculta(objeto)
{
	$("#"+objeto+"").hide();
}
function nuevaImagen(){
	var id_galeria=$("#idg").attr("value");
	$("#ima").append('<iframe src="formImagen.php?folder=galeria&id='+id_galeria+'" width="100%" height="45"   scrolling="no" frameborder="0"></iframe><hr>');
}
function eliminarFoto(id){
	$.ajax({
           async:true,
           type: "GET",
           dataType: "html",
           url:"delete_foto.php?id="+id,
           beforeSend:eliminando($("#eliminach"+id+"")),
           success:function(data) {
						$("#imach"+id+"").html(data);						
  					},
           timeout:4000,
           error:function() {
						$("#imach"+id+"").html("error al eliminar la imagen");						
  					}
         }); 
}
function eliminando(objeto){
	objeto.attr("disabled","disabled");
	objeto.attr("value","eliminando...");
}
