var scrolls = new Array();
var hdleft;
var hdleft2;
var hdright;
var hdright2;

var steps = new Array(2,3,4,5,6,7,8,10,11,14,16,16,16,16,16,20,20,16,13,11,9,7,4,2);
var stepindex = 0;
var const_interval = 30;
var global_interval;
var global_timeout;
var global_direction = -1;
var global_direction_next = -1;
var const_pause_standard = 3000;
var global_pause_next = const_pause_standard;
var global_posy = 0;
var global_width = 252;
var global_screenmid;
// Anzahl der Bilder hier aendern:
var global_picscount = 11;
var global_picsshow = 5;
var global_stop = 0;

function init() {
	
	global_screenmid = browser.innerWidth() / 2;
	
	maxshow = Math.floor((browser.innerWidth()-(2*0))/global_width);
	if((maxshow)>global_picsshow) global_picsshow = Math.min(maxshow,(global_picscount-1));
	global_screenleft = global_screenmid - global_width*((global_picsshow)/2);
	global_screenright = global_screenmid + global_width*((global_picsshow)/2);
	
	hdleft = new divobj("hdleft"+(browser.ms?"ms":"ns"),Math.floor(global_width/2),134);
	hdleft2 = new divobj("hdleft2",global_width,134);
	hdright = new divobj("hdright"+(browser.ms?"ms":"ns"),Math.floor(global_width/2),134);
	hdright2 = new divobj("hdright2",global_width,134);
	
	hdleft.moveto(global_screenleft,global_posy);
	hdleft2.moveto(global_screenleft-global_width,global_posy);
	hdright.moveto(global_screenright-hdright.width,global_posy);
	hdright2.moveto(global_screenright,global_posy);
	
	hdleft.show();
	hdleft2.show();
	hdright.show();
	hdright2.show();
	
	hdsc = new divobj("sc",0,0);
	hdsc.moveto(0,258);
	
	for(i=0;i<global_picscount;i++) {
		scrolls[i] = new divobj("sc"+i,global_width,134);
		scrolls[i].moveto(global_screenleft+scrolls[i].width*i,global_posy);
		scrolls[i].show();
	}
	
	global_interval = "";
	global_timeout = "";
	global_timeout = window.setTimeout("start()",1000);
}

function pause() {
	window.clearInterval(global_interval);
	global_interval = "";
	window.clearTimeout(global_timeout);
	global_timeout = window.setTimeout("start()",global_pause_next);
}

function start() {
	window.clearInterval(global_interval);
	global_direction = global_direction_next;
	if(global_interval=="") global_interval = window.setInterval("scrolling()",const_interval);
}

function moveleftstart() {
	global_direction_next = 1;
	global_pause_next = 50;
	if(global_interval=="") pause();
}
function moveleftstop() {
	global_pause_next = const_pause_standard;
}

function moverightstart() {
	global_direction_next = -1;
	global_pause_next = 50;
	if(global_interval=="") pause();
}
function moverightstop() {
	global_pause_next = const_pause_standard;
}

function movestop() {
	global_stop = 1;
}

function movestart() {
	global_stop = 0;
}

function scrolling() {
	if(stepindex==0 && global_stop>0) return;
	if(stepindex>=steps.length) {
		stepindex=0;
		pause();
	} else {
		for(i=0;i<scrolls.length;i++) {
			scrolls[i].moveby(global_direction*steps[stepindex],0);
			//if(scrolls[i].posx()<100) scrolls[i].setstyle("filter","Alpha(opacity="+scrolls[i].posx()+", finishopacity=100, style=1)")
		}
		stepindex = stepindex + 1;
	}
	
	for(i=0;i<scrolls.length;i++) {
		if(global_direction<0 && scrolls[i].posx()+scrolls[i].width<global_screenleft) scrolls[i].moveby(scrolls[i].width*scrolls.length,0);
		if(global_direction>0 && scrolls[i].posx()>global_screenright) scrolls[i].moveby(-scrolls[i].width*scrolls.length,0);
	}
}
