// JavaScript Document
var current = "";
var next = "";

$(document).ready(function()
{	
	$('#texto-privacidad').hide();
	$('.portafolio-info').hide();
		
	//Ideas pagina inicial	
	$('#idea ul li').hide();		
	current = $('#idea ul li:first-child');
	slideShow();
	
	$('.idea-siguiente').click(function(){
		var padre = $(this).parent();
		padre.animate({ height: 'hide'}, 'fast', 'easeInBack',function(){	
			if(padre.next('li').html())
			{
				padre.next('li').animate({ height: 'show'}, 'slow','easeOutBack',function(){ current = padre.next('li'); });
			}
			else
			{
				$('#idea ul li:first-child').animate({ height: 'show'}, 'slow','easeOutBack',function(){ current = $('#idea ul li:first-child'); });		
			}	
		});

	});
	
	slideShow();
	
	//Secciones portafolio
	$('.portafolio-entrada').hover(function(){
											
		$(this).find('div .portafolio-desc').show();
		$(this).find('div').animate({ height: 'show'}, 'slow','easeOutBack');
	}, function() {
		$(this).find('div .portafolio-desc').hide();
		$(this).find('div').animate({ height: 'hide'}, 'fast','easeOutBack');
	});
	
	$('.proyecto-version-header').click(function(){
		var seccionHeader = $(this);
		var imagenAbrir = seccionHeader.find('img');
                var src = imagenAbrir.attr('src');
		if($(this).next('div .proyecto-version-body').is(':visible'))	
		{
                    $(this).next('div .proyecto-version-body').animate({ height: 'hide'}, 'slow','swing',function()
                     {
                        src = src.replace('proyecto_abierto.png','proyecto_cerrado.png');
                        imagenAbrir.attr('src',src);
                        imagenAbrir.attr('alt','Abrir');
                        imagenAbrir.attr('title','Abrir');
                    });
		}
		else
		{
                    src = src.replace('proyecto_cerrado.png','proyecto_abierto.png');
                    imagenAbrir.attr('src',src);
                    imagenAbrir.attr('alt','Cerrar');
                    imagenAbrir.attr('title','Cerrar');
                    $(this).next('div .proyecto-version-body').animate({ height: 'show'}, 'slow','easeOutElastic');
		}
	});	
	
	//Download proyecto
	$('.proyecto-download').hover(function(){
		$(this).animate({marginTop:'+=10px'});
	},function(){
		$(this).animate({marginTop:'-=10px'});
	});	

        $('a[rel=group]').fancybox({
            'transitionIn'		: 'none',
            'transitionOut'		: 'none',
            'titlePosition' 	: 'over',
            'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
                    //return '<span id="fancybox-title-over">Imagen ' + (currentIndex + 1) + ' de ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                    if(title.length)
                        return '<span id="fancybox-title-over">' + title + '</span>';
                    else
                        return '<span id="fancybox-title-over">Imagen ' + (currentIndex + 1) + ' de ' + currentArray.length + '</span>';
            }
        });
	
	//Texto privacidad formulario contacto
    $("#privacidad").click(function()
    {
        if($("#texto-privacidad").hasClass('visible'))
        {
            $("#texto-privacidad").hide();
        }
        else
        {
            $("#texto-privacidad").show();

        }
        $("#texto-privacidad").toggleClass("visible");
    });

    $('#texto-privacidad div.cerrar').click(function(){
        $('#texto-privacidad').hide();
        $("#texto-privacidad").toggleClass("visible");
    });	
	
	//Tooltips inicio
	$(".col2 img[title]").tooltip();
	$("#portafolio ul li[title]").tooltip({ position: "center right", tipClass:"tooltip-secciones" });

	//Highlighting
	sh_highlightDocument(template_directory + '/lang/', '.js');	

});

function slideShow() 
{ 	

	next = current.next().length ? current.next() : current.parent().children(':first'); 
	
	current.animate({ height: 'hide'}, 'fast', 'easeInBack',function(){	
				next.animate({ height: 'show'}, 'slow','easeOutBack',function(){ current = next; });		
	});	
		
	
	setTimeout(slideShow, 10000);
}
