var currImg = '';

function prevNext() {
    var alt = $('#playpause img').attr('alt');
    if (alt == "Pause") slidePause();
}

function slidePause() {
    $('#slideshow_content').cycle('pause');
    $('#playpause').html('<img src="/images/nav_play.gif" alt="Play" />');
}

function slidePlay() {
    $('#slideshow_content').cycle('resume');
    $('#playpause').html('<img src="/images/nav_pause.gif" alt="Pause" />');
}

function onAfter() {
    currImg = this.src;
}

var slideZoom = function() {
    if (currImg == '') return;
    
    // Get _large version of this image
    var len = currImg.length;
    //var ext = currImg.substr(len-4);
    var next = currImg.substr(0,len-4);
    var img = next+'_large.jpg';
    
    window.open(img,'slideshow_zoom','width=800,height=600');
}

$(function() {
    $('#slideshow_content').cycle({
        fx:    'scrollHorz',
        speed:  'slow',
        timeout: 3500,
        next:   '#next',
        prev:   '#prev',
        prevNextClick: prevNext,
        after:   onAfter
    });
    
    $('#slideshow_content').click(slideZoom);
    $('#slideshow_content').cycle('resume');
    
    $('#playpause').click(function() {
        var alt = $('#playpause img').attr('alt');
        if (alt == "Pause") slidePause();
        else if (alt == "Play") slidePlay();
    });
    
    $('#zoom').click(slideZoom);
});