function initScroller(container, itemList)
{
	function ContentScroller_itemVisibleInCallback(carousel, item, i, state, evt)
	{
		var idx = carousel.index(i, itemList.length);
		carousel.add(i, ContentScroller_getItemHTML(itemList[idx - 1]));
	};
	
	function ContentScroller_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
		carousel.remove(i);
	};
	
	function ContentScroller_getItemHTML(item)
	{
		return item.html;
	};
	
	$(container).jcarousel({
		wrap: "circular",
		scroll: 1,
		itemVisibleInCallback: {onBeforeAnimation: ContentScroller_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: ContentScroller_itemVisibleOutCallback},
		buttonNextEvent: "click",
		buttonPrevEvent: "click"
	});
	
	$(container).each(function(){
		var self = this;
		$(self.carousel.buttonPrev).hover(
			function() {
				self.carousel.startAuto(200, false);
			},
			function() {	
				self.carousel.stopAuto(true);
			}
		);
		$(self.carousel.buttonNext).hover(
			function() {
				self.carousel.startAuto(200, true);
			},
			function() {	
				self.carousel.stopAuto(true);
			}
		);
	});
}

function initScroller2(container, meta)
{
	var itemList = [];
	$(container).children('li').each(function(){
		itemList.push($(this).html());
	});
	
	if(meta && jQuery.browser.msie) {
		var itemWidth = 280; 
		$(container).width((itemList.length * (itemWidth + 3)) + 'px');
		//return;
	}
	
	function ContentScroller_itemVisibleInCallback(carousel, item, i, state, evt)
	{
		var idx = carousel.index(i, itemList.length);
		carousel.add(i, itemList[idx - 1]);
	};
	
	function ContentScroller_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
		carousel.remove(i);
	};
	
	var speed = 200;
	if(container == "#autosalonBlockScroller") speed = 1000;
	$(container).jcarousel({
		wrap: "circular",
		scroll: 1,
		size: null,
		animation: speed,
		itemVisibleInCallback: {onBeforeAnimation: ContentScroller_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: ContentScroller_itemVisibleOutCallback},
		buttonNextEvent: "click",
		buttonPrevEvent: "click"
	});
	
	$(container).each(function(){
		var self = this;
		$(self.carousel.buttonPrev).hover(
			function() {
				self.carousel.startAuto(200, false);
			},
			function() {	
				self.carousel.stopAuto(true);
			}
		);
		$(self.carousel.buttonNext).hover(
			function() {
				self.carousel.startAuto(200, true);
			},
			function() {	
				self.carousel.stopAuto(true);
			}
		);
	});
}

function initScroller_test(container, meta)
{
	time_start_total = new Date();
	DEBUG_LOG += container + ":\n";
	
	// load items
	time_start = new Date();
	var itemList = [];
	$(container).children('li').each(function(){
		itemList.push($(this).html());
	});
	
	now = new Date();
	duration = now.getTime() - time_start.getTime();
	DEBUG_LOG += "load items: " + duration + "\n";
	
	if(meta && jQuery.browser.msie) {
		var itemWidth = 280; 
		$(container).width((itemList.length * (itemWidth + 3)) + 'px');
		//return;
	}
	
	function ContentScroller_itemVisibleInCallback(carousel, item, i, state, evt)
	{
		var idx = carousel.index(i, itemList.length);
		carousel.add(i, itemList[idx - 1]);
	};
	
	function ContentScroller_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
		carousel.remove(i);
	};
	
	// make carousel
	time_start = new Date();
	$(container).jcarousel({
		wrap: "circular",
		scroll: 1,
		size: null,
		itemVisibleInCallback: {onBeforeAnimation: ContentScroller_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: ContentScroller_itemVisibleOutCallback},
		buttonNextEvent: "click",
		buttonPrevEvent: "click"
	});
	
	now = new Date();
	duration = now.getTime() - time_start.getTime();
	DEBUG_LOG += "make carousel: " + duration + "\n";
	
	// add events
	time_start = new Date();
	$(container).each(function(){
		var self = this;
		$(self.carousel.buttonPrev).hover(
			function() {
				self.carousel.startAuto(200, false);
			},
			function() {	
				self.carousel.stopAuto(true);
			}
		);
		$(self.carousel.buttonNext).hover(
			function() {
				self.carousel.startAuto(200, true);
			},
			function() {	
				self.carousel.stopAuto(true);
			}
		);
	});
	now = new Date();
	duration = now.getTime() - time_start.getTime();
	DEBUG_LOG += "add events: " + duration + "\n";
	
	now = new Date();
	duration = now.getTime() - time_start_total.getTime();
	DEBUG_LOG += "total: " + duration + "\n\n";
}
