var carouselCategory = null;
function mycarousel_itemLoadCallback(carousel, state)
{
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    jQuery.get(
        '/produkt/carousel',
        {
            first: carousel.first,
            last: carousel.last,
            category: carouselCategory
        },
        function(data) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
        },
        'json'
    );
}

function mycarousel_itemAddCallback(carousel, first, last, data)
{
    // Set the size of the carousel
//    console.log(data.total-1);
    carousel.size(parseInt(data.total));
//    console.log(data.images.length);
//    for(var i = 0; i < data.images.length; i++)
    for(var i = 0; i < 7; i++)
    {
       if(data.images[i])
       {
           carousel.add(first + i, mycarousel_getItemHTML(data.images[i]));
       }
       else
       {
           carousel.add(first + i, mycarousel_getItemEmptyHTML());
       }
    }

}

var ImageGallery = {
    loadImage : function(id)
    {
        $('.mainimage a').hide();
        $(id).fadeIn();
    }
}

function mycarousel_getItemEmptyHTML()
{
    return '<div><img src="/images/blank.gif" alt=""/></div><div style="padding-top: 5px;">';
}

function mycarousel_getItemHTML(image)
{
    return '<a href="/produkty/'+image.id+'/'+carouselCategory+'/'+image.category_url+'/'+image.title_url+'"><div><img src="' + image.url + '" alt="" class="image shadow"/></div><div style="padding-top: 5px;">' + image.title + '</a>';
}

jQuery(document).ready(function() {
    jQuery('#productCarousel').jcarousel({
        scroll: 6,
        itemLoadCallback: mycarousel_itemLoadCallback
    });


    var colorBoxOptions = {
        maxWidth: 800,
        maxHeight: 600,
        slideshowStart: 'Rozpocznij pokaz slajdów',
        slideshowStop: 'Zatrzymaj pokaz slajdów',
        current: 'Zdjęcie {current} z {total}',
        previous: 'Poprzednie',
        next: 'Następne',
        close: 'Zamknij',
        title: $(this).attr('title')
    };

    $("a.lb").colorbox(colorBoxOptions);
    //$("a.lb_colors").colorbox(colorBoxOptions);;
    //$("a.lb_projects").colorbox(colorBoxOptions);;


    $('#tabmenu a').click(function(){
        var tab = $(this).attr('href');
        $('#tab1, #tab2, #tab3, #tab4').hide();
        $('#tabmenu a').removeClass('selected');
        $(tab).show();
        $(this).addClass('selected');
        return false;
    });






});

