SL = {
	listing : function(block_id, page, slide_show)
	{
		if ((!slide_show) || (slide_show==undefined))
			slide_show=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&block_id=' + block_id + '&opg=' + page + '&slide_show='+slide_show,
			onSuccess:function(req){
     	 		var i;
     	 		
				if($('place'+block_id))
					i = $('place'+block_id);
		
				if(req.responseText)
				{
					
					i.innerHTML = '';
					i.innerHTML = req.responseText;
				}
				SL.EndLoading();
				if ($('slide_show'+block_id).value == '1')
					SL.start_slide_show(block_id);
				else
					SL.stop_slide_show(block_id);
    	}, 
		onFailure:SL.ErrorView});

		}
	},
	
	stop_slide_show : function(block_id)
	{
		$('go_slide'+block_id).value=0;
		$('slide_show'+block_id).value=0;
		$('slide_button'+block_id).src="/img/play.gif";
		
	},
	
	start_slide_show : function(block_id)
	{
		$('go_slide'+block_id).value = 1;
		$('slide_button'+block_id).src="/img/pause.gif";
		var cur_photo=$('cur'+block_id).value;
		var next_photo=$('next'+block_id).value;
		var block_id=$('block_id'+block_id).value;
		if ( (!next_photo) || (next_photo == undefined))
			next_photo=0;
		setTimeout("if ($('go_slide'+" + block_id + ").value == 1){SL.listing("+block_id+", "+next_photo+", 1);};", 3000);
		
	},
	start_stop_slide_show : function(block_id)
	{
		if ($('slide_show'+block_id).value==1)
			SL.stop_slide_show(block_id);
		else
		{
			SL.start_slide_show(block_id);
		}		
	},
	
	processGetPost : function(req)
	{
		var i;
		if($('place1'))
			i = $('place1');
		
		if(req.responseText)
		{
			i.innerHTML = '';
			i.innerHTML = req.responseText;
		}
		SL.EndLoading();
		if ($('slide_show'+block_id).value == '1')
			SL.start_slide_show();
		else
			SL.stop_slide_show();
		
	},
	
	StartLoading : function()
	{
		if($('Loading'))
			SL.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('loading');
		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;
	},
	ShowNewWin: function(src, bwidth, bheight)
	{
		window.open(src, '' , 'width='+ bwidth +',height='+ bheight +',toolbar=no,location=no,titlebar=no,scrollbars=yes,status=no,resizable=yes');
	}
}