var array_number=2;
var move_div='bird_';
//var foto_array = new Array("images/img_875595_2__.jpg","images/img__707253_2__.jpg");
var started=0;
var array_fots_nr=0;
var oldnumber=0;
var auto_number=2;

function fmod(x, y) {
   var ha = parseInt(x/y);
   return (x-ha*y);
}

function stop_rooling(val)
{
	if(val==1)
	stop_auto=1;
	else
	stop_auto=0;
	go_nonstop();
	array_fots_nr=fmod(array_number, foto_array.length);
}
/*function moveIt_out(currPos,id)
{

<a href="#" style="display:block;width: 161px;  height: 249px;" onMouseOver="stop_rooling(1)" onClick="getit_to_at(1)"></a></div>
<div style="position:relative;width: 161px;  height: 249px; left:-332px; float:left;  z-index:11;"><a href="#######" style="display:block;width:161px;  height: 249px;" onMouseOver="stop_rooling(1)" onClick="getit_to_at(2)"><div style="margin:111px; left:130px;"><img height="27" width="27"  border="0"  src="forward.png" ></div></a></div>


var divPath = document.getElementById(id);
	if (currPos > 0)
	{currPos = currPos - 5;
	divPath.style.left = '-'+currPos+'px';
	setTimeout("moveIt_out(" + currPos + ",'" +id+ "')",10);
	}
	else
	{
	var id_parent=document.getElementById("inside");
	var id_child=document.getElementById(id);
			id_parent.removeChild(id_child);
	}
}*/
function moveIt_in(currPos,id)
{
	if(document.getElementById(id))
	{
		var divPath = document.getElementById(id);
		var x = parseInt(divPath.offsetWidth);
		if (currPos < x)
		{
			started=1;
			currPos = currPos + 5;
			divPath.style.left =currPos+'px';
			setTimeout("moveIt_in(" + currPos + ",'" + id+ "')",10);
		}
		else
			go_nonstop();
	}
}

/*function moveIt_top(currPos,id)
{
var divPath = document.getElementById(id);
var x = parseInt(divPath.offsetWidth);
if (currPos < x)
{currPos = currPos + 5;
divPath.style.left ='-'+ currPos+'px';
setTimeout("moveIt_in(" + currPos + ",'" + id+ "')",10);
}
}
function moveIt_bottom(currPos,id)
{
var divPath = document.getElementById(id);
var x = parseInt(divPath.offsetWidth);
if (currPos < x)
{currPos = currPos + 5;
divPath.style.left ='-'+ currPos+'px';
setTimeout("moveIt_in(" + currPos + ",'" + id+ "')",10);
}

}*/

function move_left(number)
{
	if ((started!=1) && (oldnumber!=number))
	{
		if (array_number==2) array_number=1;
			else array_number=2;
		auto_number++;
		//array_number=fmod(number,2)+1;
		//alert(array_number);
	//	var remove=1;
	//	if (array_number==1) remove=2;
		//++array_number;
		var id =move_div+array_number;
		
			var id_parent=document.getElementById("inside");
			var id_child=document.getElementById(move_div+array_number);
			id_parent.removeChild(id_child);
		//alert(foto_array);
		
			var foto=foto_array[fmod((number-1), foto_array.length)];
			var text ='<div id="bird_'+array_number+'" style="position: relative; top: 0px; left: 0px; width: 332px; height: 249px; float:left; background: url('+foto+') no-repeat center;">&nbsp;</div>';
			document.getElementById("inside").innerHTML=text+document.getElementById("inside").innerHTML;
			document.getElementById(move_div+array_number).style.left="0px";
			
		
	
		var supported = (document.getElementById);
		if (!supported) return;
		var divPath = document.getElementById(id);
		var currPos = parseInt(divPath.style.left);
		var x = parseInt(divPath.offsetWidth);
	
	/*if(currPos==0)
	moveIt_in(0,id);
	else
	moveIt_out(x,id);*/
		moveIt_in(0,id);
		if(array_number==1)
		{
			++array_number;
			var id =move_div+2;
			moveIt_in(0,id);
			array_number--;
		}
		else
		{
			var id =move_div+(array_number-1);
			moveIt_in(0,id);
		}
		oldnumber=number;
	}
}

function go_nonstop()
{	
	started=0;
	if(stop_auto==0)
	{
		setTimeout("move_left(auto_number)",5000);
	}
}


function getit_to_at(sk)
{
	if((array_fots_nr==0)&& (sk==1))
		var foto=foto_array[foto_array.length];
	else if((array_fots_nr==foto_array.length)&& (sk==2))
		var foto=foto_array[0];
	else if(sk==2)
		var foto=foto_array[array_fots_nr+1];
	else if(sk==1)
		var foto=foto_array[array_fots_nr-1];
	alert(foto+'  '+array_fots_nr);
	if(array_number==0)
		var div_s =move_div+'1';
	else
		var div_s =move_div+array_number;
	document.getElementById(div_s).style.backgroundImage = "url(" + foto + ")"; 
	++array_fots_nr;
//foto_array[fmod(array_number, foto_array.length)];
//id.src

}
//window.onload = moveIt('birdy',300);

