
var PosWinY;



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

		}
	},
	vote : function(block_id,answer)
	{
		if(!answer)
			answer = 0;
		if(!block_id)
			this.errors("No Block!");
		else
		{
			this.StartLoading();
			new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=vote&block_id=' + block_id + '&answer_key=' + answer, onSuccess:Gallery.processGetVotePost, onFailure:Gallery.ErrorView});

		}
	},
	show_gallery_anons : function(block_id, cat, page)
	{
		if (!cat)
			cat=0;
		if (!page)
			page=0;
		if(!block_id)
			this.errors("No Block!");
		else
		{
			this.StartLoading();
			new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=gallery_anons&block_id=' + block_id + '&cat='+cat + '&pg='+page, onSuccess:Gallery.processGetPost, onFailure:Gallery.ErrorView});
		}
	},
	show_news : function(page)
	{
		if(!page)
			page = 0;
		this.StartLoading1();
		new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=news_anons&cat=' + page, onSuccess:Gallery.processNewsGetPost, onFailure:Gallery.ErrorView});
	},
	processNewsGetPost : function(req)
	{
		var i;
		if($('news_anons'))
			i = $('news_anons');
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading1();
	},
	processGetPost : function(req)
	{
		var i;
		if($('gallery_place'))
			i = $('gallery_place');
		
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading();
	},
	processGetVotePost : function(req)
	{
		var i;
		if($('vote_place'))
			i = $('vote_place');
		
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading();
	},
	StartLoading : function()
	{
		if($('Loading'))
			EndLoading();
		var d = document.createElement("div");
		d.setAttribute("id", "Loading");
		d.className = "Loading";
		d.style.left = document.body.scrollWidth / 2 - 70 + "px";
		if(PosWinY)
			d.style.top = PosWinY + "px";
		else
			d.style.top = document.body.scrollTop + (document.body.clientHeight / 2) - 40 + "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";
		}
	},
	StartLoading1 : function()
	{
		if($('Loading1'))
			EndLoading1();
		var d = document.createElement("div");
		d.setAttribute("id", "Loading1");
		d.className = "Loading1";
		d.style.left = document.body.scrollWidth / 2 - 70 + "px";
		if(PosWinY)
			d.style.top = PosWinY + "px";
		else
			d.style.top = document.body.scrollTop + (document.body.clientHeight / 2) - 40 + "px";

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

		document.body.appendChild(d);
		document.body.style.cursor = "wait";
	},
	EndLoading1 : function()
	{
		if($('Loading1'))
		{
			var d = $("Loading1");
			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;
	}
}
