/*
    Copyright © 2009 - Svenn-Arne Dragly (svenni@dragly.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */
function initShowcase() {
    $('.showcase').cycle({
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        timeout: 0,
        easing: 'easeInBack', // easing supported via the easing plugin
        speed: 500
    });
}
$(document).ready(function() {
    initShowcase();
    $('.showcase').addClass('showcase-style');
    var counter = -1;
    var kids = jQuery.makeArray($('.showcase').children());
    kids.reverse(); // we are appending to the end, so we need to reverse the array to make it look like it is in the HTML
    jQuery.each(kids, function() {
        if(counter > 0) { // the counter is set according to the reversed order
            counter = counter - 1;
        } else {
            counter = $(this).parent().children().length - 1;
        }
        $(this).parent().after('<div class="showbtn ' + $(this).attr("id") + '" num="' + counter + '"></div>'); // append this after the showcase element
    });
    $('.showbtn').click(function() {
        $('.showcase').cycle(Number($(this).attr('num')));
    });
    var enabled = 1;
    $('.disable-showcase').click(function() {
        if(enabled) {
            $('.showcase').cycle({
                fx: 'fade',
                speed: 0,
                timeout: 0
            })
        } else {
            initShowcase();
        }
        enabled = !enabled;
    });
    var numRand = Math.floor(Math.random()*9);
    $('.showcase').cycle(numRand);
});
