if (window.navigator.userAgent.indexOf ("MSIE") > 0) ie4=true;
else ie4=false;
var step=380;
var total=7;
var layer_width=250;
var startX=50;
var num_visible_layers=3;
var num_left=num_visible_layers;
var num_right=1;
if (ie4)var speed=12;
else	var speed=5;
var directs, cur_direct, coorX_left, coorX_left_left, coorX_right, coorX_right_right, counter, pr=0;
function Move(direct)
{
	if (!pr)
	directs=direct;
	if (direct==1 && !pr)
	{
		cur_direct=direct;
		if (num_right>total) num_right=1; // фиксит переход с последней на первую
		if (num_right!=total) num_left=num_right+1;
		else num_left=1;
		if (num_right-1<=0) num_right_right=total; // невидимый новый слой
		else num_right_right=num_right-1;

		coorX_right=parseInt(document.getElementById("lay"+num_right).style.left);
		coorX_right_right=step*num_visible_layers+startX;

		counter=step;
		pr=setTimeout("MoveLayers()", 100);
	}
	else if (direct==2 && !pr)
	{
		cur_direct=direct;
		if (num_left<1) num_left=total; // фиксит переход с последней на первую
		if (num_left>1)	num_right=num_left-1;
		else num_right=total;
		if (num_left+1>total) num_left_left=1; // невидимый новый слой
		else num_left_left=num_left+(num_visible_layers-2);

		coorX_left=parseInt(document.getElementById("lay"+num_left).style.left);
		coorX_left_left=0-step+startX;

		counter=0;
		pr=setTimeout("MoveLayers()", 100);
	}
}
function MoveLayers()
{
	if (directs==1)
	{
		coorX_right-=speed; coorX_right_right-=speed;
		coorX_left=coorX_right-step;
		num=num_right;
		coorX=coorX_right;
		for (i=0; i<num_visible_layers; i++)
		{
			document.getElementById("lay"+num).style.left=coorX+"px";
			coorX-=step;
			if (num!=total) num+=1;
			else num=1;
		}
		document.getElementById("lay"+num_right_right).style.left=coorX_right_right+"px";
		counter-=speed;
		if (counter>0)	pr=setTimeout("MoveLayers()", 10);
		else
		{
			num_right--;
			if (num_right<=0) num_right=total;
			clearTimeout(pr);
			pr=0;
		}
	}
	else if (directs==2)
	{
		coorX_left+=speed; coorX_left_left+=speed;
		coorX_right=coorX_left+step;
		num=num_left;
		coorX=coorX_left;
		for (i=0; i<num_visible_layers; i++)
		{
			document.getElementById("lay"+num).style.left=coorX+"px";
			coorX+=step;
			if (num>1)	num-=1;
			else num=total;
		}
		document.getElementById("lay"+num_left_left).style.left=coorX_left_left+"px";
		counter+=speed;
		if (counter<step)	pr=setTimeout("MoveLayers()", 10);
		else
		{
			num_left++;
			if (num_left>total) num_left=1;
			clearTimeout(pr);
			pr=0;
		}
	}
}

function getClientWidth()
{
  return document.compatMode=="CSS1Compat" && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function PositionLayers()
{
	width=getClientWidth();
	if (width>1300) width=1300;
	if (width>=1020)
	{
		step=(width-startX-layer_width)/(num_visible_layers-1);
		step=parseInt(step)-startX/2;
	}
	else
	{
		step=330;
	}
	w2=step+startX;
	w3=step*2+startX;
	right_rect=step*2+layer_width+startX;

//	alert(num_left)
	n3=num_left;
	n2=num_left-1;
	n1=num_left-2;
	if (n2<1) n2+=total;
	if (n1<1) n1+=total;
	document.getElementById("portfolio2").style.clip="rect(10px, "+right_rect+"px, 220px, 50px)";
	document.getElementById("lay"+n1).style.left=w3+"px";
	document.getElementById("lay"+n2).style.left=w2+"px";
	document.getElementById("lay"+n3).style.left=startX+"px";
	document.getElementById("menu_inn").style.marginRight="0px";
}

function Send()
{
	re2 = /^\d+$/;
	re3= /([^<)\s]+@\S+\.[^>(\s]+)/;
	if (document.getElementById("name").value=="")
	{
		alert("Prego inserire il vostro cognome, nome!");
		document.getElementById("name").focus();
		return;
	}
	if (!re3.test(document.getElementById("email").value))
	{
		alert("Prego inserire il vostro indirizzo email!");
		document.getElementById("email").focus();
		return;
	}
	if (document.getElementById("message2").value=="")
	{
		alert("Prego messaggio!");
		document.getElementById("message2").focus();
		return;
	}
	if (!re2.test(document.getElementById("checknum").value) || document.getElementById("checknum").value=="")
	{
		alert("Prego codice!");
		document.getElementById("checknum").focus();
		return;
	}

	document.Form.sent.value=1;
	document.Form.submit();
}
