// параметры слайдера с работами

var timerID = null;
var timerRunning = false;
var direction = 'right';
var faster = false;
var selfMoving = false;

function stopMoving() {
	if(timerRunning) {
		clearTimeout(timerID);
		timerRunning = false;
	}
	faster = false;
}

function startMoving() {
	stopMoving();
	Moving();
}

function moveFaster() {
	selfMoving = false;
	faster = true;
}

function moveSlower() {
	selfMoving = false;
	faster = false;
}

function Moving() {

	nowpos = getPosition();

	if (faster) {
		speed = 12;
		timeouter = 10;
	} else {
		speed = 1;
		if (selfMoving) {
			timeouter = 40;
		} else {
			timeouter = 10;
		}
	}
	if (direction == 'right') {
		nowpos = nowpos + speed;
	} else {
		nowpos = nowpos - speed;
	}

	stophere = false;

	if (nowpos < 0) {
		nowpos = 0;
		stophere = true;
	}

	tt = document.getElementById('sectionpicsline').clientWidth - document.getElementById('modelline').clientWidth;

	//alert(nowpos + ":" + tt);
	
	if (nowpos > tt) {
		nowpos = tt;
		stophere = true;
	}

	//alert(nowpos);
	document.getElementById('lent').style.left = "-" + nowpos + "px";

	if (!stophere) {
		timerID = setTimeout("Moving()", timeouter);
		timerRunning = true;
	} else {
		//alert('stophere');
		if (selfMoving) {
			startSelfMoving();
		} else {
			stopMoving();
		}
	}

}

function getPosition() {
	t = document.getElementById('lent');
	re = /(-?\d+)/;
	poss = t.style.left.match(re);
	if (poss == undefined) {
		poss = 0;
	} else {
		poss = poss[0];
	}
	return poss * (-1);
}

function moveLeft() {
	selfMoving = false;
	direction = 'left';
	startMoving();
}

function moveRight() {
	selfMoving = false;
	direction = 'right';
	startMoving();
}

function startSelfMoving() {
	selfMoving = true;
	//alert(getPosition());
	if (getPosition() == 0) {
		direction = 'right';
		startMoving();
	} else {
		direction = 'left';
		startMoving();
	}
	
}