var oAjaxLoader = new Object();




//=======================================================
// Загружает контене с помощью Ajax
//		Url - адрес, с которого грузится контент
//		ContainerID - ID контаинера, в котором будет находится загруженный элемент 
//			(в момент загрузки прикрывается тенью).
//		SectionID - ID секции, в которой будет находится результат. Если такой нет, создается новая.
//		SecClass - CSS класс для секций (все секции подобного класса будут скрываться после загрузки)
//			Созданная секция тоже будет иметь этот класс.
//		IsScroll - нужно ли прокрутить окно к началу контейнера.
//=======================================================
oAjaxLoader.LoadHtmlWithShadow = function(Url, ContainerID, SectionID, SecClass, IsScroll)
{	var oDivContainer = $('#'+ContainerID);
	
	if(oDivContainer.attr('cur_section')!=SectionID)
		{	oDivContainer.attr('cur_section', SectionID);
			var oDivSec = $('#'+SectionID);
			if(oDivSec.length<=0)
				{	oDivSec = $('<div id="'+SectionID+'" class="'+SecClass+'"></div>');
					oDivSec.appendTo(oDivContainer);
				}
			if(oDivSec.children().length>0)
				this.LoadHtmlWithShadow_show(ContainerID, SectionID, SecClass);
			else
				this.LoadHtmlWithShadow_load(Url, ContainerID, SectionID, SecClass);
		}

	if(IsScroll)
		{	var pos = oDivContainer.position();
			window.scrollTo(pos.left, pos.top);
		}
	
	return false;
}
oAjaxLoader.LoadHtmlWithShadow_load = function(Url, ContainerID, SectionID, SecClass)
{	var oDiv = $('#'+ContainerID);
	
	var oShadow = $('#'+ContainerID+'_shadow');
	if(oShadow.length<=0)
		{	oShadow = $('<div id="'+ContainerID+'_shadow" style="position:absolute;background-color:#000000;opacity:0.4;filter:alpha(opacity=40);display:none;background-repeat:no-repeat;background-position:center center;background-image:url(/upload/pages/wait_gray.gif);">&nbsp;</div>');
			oShadow.appendTo('body');
			var pos = oDiv.position();
			oShadow.css('left', pos.left);
			oShadow.css('top', pos.top);
		}
	oShadow.css('width', oDiv.get(0).offsetWidth);
	oShadow.css('height', oDiv.get(0).offsetHeight);
	oShadow.show();
	
	var oDivSec = $('#'+SectionID);
	oDivSec.load(Url, undefined,
		function(responseText, textStatus, XMLHttpRequest)
			{	if(oDiv.attr('cur_section')==SectionID)
					oAjaxLoader.LoadHtmlWithShadow_show(ContainerID, SectionID, SecClass);
				else
					oShadow.hide();
			}
	);
}
oAjaxLoader.LoadHtmlWithShadow_show = function(ContainerID, SectionID, SecClass)
{	$('#'+ContainerID+'_shadow').hide();
	$('.'+SecClass).hide();
	$('#'+SectionID).show();
}





oAjaxLoader.OpenOrCloseHtmlBlock = function(Url, DivContainerID)
{	var oDiv = $('#'+DivContainerID);
	
	if(oDiv.children().length>0)
		oDiv.attr('IsLoad', 1);
	
	if(oDiv.attr('IsLoad')!=1)
		{	var oDivWait = $('<div style="width:100%;text-align:center;height:80px;padding-top:40px;background-color:#f0f0f0;"><img alt="Wait..." src="/upload/pages/wait.gif" /></div>');
			oDivWait.appendTo(oDiv);
			oDiv.hide().slideDown();
			oDiv.load(Url, undefined,
				function(responseText, textStatus, XMLHttpRequest)
					{	oDiv.attr('IsLoad', 1);
					}
			);
		}
	else
		oDiv.slideToggle();
	
	return false;
}





oAjaxLoader.LoadAndShowPhoto = function(Url, PhotoID, PhotoTitle)
{	// show shadow
	var oDivImg = $('#photo_big_container');
	if(oDivImg.length<=0)
		{	oDivImg = $('<div id="photo_big_container" style="position:fixed;display:none;"><div style="width:100%;height:100%;background-color:#000000;opacity:0.4;filter:alpha(opacity=40);">&nbsp;</div><div id="photo_big_fon" style="position:absolute;background-color:white;border:solid 2px #404040;padding:0px 30px 30px 30px;"><div style="text-align:right;padding:2px 2px 10px 2px;font-size:12px;font-weight:bold;cursor:pointer;cursor:hand;" onclick="oAjaxLoader.LoadAndShowPhoto_hide();">закрыть &nbsp; X</div><div class="photo_big_itm" id="photo_big_wait" style="width:400px;height:200px;text-align:center;padding-top:150px;display:none;"><img alt="Wait..." src="/upload/pages/wait.gif" /></div></div></div>');
			oDivImg.appendTo('body');
			oDivImg.css('left', 0);
			oDivImg.css('top', 0);
		}
	oDivImg.css('width', $(window).width());
	oDivImg.css('height', $(window).height());
	oDivImg.show();

	var oImg = $('#'+PhotoID);
	if(oImg.length>0)
		{	// display image
			oAjaxLoader.LoadAndShowPhoto_show(oImg);
		}
	else
		{	// load image
			this.LoadAndShowPhoto_show($('#photo_big_wait'));
			oImgD = $('<div id="'+PhotoID+'" class="photo_big_itm" style="display:none;" onclick="oAjaxLoader.LoadAndShowPhoto_hide();"></div>');
			oImgD.appendTo($('#photo_big_fon'));
			oImg = $('<img alt="'+PhotoTitle+'" title="'+PhotoTitle+'" src="" />');
			oImg.appendTo(oImgD);
			oImg.load(function() { oAjaxLoader.LoadAndShowPhoto_show(oImgD); });
			oImg.attr('src', Url);
			if(PhotoTitle)
				{	oImgTitle = $('<div class="photo_big_itm-title">'+PhotoTitle+'</div>');
					oImgTitle.appendTo(oImgD);
				}
		}
}
oAjaxLoader.LoadAndShowPhoto_show = function(oImg)
{	if(!$('#photo_big_container').is(':hidden'))
		{	var oImgF = $('#photo_big_fon');
			oImgF.children('.photo_big_itm').hide();
			oImg.show();
			oImgF.css('left', ($(window).width()-oImgF.width())/2);
			oImgF.css('top', ($(window).height()-oImgF.height())/2);
		}
}
oAjaxLoader.LoadAndShowPhoto_hide = function()
{	$('#photo_big_container').hide();
}
