
//Diapos
function slideSwitch() {
        var $active = $('#slideshow img.active');
    
        if ( $active.length == 0 ) $active = $('#slideshow img:last');
    
        var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');
    
        $active.addClass('last-active');
    
        $active.animate({opacity: 0.0}, 5000, function() {});
        
        $next.css({opacity: 0.0})
                .addClass('active')
                .animate({opacity: 1.0}, 5000, function() {
                    $active.removeClass('active last-active');
                
                
        }); 
}



//DOM cargado
$(document).ready(function(){
    
    //Idioma
    var $idioma = '';
    if( $('#idioma a').attr('href')  == 'index.html'){
    		$idioma='english'
    	}else{
    		$idioma='spanish';
    	}  
    
    //Intérvalo diapos
    setInterval( "slideSwitch()", 5000 );
    
    
    //Tabs
    $("ul.tabs").tabs("div.panes > div",{
        effect:'fade',
        history:'true'
    });
    
    
    //Espose
    $("a[rel]").overlay({expose: '#a2b7a9', color:'#facdef'});      

    //Formulario
	$('#botonEnviar').click(function(e){
	   e.preventDefault();
	   $nombre = $('#nombre');
	   $apellido = $('#apellido');
	   $email = $('#email');
	   $comentario = $('#comentario');
	   
	   /* alert($('#comentario').val()); */
	   
	   if( !($comentario.val() && $email.val() && $apellido.val() && $nombre.val() ) ){
    	   if(!$comentario.val()) $comentario.addClass('error').focus(); else $comentario.removeClass('error');
    	   if(!$email.val()) $email.addClass('error').focus(); else $email.removeClass('error');
    	   if(!$apellido.val()) $apellido.addClass('error').focus(); else $apellido.removeClass('error');
    	   if(!$nombre.val()) $nombre.addClass('error').focus(); else $nombre.removeClass('error');
    	   
    	   if ($idioma == 'spanish'){
    	   		alert('Los campos marcados en amarillo son obligatorios.');
    	   }else{
    	   		alert('Yellow fields are mandatory.');
    	   }
	   }else{
		   	jQuery.get('informacion.php',
		   		{
			   		nombre: $('#nombre').val(),
			   		apellido: $('#apellido').val(),
			   		email: $('#email').val(),
			   		comentario: $('#comentario').val(),
			   		idioma: $idioma
		   		},
		   		function(datos){ 
		   			alert(datos);
		   			$('*').removeClass('error').val('');
		   		 });
	      		   
	   }
	
	});
	
	//Fotos
	$('.panes a img').hover(
		function(e){
			var html = '<div id="info">';
			//html +=	   '<img src="'+$(this).attr('src')+'" alt="image" />';
			html +=    '<h3>'+$(this).attr('id')+'</h3>';
			html +=		'</div>';
							
			$('body').append(html).children('#info').hide().fadeIn(400);
			$('#info').css('top', e.pageY + 10).css('left', e.pageX - 40);
		},
		function(){
			$('#info').remove();
	});
	$('.panes a img').mousemove(function(e) {
		$('#info').css('top', e.pageY + 10).css('left', e.pageX - 40);
	});
	
	
});


