//Дополнительные функции
(new Image(20,20)).src='/img/lupa.png';
function lupa_over(id){document.getElementById("lupa_"+id).style.display="block"; document.getElementById("black_"+id).style.background="#000000";}
function lupa_out(id){document.getElementById("lupa_"+id).style.display="none"; document.getElementById("black_"+id).style.background="url('/img/0.gif')";}

//********************************************************************//
//*********************  Работа с фотографиями  ***********************//
//********************************************************************//
var this_photo,photos_array=new Array();

//Запрос к предыдущей фотографии
function openphoto_last()
{
	clearTimeout(ViewTimeout);
	document.getElementById("photoimg").src="/img/0.gif";
	for(i=0;i<photos_array.length;i++)
	{
		if(this_photo==photos_array[i] && typeof photos_array[i-1]!='undefined'){open_id=photos_array[i-1]}
		if(this_photo==photos_array[i] && typeof photos_array[i-1]=='undefined'){open_id=photos_array[photos_array.length-1]}
	}
	openphoto(open_id,photos_array)
}

//Запрос к следующей фотографии
function openphoto_next()
{
	clearTimeout(ViewTimeout);
	document.getElementById("photoimg").src="/img/0.gif";
	for(i=0;i<photos_array.length;i++)
	{
		if(this_photo==photos_array[i] && typeof photos_array[i+1]!='undefined'){open_id=photos_array[i+1]}
		if(this_photo==photos_array[i] && typeof photos_array[i+1]=='undefined'){open_id=photos_array[0]}
	}
	openphoto(open_id,photos_array)
}

//Функция определения размеров изображения
function openphoto(id,array)
{
	this_photo=id; photos_array=array;
	LoadAjaxDoc("/ajax/openphoto.js.php?id="+id+"&"+Math.random());
	if(photos_array.length==1)
	{
		document.getElementById("photolast").style.display="none";
		document.getElementById("photonext").style.display="none";
}	}

//Открытие плашки фотографии
function photo_correct(width,height,nottop)
{
	X=(document.body.clientWidth-width-32)/2+document.body.scrollLeft;
	Y=(document.body.clientHeight-height-50)/2+document.body.scrollTop;
	X_window=document.body.clientWidth+document.body.scrollLeft;
	Y_window=document.body.scrollHeight;
	if(Y<document.body.scrollTop){Y=document.body.scrollTop+27;}
	if((Number(Y)+Number(height)+37)>Y_window){Y=Number(Y_window)-Number(height)-77;}
	if(Y_window>32000){document.getElementById("bigdiv").style.filter="";}
	document.getElementById("bigdiv").style.width=X_window+"px";
	document.getElementById("bigdiv").style.height=Y_window+"px";
	document.getElementById("photo").style.left=X+"px";
	if(typeof nottop=='undefined')
	{
		document.getElementById("photo").style.top=Y+"px";
		document.getElementById("photo").style.display="block";
	}
	document.getElementById("photo").style.width=Number(width)+32+"px";
	document.getElementById("photo").style.height=Number(height)+32+"px";
	document.getElementById("photoimg").style.width=width+"px";
	document.getElementById("photoimg").style.height=height+"px";
	ViewTimeout=setTimeout("photo_correct('"+width+"','"+height+"','nottop')",500);
}

//Закрытие плашки фотографии
function closephoto(display)
{
	if(typeof display=='undefined')	{
		document.getElementById("photoimg").src="/img/0.gif";
		setTimeout("closephoto('display')",10);
	}	if(typeof display=='string'){
		document.getElementById("photo").style.display="none";
		document.getElementById("bigdiv").style.display="none";
		clearTimeout(ViewTimeout);
}	}

//*******************************************************************//
//**************************  Движок аякса  ***************************//
//*******************************************************************//
function LoadAjaxDoc(url)
{
    var req=getXmlHttp()  
    req.open('GET',url,true);
    req.onreadystatechange=function()
	{
		if(req.readyState==4)
		{
            if(req.status==200){eval(req.responseText);}
			else{window.alert("Ошибка: не удалось получить данные!");}
	}	}
    req.send(null);
}
function getXmlHttp()
{
	var xmlhttp; try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e)
	{
		try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		catch(E){xmlhttp=false;}
	}
	if(!xmlhttp && typeof XMLHttpRequest!='undefined'){xmlhttp=new XMLHttpRequest();}
	return xmlhttp;
}
