﻿var movingimg;
var movingimgsave;
var movingwindowsize;
var movingsavedate;
var movingdiv;
var movingimgwidth = new Array();
var movingcur = 0;
function moving() {
	movingdiv = document.getElementById("movingwindow");
	movingimg = new Array();
	movingimgsave = movingdiv.getElementsByTagName("img");
	movingwindowsize = movingdiv.offsetWidth;
	for (var i = 0; i < movingimgsave.length; i++) {
		movingimgsave[i].onmouseover = showinfo;
		movingimgsave[i].onmouseout = hideinfo;
		if (movingcur <= movingwindowsize) {
			movingimg[i] = movingimgsave[i];
			movingimgwidth[i] = movingimg[i].width;
			movingimg[i].style.left = movingcur + 'px';
			movingcur += movingimgwidth[i];
			if (movingcur > movingwindowsize) {
				movingsavedate = i;
			}
		}
	}
	movingcur = movingsavedate;

	moving = function() {

		movingsavedate = new Date();
		if (movingstep < timestepmax) {
			for (i = 0; i < movingimg.length; i++) {
				var e = movingimg[i].style;
				if (e.left == '') e.left = '0';
				e.left = (parseFloat(e.left) - step) + 'px';
			}
			if ((parseFloat(movingimg[0].style.left) + movingimgwidth[0]) < -1) // remove first element
			{
				movingimgwidth.splice(0, 1);
				movingimg.splice(0, 1);
			}
			if ((parseFloat(movingimg[movingimg.length - 1].style.left) + movingimgwidth[movingimg.length - 1] - movingwindowsize) < step * 3) // insert new image
			{
				var testmovingcur = movingcur + 1;
				if (testmovingcur == movingimgsave.length) testmovingcur = 0;
				if (movingimg[0] != movingimgsave[testmovingcur]) {
					movingcur = testmovingcur;
					movingimg[movingimg.length] = movingimgsave[movingcur];
					movingimgwidth[movingimgwidth.length] = movingimgsave[movingcur].width;
					movingimgsave[movingcur].style.left = (movingwindowsize + step * 2) + 'px';
				}
			}
		}
		movingstep *= movingtemp;
		if (movingstep < timestep) movingstep = timestep;
		if (movingstep > timestepmax) movingstep = timestepmax;

		var d = new Date();
		var time = movingstep - (d - movingsavedate);
		if (time < 2) time = 2;
		window.setTimeout('moving()', time);
	}
	moving();
}
function getTargetId(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode;
	return targ.getAttribute('infoid');
}

function showinfo(e) {
	document.getElementById("movinginfo" + getTargetId(e)).style.display = 'block';
	movingtemp = movingtempshow;
}

function hideinfo(e) {
	document.getElementById("movinginfo" + getTargetId(e)).style.display = 'none';
	movingtemp = movingtemphide;
}

