
var PosWinY;



Gallery = {
	listing : function(block_id, page)
	{
		if(!page)
			page = 0;
		if(!block_id)
			this.errors("No Block!");
		else
		{
			Gallery.StartLoading();
			new Ajax.Request('/ajax.php', {method: 'post', parameters:'C='+page+'&news=' + block_id, onSuccess:Gallery.processGetPost, onFailure:Gallery.ErrorView});

		}

	},

	processGetPost : function(req)
	{
		var i;
		if($('gallery_place'))
			i = $('gallery_place');

		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading();
	},

	StartLoading : function()
	{
		if($('Loading'))
			Gallery.EndLoading();
		var d = document.createElement("div");
		d.setAttribute("id", "Loading");
		d.className = "Loading";
		d.style.left = document.body.scrollWidth / 2 + 50 + "px";
		if(PosWinY)
			d.style.top = PosWinY + "px";
		else
			d.style.top = document.body.scrollTop + (document.body.clientHeight / 2) -100 + "px";

		var text = document.createTextNode("Завантаження...");
		d.appendChild(text);

		document.body.appendChild(d);
		document.body.style.cursor = "wait";
	},
	EndLoading : function()
	{
		if($('Loading'))
		{
			var d = $("Loading");
			document.body.removeChild(d);
			document.body.style.cursor = "default";
		}
	},
	errors : function(s)
	{
		alert(s);
	},
	ErrorView : function(t)
	{
		alert('Ошибка: ' + t.status + ' -- ' + t.statusText);
	},
	PosWin : function(e)
	{
		PosWinY = Event.pointerY(e) - 50;
	}
}
