/*
 * Home gallery
 */
var lastNum = 1;
var images = 0;
$( function() {
    $('#gallery .image .zoom').prettyPhoto({
        theme: 'dark_square'
    });

    $('.zoomBg').css('opacity', '0.2');

    images = $('.image').each(function(i) {
        $(this).attr('num', i+1);
    }).get().length;

    $('#slider a').each(function(i) {
        $(this).attr('num', i+1);
    }).click(minClick);
    if(images ==1 ) {
        $('#nav ').hide();
    }

    $('#nav .next').click(nextPage);
    $('#nav .prev').click(prevPage);

} );

function nextPage() {
    if( lastNum == images ) {
        showPage( 1 );
    } else {
        showPage( lastNum+1 );
    }
    return false;
}

function prevPage() {
    if( lastNum == 1 ) {
        showPage( images );
    } else {
        showPage( lastNum-1 );
    }
    return false;
}

function minClick() {
    return showPage( $(this).attr('num') );
}
function showPage( num ) {
    num = parseInt(num);
    $('.image[num=' + lastNum + ']').fadeOut();
    $('.image[num=' + num + ']').addClass('.active').fadeIn();
    lastNum = num;
    if( num < 3 ) {
        $('#sliderWrap').animate({top: '0px'});
    } else {
        $('#sliderWrap').animate( {
            top: '-' + ( num == images ? (images-4)*70 : (num-3)*70  ) + 'px'
        } );
    }
    $('#galleryTitle').html( $('.image[num=' + num + '] .title').html() );
    return false;
}

