var pos = 0;
var moving;
var st;
var loadingImg = document.createElement('img');
loadingImg.src= '/i/loading35x35.gif';
loadingImg.style.marginTop="25px";
function Forward()
{
 s = document.getElementById('scroller'); // находим блок scroller
 scroll_range = s.offsetWidth - s.parentNode.offsetWidth; // ширина невидимой части
 pos -= 5;
 if (-pos > scroll_range ) pos = -scroll_range;

 s.style.left = pos + 'px'; 
 moving = window.setTimeout("Forward()", 20)
}

function Back()
{
 s = document.getElementById('scroller'); // находим блок scroller
 scroll_range = s.offsetWidth - s.parentNode.offsetWidth; // ширина невидимой части
 pos += 5;
 if (pos > 0) pos = 0;
 s.style.left = pos + 'px';
 moving = window.setTimeout("Back()", 10)
}
function Stop()
{
 if (moving) clearTimeout(moving);
}


function start_onload()
{
var s = document.getElementById('scroller').getElementsByTagName('img')[0];
if(s.parentNode.offsetLeft == -1) {moving = window.setTimeout("start_onload()", 600)}
else {setScroll()}
}


function setDivWidth()
{
	document.getElementById('slideshow').style.width = 100;
	var dwidth = document.getElementById('directr').getBoundingClientRect().left - document.getElementById('directl').getBoundingClientRect().right;
	//var dwidth = Coordinates.northwestPosition(document.getElementById('directr'), true).x - Coordinates.southeastPosition(document.getElementById('directl'), true).x;
	document.getElementById('slideshow').style.width = dwidth + "px";
return dwidth;
}

function setScroll()
{
var dwidth = setDivWidth();
window.onresize=function() {setDivWidth();widthEx();}
if (moving) clearTimeout(moving);

	var s = document.getElementById('scroller');
	var arr= s.getElementsByTagName('img');

	var no = -1;

	for(var z=0; z < arr.length; z++)
	{
	if (arr[z].parentNode.href == location.href ) {no = z}
	}

	if (no >= 0)
	{
		var ofset = arr[no].parentNode.offsetLeft;
 if (ofset == -1)
		{
		 ofset=arr[no].parentNode.getBoundingClientRect();
		 ofset-=arr[0].parentNode.getBoundingClientRect();
		}
		scroll_range=s.offsetWidth-s.parentNode.offsetWidth;
		pos = (-1 * ofset) + dwidth/2 - arr[no].width/2;
		if (pos > 0) {pos = 0}
		s.style.left = pos + 'px';
	}
s.style.visibility = 'visible';
}


function changeState()
{
  for(var i=0;i<links.length;i+=2){links[i].className=''}
  this.className='active';
  document.getElementById('scroller').innerHTML='';
  document.getElementById('scroller').appendChild(loadingImg);
  if(document.getElementById('moreal')){
  var moreal = document.getElementById('moreal');
  switch(this.childNodes[0].childNodes[0].innerHTML){
  case "Новинки":
  moreal.innerHTML = '<a href="/new.html">Смотреть все новинки</a>';
  break;
  case "Распродажа":
  moreal.innerHTML = '<a href="/sale.html">Смотреть всю распродажу</a>';
  break;
  case "Популярные":
  moreal.innerHTML = '<a href="/popular.html">Смотреть все популярные</a>';
  break;
  case "Оригинальные":
  moreal.innerHTML = '&nbsp;';
  break;
  }}  
  Ajax.Load(document.getElementById('scroller'),'/menu.txt?show='+this.getElementsByTagName('a')[0].getAttribute('module'), 
  function() {pos=0;document.getElementById('scroller').style.left='0';});
  
  return false;
}