function ImageSlider() {
	//********************************************************************************
	function constructor(dsp, config, items, spacing) {
	//********************************************************************************
		this.itemWidth = 127;
		this.itemHeight = 185;
		if (spacing != null)
			this.itemSpacing = spacing; 
		else
			this.itemSpacing = 20;//-30
		this.slideToDuration = 500;
		
		this.dsp = dsp;
		this.index = config.index;
		this.aniIndex = this.index;
		this.centerIndex = 1;
		this.scaleType = config.scaleType;
		this.items = items;
		
		this.leftDsp = this.dsp.children().eq(0);
		this.itemsDsp = this.dsp.children().eq(1).children().eq(0);
		this.rightDsp = this.dsp.children().eq(2);
		
		for (var i=0; i<this.items.length; i++) {
			// setup item
			var item = this.items[i];
			item.nr = i;
			item.x = i * (this.itemWidth + this.itemSpacing);
			item.y = 0;
			item.width = this.itemWidth;
			item.height = this.itemHeight;
			
			item.dsp = $(document.createElement("div"));
			item.dsp.data("item", item);
			item.dsp.css({ "position":"absolute" });
			item.dsp.bind("click", $.proxy(this.itemDsp_onClick, this));
			item.dsp.append("<img src='"+item.imageUrl+"' class='itemImage' />");
			item.dsp.append("<img src='/img/layout/imageslider_shadow.png' />");
			this.itemsDsp.append(item.dsp);
		}
		
		
		this.leftDsp.bind("click", $.proxy(this.leftDsp_onClick, this));
		this.rightDsp.bind("click", $.proxy(this.rightDsp_onClick, this));
		
		this.updateIndex();
		this.updateAniIndex();
	}
	
	//--------------------------------------------------------------------------------
	this.slideTo = function(toIndex) {
	//--------------------------------------------------------------------------------
		this.index = toIndex;
		this.updateIndex();
		
		$(this).animate({
			aniIndex: this.index
		}, {
			duration: this.slideToDuration,
			step: this.updateAniIndex,
			complete: this.updateAniIndex
		});
	};
	
	//--------------------------------------------------------------------------------
	this.updateIndex = function() {
	//--------------------------------------------------------------------------------
		if (this.index == 0)                   this.leftDsp.hide(); else this.leftDsp.show();
		if (this.index == this.items.length-1) this.rightDsp.hide(); else this.rightDsp.show();
	};
	
	//--------------------------------------------------------------------------------
	this.updateAniIndex = function() {
	//--------------------------------------------------------------------------------
		// item-container
		var itemsX = (this.centerIndex - this.aniIndex) * (this.itemWidth + this.itemSpacing);
		this.itemsDsp.css("left", itemsX);
		// items
		for (var i=0; i<this.items.length; i++) {
			var item = this.items[i];
			item.setScaleByPos(item.nr - this.aniIndex, this.scaleType);
		}
	};
	
	//--------------------------------------------------------------------------------
	this.itemDsp_onClick = function(event) {
	//--------------------------------------------------------------------------------
		var item = $(event.currentTarget).data("item");
		if (item.nr == this.aniIndex) {
			window.open(item.targetUrl);
			// alert(item.targetUrl);
		} else {
			this.slideTo(item.nr);
		}
	};
	
	//--------------------------------------------------------------------------------
	this.leftDsp_onClick = function(event) {
	//--------------------------------------------------------------------------------
		this.slideTo(this.index - 1);
	};
	
	//--------------------------------------------------------------------------------
	this.rightDsp_onClick = function(event) {
	//--------------------------------------------------------------------------------
		this.slideTo(this.index + 1);
	};
	
	constructor.apply(this, arguments);
}

function ImageSliderItem() {
	//********************************************************************************
	function constructor(imageUrl, targetUrl) {
	//********************************************************************************
		this.imageUrl = imageUrl;
		this.targetUrl = targetUrl;
		
		this.nr = null;
		this.dsp = null;
		
		this.x = null;
		this.y = null;
		this.width = null;
		this.height = null;
	}
	
	//--------------------------------------------------------------------------------
	this.setScaleByPos = function(pos, scaleType) {
	//--------------------------------------------------------------------------------
		switch (scaleType) {
			case 0:
				var x = Math.abs(0.75 * pos);
				if (x >= 1) {this.dsp.hide(); return;}
				var scale = Math.sqrt(1 - x*x); // 0..1
				break;
			case 1:
				var x = Math.abs(pos);
				var scale = 1 - 0.35 * x;
				if (scale <= 0) {this.dsp.hide(); return;}
				break;
		}
		
		var scaledWidth = scale * this.width;
		var scaledHeight = scale * this.height;
		var deltaWidth = scaledWidth - this.width;
		var deltaHeight = scaledHeight - this.height;
		
		this.dsp.show();
		this.dsp.css({
			//"opacity": scale,
			"z-index": Math.round(scale * 1000),
			"left": this.x - deltaWidth/2,
			"top": this.y - deltaHeight/2
		});
		this.dsp.children().eq(0).width(scaledWidth);
		this.dsp.children().eq(1).width(scaledWidth+2);
	};
	
	constructor.apply(this, arguments);
}

