if(typeof(itemHeightSP) != "undefined")
	this.itemHeight = itemHeightSP;
else
	this.itemHeight = 141;
	
if(typeof(totalHeightSP) != "undefined")
	this.totalHeight = totalHeightSP;
else
	this.totalHeight = 281;
	
Rotator = function (rotatorID) 
{
 if(typeof(displayCount) != "undefined")
  	this.visibleItems=displayCount;
	else
		this.visibleItems = 2;

	this.rotator = document.getElementById(rotatorID);
	this.area = document.getElementById("scrollarea");
	this.items = this.area.getElementsByTagName("div");
	this.total = this.items.length;

	if (this.total < this.visibleItems) return;

	document.getElementById("rotatorup").rotator = this;
	document.getElementById("rotatorup").onclick = function () {this.rotator.manual();this.rotator.down()}
	document.getElementById("rotatorup").onmouseover = function () {this.className = "over";}
	document.getElementById("rotatorup").onmouseout = function () {this.className = "";}

	document.getElementById("rotatordown").rotator = this;
	document.getElementById("rotatordown").onclick = function () {this.rotator.manual();this.rotator.up()}
	document.getElementById("rotatordown").onmouseover = function () {this.className = "over";}
	document.getElementById("rotatordown").onmouseout = function () {this.className = "";}

	var bottomClones = new Array(this.visibleItems);
	var topClones = new Array(this.visibleItems);
	/* Duplicate head and tail of the newsitem list */
	for (var i = 0; i < this.visibleItems; i++) {
		bottomClones[i] = this.items[this.total - 1 - i].cloneNode(true);
		topClones[i] = this.items[i].cloneNode(true);
	}
	/* Grow the list */
	for (var i = 0; i < this.visibleItems; i++) {
		this.area.insertBefore(bottomClones[i], this.items[0]);//items is dynamic, so items[0] always refers to first item
		this.area.appendChild(topClones[i]);
	}

	this.index = 0;
 // this.totalHeight = document.getElementById("newsrotator").style.height;
	//this.area.scrollTop = this.index*141+281;
	//this.scrollUp = new Animator(0, 141, createContextFunction(this, "animateUp"));
	//this.scrollDown = new Animator(0, 141, createContextFunction(this, "animateDown"));
		this.area.scrollTop = this.index*itemHeight+totalHeight;
	this.scrollUp = new Animator(0, itemHeight, createContextFunction(this, "animateUp"));
	this.scrollDown = new Animator(0, itemHeight, createContextFunction(this, "animateDown"));


	this.auto = setTimeout(createContextFunction(this, "automatic"), 1500);
}

Rotator.prototype.automatic = function () 
{
	this.up();
	if (this.restart) clearInterval(this.restart);
	this.restart = null;
	this.auto = setInterval(createContextFunction(this, "up"), 4000);
}
Rotator.prototype.manual = function () {
	if (this.auto) clearInterval(this.auto);
	this.auto = null;
	if (this.restart) clearInterval(this.restart);
	this.restart = setTimeout(createContextFunction(this, "automatic"), 7000);
}
Rotator.prototype.up = function () {
	this.index++;
	if (this.index == this.total) this.index = 0;
	this.scrollUp.start();
}
Rotator.prototype.animateUp = function (value) {
	this.area.scrollTop = (this.index-1)*itemHeight + value + totalHeight;
}
Rotator.prototype.down = function () {
	this.index--;
	if (this.index == -this.visibleItems) this.index = this.total - this.visibleItems;
	this.scrollDown.start();
}
Rotator.prototype.animateDown = function (value) {
	this.area.scrollTop = (this.index+1)*itemHeight - value + totalHeight;
}
function createContextFunction(context, method) {
	return (function(){
		eval("context."+method+"(arguments[0],arguments[1],arguments[2])");
		return false;
    });
}

Animator = function (startValue, endValue, f, t) {
	this.step  = 3;	        //The step by which timer counts from 0 to 100
	this.rate  = 10;	    //The rate in ms at which steps are taken
	this.power = 3;         //The steepness of the animation curve
	this.type  = this.EASEINOUT; //The type of easing

	this.min = startValue;
	this.max = endValue;
	this.animateFunction = f;
	this.terminateFunction = t;

	this.precalc = new Array(100);
	for (var i=0; i <= 100; i++) this.precalc[i] = this.calculate(i);
}
Animator.prototype.NONE      = 0;
Animator.prototype.EASEIN    = 1;
Animator.prototype.EASEOUT   = 2;
Animator.prototype.EASEINOUT = 3;

Animator.prototype.setStep = function (step) {
	this.step = step;
}
Animator.prototype.setRate = function (rate) {
	this.rate = rate;
}
Animator.prototype.setPower = function (power) {
	this.power = power;
	for (var i=0; i <= 100; i++) this.precalc[i] = this.calculate(i);
}
Animator.prototype.setType = function (type) {
	this.type = type;
	for (var i=0; i <= 100; i++) this.precalc[i] = this.calculate(i);
}
Animator.prototype.setAnimateFunction = function (f) {
	this.animateFunction = f;
}
Animator.prototype.start = function () {
	if (this.interval) return;
	this.time = 0;
	this.interval = setInterval(this.createContextFunction("animate"), this.rate);
}
Animator.prototype.stop = function () {
	if (this.interval) clearInterval(this.interval);
	this.interval = null;
}
Animator.prototype.animate = function () {
	if (this.time <= 100) {
		var factor = this.precalc[this.time];
		var result = this.min + factor*(this.max-this.min);
		this.animateFunction(parseInt(result));//log(parseInt(result));
		this.time += this.step;
	} else {
		clearInterval(this.interval);
		this.interval = null;
		if (this.terminateFunction) this.terminateFunction();
	}
}
Animator.prototype.calculate = function (t) {
	t = t/100;
	switch (this.type) {
		case this.NONE      : return this.easeNone(t);
		case this.EASEIN    : return this.easeIn(t);
		case this.EASEOUT   : return this.easeOut(t);
		case this.EASEINOUT : return this.easeInOut(t);
	}
}
Animator.prototype.easeNone = function (t) {
	return t;
}
Animator.prototype.easeIn = function (t) {
	return Math.pow(t,this.power);
}
Animator.prototype.easeOut = function (t) {
	return 1-this.easeIn(1-t);
}
Animator.prototype.easeInOut = function (t) {
	if (t < 0.5) return this.easeIn(t*2)/2;
	return 0.5+this.easeOut((t-0.5)*2)/2;
}
Animator.prototype.createContextFunction = function (method) {
	var context = this;
	return (function(){
		eval("context."+method+"()");
		return false;
    });
}