function CSCarouselManager(startindex, numitems, autoswitchseconds, buttons, nextbutton, buttonimagespath) {
	
	this.autoswitchseconds = autoswitchseconds;
	this.currentindex = startindex;
	this.numItems = numitems;
	this.alerttimerid = 0;
	this.buttons = buttons;
	this.nextbutton = nextbutton;
	this.buttonimagespath = buttonimagespath;

	var manager = this;
	this.buttons.each(function() { 
		$(this).click(function() { manager.activatebutton(manager.buttons.index($(this))); });
	});

	/* Start timer */
	this.startautoswitch = function(intervaltime){
		this.autoswitchseconds = intervaltime;
		this.restarttimer();
	}

	/* Ends and starts the clock */
	this.restarttimer = function() {
		if (this.alerttimerid != 0) {
			clearInterval(this.alerttimerid);
		}
		var manager = this;
		
		this.alerttimerid = setInterval(function() { manager.switchcase(); }, this.autoswitchseconds * 1000);
	}

	this.movepic = function(img,img_src) {
		img.attr('src', img_src);
		this.restarttimer(this);
	}
	
	/* Updates graphics prior to which button/image is pressed/selected. */
	this.activatebutton = function(button_nr) {
		this.currentindex = button_nr;
		for (i = 0; i < this.buttons.length; i++) {
			if (button_nr == i) {
				this.movepic($(this.buttons[i]).find('img'), this.buttonimagespath + (i + 1) + '_active.png');
			}
			else {
				this.movepic($(this.buttons[i]).find('img'), this.buttonimagespath + (i + 1) + '.png');
			}
		}
	}

	/* Event handler to next button */
	this.buttonnextclick = function() {
	if (this.currentindex < (this.carouselsize()-1)) {
			this.activatebutton(this.currentindex+1);
		}
		else {
			this.activatebutton(0);
		}
	}

	/* Event handler to prev button */
	this.buttonprevclick = function() {
		if (this.currentindex != 0)
		{ this.activatebutton(this.currentindex - 1); }
		else
		{ this.activatebutton(this.carouselsize()-1); }
	}

	/* Return number of elements in carousel */
	this.carouselsize = function() {
		var size = this.numItems;
		
		if (size > 5)
			return 5;
		return size;
	}


	/* Activate buttons corresponding to nr of cases in carousel */
	this.showcurrentcases = function() {
		for (i = 0; i < this.buttons.length; i++) {
			if (i < this.carouselsize()) {
				$(this.buttons[i]).show();
			}
			else {
				$(this.buttons[i]).hide();
			}
		}
	}

	this.switchcase = function() {
		this.nextbutton.click();
	}
}









