$(document).ready(function(){
    var height = $('#kategorijos').height()+38;
    $('#bottom').height(height);
    $('#akcijos a.button, #skaiciuokle a.button').css('padding-top', height);
	
    $('#marquee div').marquee('pointer').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    });
    $('#cats a').mouseenter(function(){
        $(this).parent().parent().addClass('hover');
    }).mouseleave(function(){
        $(this).parent().parent().removeClass('hover');
    });
    $('#akcijos a.button').click(function(e){
        e.preventDefault();
        var height = 464;
        $('#bottom').height(height);
        $('#akcijos a.button, #skaiciuokle a.button').css('padding-top', height);
        $('#akcijos').removeAttr('style').css('right',85);
        $('#skaiciuokle .vidus, #kategorijos, #akcijos a.button').hide();
        $('#akcijos .vidus, #skaiciuokle a.button, #akcijos .kategorijos-btn, #kategorijos-btn').show();
    });
    $('#skaiciuokle a.button').click(function(e){
        e.preventDefault();
        var height = 464;
        $('#bottom').height(height);
        $('#akcijos a.button, #skaiciuokle a.button').css('padding-top', height);
        $('#akcijos').css('left',85);
        $('#akcijos .vidus, #kategorijos, #skaiciuokle a.button').hide();
        $('#skaiciuokle .vidus, #akcijos a.button, #skaiciuokle .kategorijos-btn, #kategorijos-btn').show();

    });
    $('#kategorijos-btn').click(function(e){
        e.preventDefault();
        var height = $('#kategorijos').height()+38;
        $('#bottom').height(height);
        $('#akcijos a.button, #skaiciuokle a.button').css('padding-top', height);
        $('#akcijos, #skaiciuokle').removeAttr('style')
        $('#akcijos .vidus, #skaiciuokle .vidus, #kategorijos-btn').hide();
        $('#akcijos a.button, #skaiciuokle a.button, #kategorijos').show();
    });

//    if (typeof( akc_count ) != 'undefined' && akc_count > 3)
    {
        jQuery("#block_akcijos").jcarousel({
            initCallback: carInitCallback,
            wrap: 'circular',
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null,
            itemLoadCallback: akcija_itemLoadCallback
        });    
    }

//    if (typeof( isp_count ) != 'undefined' && isp_count > 3)
    {
        jQuery("#block_ispardavimai").jcarousel({
            initCallback: carInitCallback,
            wrap: 'circular',
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null,
            itemLoadCallback: ispard_itemLoadCallback
        });  
    }
                  
});

function carInitCallback(carousel) {    
    jQuery('.next').bind('click', function() {
        carousel.next();
        return false;
    }); 
};

function akcija_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.getJSON(
        '/index/async-special',
        {
            first: carousel.first,
            last: carousel.last,
            type: 'akcija'
        },
        function(data) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
        }       
    );
};

function ispard_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.getJSON(
        '/index/async-special',
        {
            first: carousel.first,
            last: carousel.last,
            type: 'ispard'
        },
        function(data) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
        }       
    );
};

function mycarousel_itemAddCallback(carousel, first, last, data)
{
    // Set the size of the carousel
    carousel.size(parseInt(data.total));    
    $.each(data.items, function(i) {
        carousel.add(first + i, data.items[i]);
    });
};
