var	scrollerWidth		=	0;
var	inactiveWidth		=	50;
var	activeWidth		=	0;
var	scrollerOffset		=	0;

var	contentItems		=	18;
var	contentItemWidth	=	40;
var	contentWidth		=	0;
var	contentScrollQuotient	=	1;


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

window.onload = function()
{

	document.getElementById("scroller").onmousemove	= ScrollDiv;

	scrollerWidth		= document.getElementById("scroller").offsetWidth;
	activeWidth		= scrollerWidth - 2 * inactiveWidth; //отношение перемещения курсора относительно фотки
	contentItems		= document.getElementById("scroller").childNodes.length - 2;
	contentWidth		= contentItems * contentItemWidth;
	contentScrollQuotient	= ( contentWidth - scrollerWidth ) / activeWidth;

	scrollerOffset = findPos( scroller )[0];

};
//отвечает за смену картинок
function ScrollDiv(event)
{

	var e = event || window.event;

	var PointerPosition = e.clientX - scrollerOffset;

	if ( PointerPosition < inactiveWidth )
	{
		PointerPosition = inactiveWidth;
	};
	if ( PointerPosition > scrollerWidth - inactiveWidth )
	{
		PointerPosition = scrollerWidth - inactiveWidth;
	};

	PointerPosition -= inactiveWidth;

	document.getElementById( "scroller" ).scrollLeft = PointerPosition * contentScrollQuotient;

};
//выводит текст при смене картинки
function DisplayPhotoTitle(text)
{

	document.getElementById("scrollertext").innerHTML = text;

};

//меняет размер картинки при наведении на нее
function ChangePhotoSize(num, max)
{  var num;
   // document.write("мы выводим num=" + max);
    //размер фотки на которую наведен курсор
    document.getElementById("photo_" + num).style.height="85";
    document.getElementById("photo_" + num).style.width="100";
    //две соседни фотки
    // var num1 = num + 1;
  if(num > 1 && num < max ){
    document.getElementById("photo_" + (num + 1)).style.height="75";
    document.getElementById("photo_" + (num + 1)).style.width="90";
    //  var num12 = num - 1;
    document.getElementById("photo_" + (num - 1)).style.height="75";
    document.getElementById("photo_" + (num - 1)).style.width="90";
  }
    //через одну фотку 
    //  var num2 = num + 2;
  if(num > 2 && num < (max - 1) ){
    document.getElementById("photo_" + (num + 2)).style.height="65";
    document.getElementById("photo_" + (num + 2)).style.width="80";
   //  var num22= num - 2;
    document.getElementById("photo_" + (num - 2)).style.height="65";
    document.getElementById("photo_" + (num - 2)).style.width="80";
    }
    //через две фотки
  var i = 3;
  while (i < 12){
    if(num > i && num < (max - (i - 1)) ){
      document.getElementById("photo_" + (num + i)).style.height="55";
      document.getElementById("photo_" + (num + i)).style.width="70";

      document.getElementById("photo_" + (num - i)).style.height="55";
      document.getElementById("photo_" + (num - i)).style.width="70";
    }
    i++;
  }
}
