Array.prototype.key=function(v){
	for (i=0;i<this.length;i++){
	if (this[i]==v) return i;
	}
	return 0;
}
/**
 * contentslider by steepi
 *
 * used by Re/Media/ContentSlider
 */
function ContentSlider(id, arr) {
	this.mid = id;
    this.items = arr;
	this.active = -1;
	this.animationSpeed = 400;
	this.rotationSpeed = 4000;
	this.isRotating = false;
	this.timer = undefined;

	this.init = function()
	{
		var obj = this;
		$("#"+this.mid+" .controls ul li a").click(function(){
			obj.showContent($(this).parent().attr("class"));
			obj.stopRotation();
			return false;
		}).mouseover(function(){
			obj.showContent($(this).parent().attr("class"));
			//obj.stopRotation();
		});

		this.startRotation();

	};

	this.showContent = function(id)
	{
		var activecls = $("#"+this.mid+" .controls .active").parent().attr("class");
		if(activecls != undefined && activecls != id)
		{
			$("#"+this.mid+" .controls .active").removeClass("active");
			$("#"+activecls).stop(true,true).animate({
			  "opacity": 0
			}, this.animationSpeed ).hide();
		}
		if(activecls != id)
		{
			$("#"+id).stop(true,true).animate({
			  "opacity": 1
			}, this.animationSpeed ).show();

			$("#"+this.mid+" .controls ."+id+" a").addClass("active");
		}
		this.active = this.items.key(id);
	};

	this.showNext = function()
	{
		var next = this.active + 1;
		if(next >= this.items.length)
		{
			next = 0;
		}
		this.active = next;
		this.showContent(this.items[next]);
	};

	this.startRotation = function()
	{
		this.isRotating = true;
		this.rotate();
	};

	this.stopRotation = function()
	{
		this.isRotating = false;
		clearTimeout(this.timer);
	}

	this.rotate = function()
	{
		if(this.isRotating == true)
		{
			var obj = this;
			this.timer = setTimeout(function(){
				obj.rotate();
			}, this.rotationSpeed);
			this.showNext();
		}
	};
}


