var objectCarousel=Array();
var getTopCarousel;

function mycarousel_videoLoadCallback(carousel, state)
{
    state = state || '';
    objectCarousel[carousel.options.nameClass] = carousel;
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }


    jQuery.get(
        'php/ajaxvideogallery.php',
        {
            first: carousel.first,
            last: carousel.last,
            type: carousel.options.typeContent
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_galleryLoadCallback(carousel, state)
{
    state = state || '';
    objectCarousel[carousel.options.nameClass] = carousel;
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }


    jQuery.get(
        'php/ajaximagegallery.php',
        {
            first: carousel.first,
            last: carousel.last,
            type: carousel.options.typeContent,
            id: carousel.options.dataID
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('preview', xml).each(function(i) {
        carousel.add(first + i, jQuery(this).text());
    });
};


/* функция подхватывающая прокрутку мыши для плагина Карусель*/

function mouseWheelCarousel(e, d){

     if (d>0){objectCarousel[$(this).attr('name')].prev();}
     if (d<0){objectCarousel[$(this).attr('name')].next();}
     return false;
}

/**
 * Item html creation helper.

function mycarousel_getItemHTML(url)
{
    return '<img src="' + url + '" width="75" height="75" alt="" />';
};   */

jQuery(document).ready(function() {
getTopCarousel=function(){jQuery('#mycarouselTop').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.

        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        typeContent: 'top',
        nameClass: 'top10',
        itemLoadCallback: {onBeforeAnimation: mycarousel_videoLoadCallback}

    });
    }
    getTopCarousel();
   // alert(objectTop.typeContent);

    jQuery('#mycarouselSubject').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.

        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        typeContent: 'subject',
        nameClass: 'subject',
        itemLoadCallback: {onBeforeAnimation: mycarousel_videoLoadCallback}

    });

    jQuery('#mycarouselProgram').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.

        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        typeContent: 'program',
        nameClass: 'program',
        itemLoadCallback: {onBeforeAnimation: mycarousel_videoLoadCallback}

    });

    jQuery('#mycarouselGallery').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.

        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        typeContent: 'gallery',
        nameClass: 'gallery',
        dataID: $('.galleryTitle:first').attr('name'),
        itemLoadCallback: {onBeforeAnimation: mycarousel_galleryLoadCallback}

    });

    $('.galleryTitle').click(function(){

        $('.gallery.tvb').html('<div id="mycarouselGallery" class="jcarousel-skin-tango"><ul></ul></div>');
        var galleryThis = $(this);
        jQuery('#mycarouselGallery').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.

        // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        typeContent: 'gallery',
        nameClass: 'gallery',
        dataID: galleryThis.attr('name'),
        itemLoadCallback: {onBeforeAnimation: mycarousel_galleryLoadCallback}

    });

    });

});


