var cycle_opts = {
    fx:     'fade',
    speed:   1000,
    timeout: 5000,
    pause:   1,
    pager:  '#thumbNav',
    next:   '#next',
    prev:   '#prev',
    before: onBeforeCycle,
    after:  onAfterCycle
};

$(document).ready(function(){
    $('a.prettyphoto').prettyPhoto({
        theme: 'light_square'
    })
    $('.slider-wrapper')
    .find('#prev')
    .after('<div id="thumbNav">')

    $('.slider')
    .cycle(cycle_opts);

});


function onBeforeCycle() {
    if($('#slide-output').is(":visible")){
        $('#slide-output').fadeOut(500);
    }
}
function onAfterCycle() {
    $('#slide-output').html('<p>'+$(this).find('img').attr('alt')+'</p>').fadeIn(500);
    showPhotos()
}

function showPhotos(){
    $(".slider a").prettyPhoto({
        theme: 'light_square',
        changepicturecallback: pauseCycle,
        callback: resumeCycle
    });
}
function pauseCycle(){
     $('.slider').cycle('pause');
}
function resumeCycle(){
     $('.slider').cycle('resume');
}

