$(function(){

    hTitle = $('h2').text().replace(' - Rush Project','');

    $( '#linksPhoto dt a' ).click(function(e){
        e.preventDefault();e.stopPropagation();
        
        $( '#linksPhoto dt a' ).removeClass('activePhoto');
        $( '#linksPhoto dd' ).hide();
        $( this ).parent().parent().find('dd').fadeIn('fast');
        $( this ).addClass('activePhoto');

    })

    $( '#linksPhoto dd a' ).click(function(e){
        e.preventDefault();e.stopPropagation();
        
        $( '#linksPhoto dd a' ).removeClass('activePhoto');
        $( this ).addClass('activePhoto');
        
        var
            texto = $( this ).text(),
            pasta = $( this ).text().replace(/[^0-9]+/g,''),    
            qt = $( this ).attr('title').replace(/[^0-9]+/g,'');      

        $("a#prev").css("visibility","hidden");
        $("a#next").css("visibility","visible");
        nav( texto, pasta, qt );

    })
       
    function nav( texto, pasta, qt ){
    
        $( '#imgPhoto' ).html('<img src="http://www.rushproject.com.br/img/fotos/' + pasta + '/img1.jpg" alt="' + texto + '" title="' + texto + '" />');
           
        var
            c = 1,
            t = qt;
        
        $( 'h2' ).html( hTitle + ' - ' + texto + ' <span>(' + hTitle.replace('s','') + ' ' + c + ')</span>');

        $( '#showPhoto span' ).html( '<strong>' + c + '</strong>' + ' de ' + qt );
    
        $( "a#next" ).click(function(e){
            e.preventDefault();e.stopPropagation();
            $(this).css("visibility","visible");
            $("a#prev").css("visibility","visible");
            c = c + 1;
            if(c >= t){ 
                c = t;
                $(this).css("visibility","hidden");
            }
            $( '#showPhoto span' ).html( '<strong>' + c + '</strong>' + ' de ' + qt );
            $( '#imgPhoto' ).html('<img src="../img/fotos/' + pasta + '/img' + c + '.jpg" alt="" />');
            $( 'h2' ).html( hTitle + ' - ' + texto + ' <span>(' + hTitle.replace('s','') + ' ' + c + ')</span>');
        })
        
        $( "a#prev" ).click(function(e){
            e.preventDefault();e.stopPropagation();
            $(this).css("visibility","visible");
            $("a#next").css("visibility","visible");
            c = c - 1;
            if(c <= 1){ 
                c = 1;
                $(this).css("visibility","hidden");
            }
            $( '#showPhoto span' ).html( '<strong>' + c + '</strong>' + ' de ' + qt );
            $( '#imgPhoto' ).html('<img src="../img/fotos/' + pasta + '/img' + c + '.jpg" alt="" />');
            $( 'h2' ).html( hTitle + ' - ' + texto + ' <span>(' + hTitle.replace('s','') + ' ' + c + ')</span>');
        })
    
    }

    // ativa imagem do último show
    //lastImg = $( '#linksPhoto dd a' ).eq(0).text().replace(/[^0-9]+/g,'');
    //$( '#imgPhoto' ).html('<img src="http://www.rushproject.com.br/img/fotos/' + lastImg + '/img1.jpg" alt="" />');
    
    $( '#linksPhoto dt a' ).eq(0).click();
    $( '#linksPhoto dd a' ).eq(0).click();

})