function carousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function carousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, carousel_itemList.length);
    var item = carousel_itemList[idx - 1];
    if(item !== undefined)
    {
        var img = carousel.add(i, carousel_getItemHTML(item));

        img.qtip({
            content: $('.tooltip-text[bannerid="' + item.bannerid + '"]').html(),
            style: {
                name: 'light',

                border: {
                    width: 3,
                    radius: 3
                },
                tip:  {
                    corner: 'topMiddle',
                    size: {
                        y: 10
                    }
                }
            },
            position: {
                corner: {
                    target: 'bottomMiddle',
                    tooltip: 'topMiddle'
                }
            },
            show: {
                delay: 0,
                effect: {
                    type: 'fade',
                    length: 0
                }
            }
        });

        if(item.link !== '' && item.link !== undefined)
        {
            img.css('cursor', 'pointer');
            img.click(function(){
            	var domain = item.link.split(/\/+/g)[1];
            	var arr = domain.split("."); 
                var link = '/carousel/click/banner/' + item.bannerid;
                
            	if('menu.ru' == (arr[arr.length - 2] + '.' + arr[arr.length - 1])) {
            		location.href = link;
            	}
            	else {
            		window.open(link);
            	}
            });
        }
    }
};

function carousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function carousel_getItemHTML(item)
{
    if(item != undefined)
    {
        return '<img src="' + item.url + '" width="' + item.width + '" height="' + item.height + '"/>';
    }
    return null;
};