$(document).ready(function() {
	
    //Slideshow
    var delay = 10000;
    var period;
    $numbers = $('.slideshow .numbers li');

    $numbers.click(function(){
        $number = $(this);
        $active = $('.slideshow .numbers .active');
        $photos = $('.slideshow #preview li');
        $new_photo = $photos.eq($number.index());

        $photos.eq($active.index()).fadeTo(1000, 0.0);
        $new_photo.fadeTo(1000, 1.0);
        $('#gallery').text($new_photo.find('img').attr('alt'));

        $numbers.removeClass('active');
        $new_active = $number.addClass('active');
        if (period) {
            clearTimeout(period);
            period = setTimeout(function() {
                active = $new_active.index();
                if (($numbers.length-1) > active) $numbers.eq(active+1).click();
                else $numbers.eq(0).click();
            }, delay);
        }

    });
    
    if ($('.slideshow').length && $('.slideshow .numbers li').size() > 1) {
        period = setTimeout(function() {
            active = $('.slideshow .numbers .active').index();
            if (($numbers.length-1) > active) $numbers.eq(active+1).click();
            else $numbers.eq(0).click();
        }, delay);
    }
    //end slideshow


    $("a.thickbox").fancybox({
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'titlePosition' 	: 'over',
        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
            return (currentArray.length > 1) ? '<span id="fancybox-title-over">Obrázek ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>' : '';
        }


    });



});
