function SpectraSlideShow() {
	var activeButton = 0,
		activeSlides = [-1, -1, -1],
		activeSlidesSize = [
			spc_mycarousel_itemList[0].length,
			spc_mycarousel_itemList[1].length,
			spc_mycarousel_itemList[2].length
		],
		timeout = 5000,
		timerName = 'spc-banner-timer',
		carousel = $('#spc-mycarousel'),
		pause = false,
		stopped = false,
		started = false,

	slidesStartShow = function () {
		//var firstButton = $("#spectraSlide0");
		//firstButton.attr('selected', 'true' );
		//firstButton.css('backgroundImage', "url('./img/b_sel.png')");

		start(true);
	},

	mycarousel_getItemHTML = function (item) {
		return '<a href="' + item.href + '"><img src="' + item.src + '" width="700" height="200" /></a>';
	},

	cleanupButtonsState = function () {
		for (var i = 0; i <= 2; i++) {
			var button = $('#spectraSlide' + i);
			button.attr('selected', 'false');
			button.css('backgroundImage', "url('./img/b_def.png')");
		}
	},

	play = function () {
		if (stopped)
			stopped = false;
		activeButton++;
		if (activeButton >= 3)
			activeButton = 0;
		activeSlides[activeButton]++;
		if (activeSlides[activeButton] >= activeSlidesSize[activeButton])
			activeSlides[activeButton] = 0;

		mouseClick($('#spectraSlide' + activeButton));
	},

	start = function (beginning) {
		if (started)
			return;
		started = true;
		if (beginning)
			activeButton = -1;
		if (!pause) {
			play();
			carousel.everyTime(timeout, timerName, play, 0);
		}
	},

	stop = function () {
		if (!stopped) {
			carousel.stopTime(timerName);
			stopped = true;
		}
		if (started)
			started = false;
	},

	execWithTimeout = function (code) {
		setTimeout(code, timeout);
	};

	mouseMove = function (obj) {
		stop();
		if (!pause)
			pause = true;
		if (obj.getAttribute('selected') == 'false')
			obj.style.backgroundImage = "url('./img/b_def_hover.png')"
	};

	mouseLeave = function (obj) {
		if (stopped)
			execWithTimeout('spcSlideShow.start()');
		pause = false;
		if (obj.getAttribute('selected') == 'false')
			obj.style.backgroundImage = "url('./img/b_def.png')"
	};

	mouseClick = function (obj) {
		obj = $(obj);
		if (obj.attr('selected') == 'true')
			return;
		activeButton = obj.attr('slideIndex');
		carousel.fadeOut(500, function () {
			carousel.html(mycarousel_getItemHTML(spc_mycarousel_itemList[activeButton][activeSlides[activeButton]]));
			carousel.fadeIn(500);
		});
		cleanupButtonsState();
		obj.attr('selected', 'true');
		$(obj).css('backgroundImage', "url('./img/b_sel.png')");
	};

	slidesStartShow();

	return {
		mouseMove: mouseMove,
		mouseLeave: mouseLeave,
		mouseClick: mouseClick,
		start: start
	};
}

spcSlideShow = {};

jQuery(document).ready(function () {
	if ($('#spc-mycarousel'))
		spcSlideShow = new SpectraSlideShow();
});
