//Фаил управления фотоальбомом.

var xmlHttp = false;
var xmlHttp1 = false;
var xmlHttp2 = false;
var xmlHttp3 = false;
var xmlHttp4 = false;
//Проверка AJAX
	/* Создание нового объекта XMLHttpRequest для общения с Web-сервером */
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
	  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	  xmlHttp1 = new ActiveXObject("Msxml2.XMLHTTP");
	  xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
	  xmlHttp3 = new ActiveXObject("Msxml2.XMLHTTP");
	  xmlHttp4 = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");
		xmlHttp4 = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) {
	    xmlHttp = false;	
		xmlHttp1 = false;	
		xmlHttp2 = false;	
		xmlHttp3 = false;
		xmlHttp4 = false;
	  }
	}
	@end @*/

	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
  		xmlHttp = new XMLHttpRequest();
		xmlHttp1 = new XMLHttpRequest();
		xmlHttp2 = new XMLHttpRequest();
		xmlHttp3 = new XMLHttpRequest();
		xmlHttp4 = new XMLHttpRequest();
	}
	if(!xmlHttp)
	{ alert('error');
		
	}





function chage_image(id)
{
	
	if(!xmlHttp)
	{ 
		return;
	}	
	
		
	close_pop_up();
	close_prew();
	div_fon				=	document.getElementById("fon_popup");	
	div_fon.className	=	"fon_popup_on";	
	
	div_fon				=	document.getElementById("popup");	
	div_fon.className	=	"pop_up_on";
	
	div_fon				=	document.getElementById("popup_content");	
	div_fon.className	=	"pop_up_content_on";
	div_fon.innerHTML	=	"<div><a onClick='close_pop_up()'><img src='img/close1.gif' width='20px' height='20px' alt='X' class='close_button_x'></a></div><div class='load_show'><img src='img/loading.gif' width='100px' height='100px' alt='Загрузка' ></div>";
	
	
	path	=	"ajax/show_image.php?id="+id+"&is="+Math.round((Math.random()*10000));
	xmlHttp.open("GET", path, true);
	xmlHttp.onreadystatechange = show_photo;
	xmlHttp.send(null);	
	
	
}


function close_pop_up()
{
	div_fon				=	document.getElementById("popup_content");	
	div_fon.innerHTML	=	" ";
	div_fon.className	=	"popup_off";
	
	div_fon				=	document.getElementById("fon_popup");	
	div_fon.innerHTML	=	" ";
	div_fon.className	=	"popup_off";
	
	
	
	div_fon				=	document.getElementById("popup");	
	div_fon.className	=	"popup_off";
	
	
	
	
}


function show_photo()
{
	var str	=	" ";
	if (xmlHttp.readyState != 4)return;
	if (xmlHttp.status != 200){close_pop_up();return;}
	if(xmlHttp.responseText.length<1){close_pop_up();return;}
	div_fon				=	document.getElementById("popup_content");	
	div_fon.className	=	"pop_up_content_on";
	div_fon.innerHTML	=	xmlHttp.responseText;
	
	
	
	
	
}

function close_prew()
{
var fon_popup	=	document.getElementById('ing_prew');
fon_popup.innerHTML	=	" ";
fon_popup.className	=	"popup_off";
}


function prew_photo(obj,id_p)
{
	
	var fon_popup	=	document.getElementById('ing_prew');
	var photo		=	document.getElementById(obj);
	var coord		=	getElementPosition(obj);
	var x	=	coord['left'];
	var y	=	coord['top'];
	var width	=	coord['width'];
	var height	=	coord['height'];
	fon_popup.className='pop_up_for_img';
	fon_popup.style.left	= (x-5)+"px";	
	fon_popup.style.top		= (y-4)+"px";
	/*fon_popup.style.width	= width+"px";
	fon_popup.style.height	= height+"px";*/
	var	img	=	"<img src='"+photo.src+"' width='"+(width+10)+"' onMouseout='close_prew()' onClick='chage_image(\""+id_p+"\")'>";
	fon_popup.innerHTML	=	img;
	
	
}


function getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}