/* ----------------------------------- */
/* - SCROLLBOX beta v0.0.0.0.0.1 ;) -- */
/* Copyright 04/2009 Patrick Tschirpke */
/* ---- http://www.tschirpke.net ----- */
/* ----------------------------------- */

var pr = 0;			//internal
var step = 700;		//width of one item (muss durch movestep teilbar sein!!)
var movestep = 25;	//how many pixels each interval? (this sets up the speed of scrolling) //Default: 25
var allitems = 4;		//how many items totally?
var actitem = 1;		//internal
var actpos = 0;		//internal
var interval = 1;		//time of interval
var max = step * (allitems-1);
var x;
var i;
var counter = 0;
var intervals = [];
var running = 0;
var bMoveInProgress = false;

function set_indicator(item) {
	document.getElementById("prev").style.visibility = "visible";
	document.getElementById("next").style.visibility = "visible";

	if(actitem == allitems) { 
		document.getElementById("next").style.visibility = "hidden";
	} else if(actitem == 1) {
		document.getElementById("prev").style.visibility = "hidden";
	}

	for(i = 1; i <= allitems; i++) {
		var itemname = "scroll"+i;
		if(i == item) {
			document.getElementById(itemname).style.background = "url('/gfx/website/indikator.jpg') no-repeat bottom center";
		} else {
			document.getElementById(itemname).style.background = "transparent";
		}
	}
}

function moveto(item) {
	if (bMoveInProgress) return;
	bMoveInProgress = true;
	var diff = item - actitem;
	if(diff < 0) {
		diff = diff * -1;
		pr = pr + (step*diff);
		actitem = item;
		move(pr,1,movestep*diff);
		set_indicator(actitem);
	} else {
		pr = pr - (step*diff);
		actitem = item;
		move(pr,-1,movestep*diff);
		set_indicator(actitem);
	}
}

function fnext() {
	if (bMoveInProgress) return;
	bMoveInProgress = true;
	if(actitem == allitems || running == 1) {
	} else {
		actitem = actitem + 1;
		pr = pr - step;
		move(pr,-1,movestep);
		set_indicator(actitem);
	}
}

function fprev() {
	if (bMoveInProgress) return;
	bMoveInProgress = true;
	if(actitem == 1 || running == 1) {
	} else {
		actitem = actitem - 1;
		pr = pr + step;
		move(pr,1,movestep);
		set_indicator(actitem);
	}
}

function move(to,direction,movestepx) {
	var func = "movebin("+to+","+direction+","+movestepx+")";
	running = 1;
	intervals[counter] = window.setInterval(func,interval);
}

function movebin(to,direction,movestepx) {
	var stophere = 0;
	if (actpos == to || actpos < (max*-1) || actpos > 0) { 
		stophere = 1;
	}
	if(stophere == 1) {
		window.clearInterval(intervals[counter]);
		counter++;
		running = 0;
		bMoveInProgress = false;
	} else {
		actpos = actpos + (movestepx * direction);
		document.getElementById("items").style.marginLeft = actpos + "px";
	}
}
