
var foto_st=5;
var comp=1;
var rs=0;
var dbm=0;
function remove_cild(div)
{
var id_parent=document.getElementById("go_alls");
	var id_child=document.getElementById(div);
	id_parent.removeChild(id_child);
	return true;

}
function add_child()
{
	
}
function remove_insert(op)
{
++rs;
if(op==1)
{
if(document.getElementById("go_6"))
remove_cild('go_6');
if(foto_st==(fotos_array.length))
		foto_st=0;
document.getElementById("go_alls").innerHTML='<div id="go_0" style="width:0px; float:left; margin:7px;"><a id="f_'+rs+'" href="#" onclick="go_fotos(3,this.id);return false;"><img class="galerija_photo" src="'+fotos_array[foto_st]+'" width="100%" border="0" alt=""></a></div>'+document.getElementById("go_alls").innerHTML;
}
else if(op==2)
{
if(document.getElementById("go_0"))
remove_cild('go_0');
	if((foto_st-5)>0)
	var t_f=foto_st-5;
	else
	var t_f=fotos_array.length-(5-foto_st);
document.getElementById("go_alls").innerHTML=document.getElementById("go_alls").innerHTML+'<div id="go_6" style="width:0px; float:left; margin:7px;"><a id="f_'+rs+'" href="#" onclick="go_fotos(3,this.id);return false;"><img class="galerija_photo" src="'+fotos_array[t_f-1]+'" width="100%" border="0" alt=""></a></div>';
}
}
function write_text(sk)
{
if(foto_st-sk<0)
st=fotos_array.length-sk+foto_st;
else
st=foto_st-sk;
document.getElementById("text").innerHTML=fotos_text_array[st];
//alert(document.getElementById("hid").value);//=sk;

}
function auto_start(currPos,op)
{
	if(currPos==0)
	remove_insert(op);
	if(op==1)
	{
	if (currPos < 10)
	{
		++currPos;
		var i = 0;
		while(i<6)
		{
		var divPath = document.getElementById("go_"+i);
		var x = parseInt(divPath.style.width);
			if(i==0)
			divPath.style.width=(x+7)+'px';
			else if(i==1)
			divPath.style.width=(x+3)+'px';
			else if(i==2)
			divPath.style.width=(x+3)+'px';	
			else if(i==3)
			divPath.style.width=(x-3)+'px';			
			else if(i==4 )
			divPath.style.width=(x-3)+'px';
			else if(i==5 )
			divPath.style.width=(x-7)+'px';

		var divPath = document.getElementById("go_"+i);
		var x = parseInt(divPath.style.width);
		//document.getElementById("go_"+i).innerHTML=(x)+'px';
		++i;
		}
		
		
	setTimeout("auto_start(" + currPos + ","+op+")",10);
	}
	else
	{
	//remove_cild("go_5");
	var div="go_5";
	var id_parent=document.getElementById("go_alls");
	var id_child=document.getElementById(div);
	id_parent.removeChild(id_child);
	var i = 5;
		while(i>0)
		{
		--i;
		//alert(document.getElementById("go_"+i).id);
		document.getElementById("go_"+i).id="go_"+(i+1);		
		}
		//alert(fotos_array.length);
		write_text(2);
		if(foto_st==(fotos_array.length))
		foto_st=0;
		else
		++foto_st;		
		if(dbm==1)
		{
		dbm=0;
		auto_start(0,1);		
		}
		else
		comp=1;
		/*document.getElementById("go_alls").innerHTML='<div id="go_0" style="width:0px; float:left;background:#00FF00; margin:10px;"><img src="'+fotos_array[foto_st]+'" width="100%"  ></div>'+document.getElementById("go_alls").innerHTML;*/
		
	}
	}
	else
	{
		if (currPos < 10)
		{
			++currPos;
			var i = 1;
			while(i<7)
			{
			var divPath = document.getElementById("go_"+i);
			var x = parseInt(divPath.style.width);
				if(i==1)
				divPath.style.width=(x-7)+'px';
				else if(i==2)
				divPath.style.width=(x-3)+'px';
				else if(i==3)
				divPath.style.width=(x-3)+'px';	
				else if(i==4)
				divPath.style.width=(x+3)+'px';			
				else if(i==5 )
				divPath.style.width=(x+3)+'px';
				else if(i==6 )
				divPath.style.width=(x+7)+'px';
	
			var divPath = document.getElementById("go_"+i);
			var x = parseInt(divPath.style.width);
			//document.getElementById("go_"+i).innerHTML=(x)+'px'+"go_"+i;
			++i;
			}
			
			
		setTimeout("auto_start(" + currPos + ","+op+")",10);
		}
		else
		{
		//remove_cild("go_5");
		var div="go_1";
		var id_parent=document.getElementById("go_alls");
		var id_child=document.getElementById(div);
		id_parent.removeChild(id_child);
		var i = 1;
			while(i<6)
			{
			++i;
			//alert(document.getElementById("go_"+i).id);
			document.getElementById("go_"+i).id="go_"+(i-1);
			//document.getElementById("go_"+(i-1)).innerHTML="go_"+(i-1);		
			}
			write_text(4);
			//alert(fotos_array.length);
			if(foto_st==0)
			foto_st=fotos_array.length-1;
			else
			--foto_st;
			
			if(dbm==5)
			{
				dbm=0;
				auto_start(0,2);				
			}
			else
			comp=1;	/*document.getElementById("go_alls").innerHTML=document.getElementById("go_alls").innerHTML+'<div id="go_5" style="width:0px; float:left;background:#00FF00; margin:10px;"><img src="'+fotos_array[foto_st]+'" width="100%"  ></div>';*/
			
		}
	
	
	}
	/*else if(fr==0)
	{
	auto_start(0,0.5,1);
	}*/

}
function go_fotos(op,id)
{
if(op==1)
{
	if(comp==0)
	{
	//setTimeout("auto_start(0,"+op+")",100);
	}
	else
	auto_start(0,1);
comp=0; 	
}
else if(op==2)
{
	if(comp==0)
	{
	//setTimeout("auto_start(0,"+op+")",100);
	}
	else
	auto_start(0,2);
comp=0; 	
}
else if(op==3)
{
	var id_parent=document.getElementById(id).parentNode.id;
	//alert(id_parent);
	 //setTimeout("add_child()",50);
	if(comp==1)
	{
	comp=0; 
	if(id_parent=='go_5')
	{
	dbm=5;
	auto_start(0,2);	
	}
	else if(id_parent=='go_4')
	auto_start(0,2);
	else if(id_parent=='go_3')
	{
		comp=1; 
		var sk=document.getElementById("hid").value;
		if(foto_st-sk<0)
		st=fotos_array.length-sk+foto_st;
		else
		st=foto_st-sk;
		//alert(fotos_text_link_array[st]);
		window.open(fotos_text_link_array[st],'','status=0,toolbar=1,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,height=550,width=819');
		//window.location=fotos_text_link_array[st];
	}
	else if(id_parent=='go_2')
	auto_start(0,1);
	else if(id_parent=='go_1')
	{
	dbm=1;
	auto_start(0,1);
	
	}
	}
	
	//alert(id_parent.Child);
	//alert(id);
}

}