/*** 
 Simple jQuery Slideshow Script
 Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
 Modified by Lars Storm (TraceWorks.com)
 ***/

function slideSwitch($clickNextImg, $clickNextInfo) {
    var $activeImg = $('#slideshowImg DIV.active');
    var $activeInfo = $('#slideshowInfo DIV.active');
    if ($activeImg.length == 0) $activeImg = $('#slideshowImg DIV:last');
    if ($activeInfo.length == 0) $activeInfo = $('#activeInfo DIV:last');
    if ($clickNextImg != null && $clickNextInfo != null) {
        var $nextImg = $clickNextImg;
        var $nextInfo = $clickNextInfo;
    }
    else {
        var $nextImg = $activeImg.next().length ? $activeImg.next() : $('#slideshowImg DIV:first');
        var $nextInfo = $activeInfo.next().length ? $activeInfo.next() : $('#slideshowInfo DIV:first');
    }
    $activeImg.addClass('last-active');
    $activeInfo.addClass('last-active');
    $nextImg.addClass('active')
    $activeImg.animate({
        opacity: 0.0
    }, 1000, function () {});
    $nextImg.animate({
        opacity: 1.0
    }, 1000, function () {
        $activeImg.removeClass('active last-active');
    });
    $activeInfo.removeClass('active last-active');
    $activeInfo.find('img').attr('src', 'wp-content/themes/TRW_2010/images/slideshow_pagin_not_selected.png');
    $nextInfo.addClass('active');
    $nextInfo.find('img').attr('src', '/wp-content/themes/TRW_2010/images/slideshow_pagin_selcted.png');
}
$(function () {
    slideshowing = setInterval("slideSwitch()", 6000);
    $('#slideshowImg DIV').css({
        opacity: 0.0
    });
    $('#slideshowImg DIV.active').css({
        opacity: 1.0
    });
    $('#slideshowInfo DIV.active').find('img').attr('src', '/wp-content/themes/TRW_2010/images/slideshow_pagin_selcted.png');
});

function slideSelect($slideID) {
    var $clickNextImg = $('#slideImg_' + $slideID);
    var $clickNextInfo = $('#slideInfo_' + $slideID);
    clearInterval(slideshowing);
    slideshowing = setInterval("slideSwitch()", 6000);
    slideSwitch($clickNextImg, $clickNextInfo);
}
