function mycarousel_resizeImageForCarousel(item) {
	if (item == null) {
		return;
	}
	var container = jQuery(".cover", item).get(0);
	var image =	jQuery('img', container).get(0);
	var resize = function() {
		var containerWidth = jQuery(container).width();
		var containerHeight = jQuery(container).height();
		image.className = image.width / containerWidth > image.height / containerHeight ? 'fitToWidth' : 'fitToHeight';
		var margin = ((containerHeight - image.height) * 100 / containerHeight) / 2; // liczymy dla obrazka juz po przeskalowaniu
		jQuery(image).css({ 'margin-top': margin + '%' });
	}
	resize();
	jQuery(image).load(resize);
}
function pgr_Callback(carousel, item, i, evt, yyy){

	if(evt=='next' && carousel.active<(jQuery(carousel.list).find('li').length-2))carousel.active+=1;
	else if(evt=='prev' && carousel.active>1)carousel.active-=1;
	else carousel.active=1;
	updateActiveItemInfo(carousel, item, i);
	//carousel.toggleActiveItemState();
}
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from az
    // given index who is out of the actual item range.
    //var idx = carousel.index(i, carousel.item.length);
	item = carousel.add(i, carousel.item); 
	mycarousel_resizeImageForCarousel(item);
	switch (state) {
		case 'next':
			carousel.setNextActiveItem();
			break;
		case 'prev':
			carousel.setPrevActiveItem();
			break;
	}
	if (i == carousel.activeItem) {
		carousel.toggleActiveItemState();
		carousel.updateActiveItemInfo();
	}
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
	//carousel.remove(i);
};


function updateActiveItemInfo(carousel, item, i) {
	//jQuery('li.jcarousel-item-placeholder').remove();
	jQuery(carousel.list).find('li').removeClass('hi');
	var all = jQuery(carousel.container).find('li').not('.jcarousel-item-placeholder').length;
	var html=jQuery(carousel.list).find('li:eq('+(carousel.active-1)+')').addClass('hi').find('.no-display').html();
	jQuery('#carousel-info-' + carousel.options.carouselId).html(html);
	jQuery('#carousel-item-nr-' + carousel.options.carouselId).html(carousel.options.labelProduct + ' ' + carousel.active + '/' + all);
}
jQuery.jcarousel.fn.extend({
	active: 1
});
