
var PosWinY;



Gallery = {
	
	objects_gallery : function(num, adm, object_category_id)
	{
		
		if(!num)
			num = 0;
		Gallery.StartLoading();
		new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=objects_gallery&num='+num+'&adm='+adm+'&object_category_id='+object_category_id, onSuccess:Gallery.processObjectGallery, onFailure:Gallery.ErrorView});
		
	},

	objects_gallery2 : function(num, adm, object_category_id)
	{
		
		if(!num)
			num = 0;
		Gallery.StartLoading();
		new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=objects_gallery&num='+num+'&adm='+adm+'&object_category_id='+object_category_id+'&start=1', onSuccess:Gallery.processObjectGallery2, onFailure:Gallery.ErrorView});
	},
	processObjectGallery : function(req)
	{
		var i;
		if($('ObjectGallery'))
			i = $('ObjectGallery');
		
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading();
	},
	
	processObjectGallery2 : function(req)
	{
		var i;
		if($('ex_objects'))
			i = $('ex_objects');
		
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading();
	},
	
	
	one_object : function(object_id, adm)
	{
		
		Gallery.StartLoading();
		new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=one_object&object_id='+object_id+'&adm='+adm, onSuccess:Gallery.processOneObject, onFailure:Gallery.ErrorView});
		
	},
	processOneObject : function(req)
	{
		var i;
		if($('OneObject'))
			i = $('OneObject');
		
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading();
	},
	
	vote : function(block_id,answer, bid)
	{
		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:function(req)
			{
				var i;
				if($('vote_place'+bid))
				i = $('vote_place'+bid);
		
				if(req.responseText)
				{
					i.innerHTML = '';
					i.innerHTML = req.responseText;
				}
				if($('Loading'))
				{
					var d = $("Loading");
					document.body.removeChild(d);
					document.body.style.cursor = "default";
				}
	    	}, 
			onFailure:function()
			{
				alert('Ошибка: ' + t.status + ' -- ' + t.statusText);
			}});

		}
	},
	
	processGetVotePost : function(req)
	{
		
	},
	
	
	subscribe : function(email, adm)
	{
		
		Gallery.StartLoading();
		new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=subscribe&email=' + email + '&adm='+adm, onSuccess:Gallery.processSubscribe, onFailure:Gallery.ErrorView});
		
	},
	processSubscribe : function(req)
	{
		var i;
		if($('subscribe_div'))
			i = $('subscribe_div');
		
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		Gallery.EndLoading();
	},
	
	
	
	unsubscribe : function(email, adm)
	{
		
		Gallery.StartLoading();
		new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=unsubscribe&email=' + email + '&adm='+adm, onSuccess:Gallery.processunSubscribe, onFailure:Gallery.ErrorView});
		
	},
	processunSubscribe : function(req)
	{
		var i;
		if($('subscribe_div'))
			i = $('subscribe_div');
		
		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";
	},
	
	listing : function(block_id, page)
	{
		
		if(!page)
			page = 0;
		if(!block_id)
			this.errors("No Block!");
		else
		{
			Gallery.StartLoading();
			new Ajax.Request('/ajax2.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();
	}
,
	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;
	}}
