/*
/* Custom style for external links */

jQuery(document).ready(function() {

// Default to show the first image in the gallery
    $('ul#featured_gal li.gal_thumb:first img.thumbontop').removeClass('unselected');
    $('ul#featured_gal li.gal_thumb:first img.thumbontop').addClass('jsSelected');
    $('ul#featured_gal li.gal_thumb:first ul.gal_under').removeClass('hide');
    $('ul#featured_gal li.gal_thumb:first ul.gal_under').addClass('jsShow-gal_under');
    $('ul#featured_gal li.gal_thumb:first ul.gal_under a').addClass('jsGal_under-li-a');

// Default to show the first image in the big gallery
    $('ul#featured_gal li.gal_thumb:first ul.biggal_under').removeClass('hide');
    $('ul#featured_gal li.gal_thumb:first ul.biggal_under').addClass('jsShow-gal_under');
    $('ul#featured_gal li.gal_thumb:first ul.biggal_under a').addClass('jsGal_under-li-a');

// Allow the end user to select any picture in the gallery
    $('img.thumbontop').click(function() {

        $('ul#featured_gal li.gal_thumb').find('img.jsSelected').removeClass('jsSelected').addClass('unselected');

        $(this).removeClass('unselected');
        $(this).addClass('jsSelected');

        $('ul#featured_gal li.gal_thumb').find('ul.jsShow-gal_under').removeClass('jsShow-gal_under').addClass('hide').find('a').removeClass('jsGal_under-li-a');

        $(this).next().removeClass('hide');
        $(this).next().addClass('jsShow-gal_under');
        $(this).nextAll().find('a').addClass('jsGal_under-li-a');
    });

// Allow the end user to toggle the title and description on and off so they can
// see the gallery better, if they have javascript enabled.
//    $('<span><input type="button" value="hide" class="gal_info"></span>').prependTo('.gal_more');
//
//    $('.gal_info').click(function() {
//        $('.gal_desc').slideToggle('slow');
//        $('.gal_title').slideToggle('slow');
//
//        if ($('.gal_desc').is(':visible')) {
//            $(this).val('hide');
//       } else {
//            $(this).val('info');
//        }
//
//   });

// Slide show
    slideShow();

});

function slideShow() {
    var firstImg = $('ul#featured_gal li.gal_thumb img.jsSelected');
    var currentImg = firstImg;
    var nextImg = currentImg.parent().next().length ? currentImg.parent().next().children('img:first') : currentImg.parent().children('li.gal_thumb:first img.thumbontop');

    currentImg.removeClass('jsSelected').addClass('unselected');
    $('ul#featured_gal li.gal_thumb').find('ul.jsShow-gal_under').removeClass('jsShow-gal_under').addClass('hide').find('a').removeClass('jsGal_under-li-a');

    nextImg.removeClass('unselected').addClass('jsSelected').next().removeClass('hide').addClass('jsShow-gal_under').nextAll().find('a').addClass('jsGal_under-li-a');

  setTimeout(slideShow, 8000);
}
