/**	Create by olmiha@gmail.com	**/
/**
*	$Id: slide.js,v 1.3 2008-01-23 11:32:44 miha Exp $
*/

var PosWinY;

Gallery = {
	Init : function(id)
	{
		this.StartLoading();

		var d = $('blocktxt');
		var l = $('prev');
		var r = $('next');
		var txt = '';
		var countphoto = myJSONObject.photo.length;
		var countrlid = myJSONObject.photo.length -1;
		/*if(ie5)
		{
			countphoto = countphoto -1;
			countrlid = countrlid - 1;
		}*/

		l.style.display = "none";
		r.style.display = "none";

		if(countphoto)
		{
			if($('Loading'))
			{
				$('Loading').style.borderColor = "#b0b0b2";
			}
			if(id >= 0 && myJSONObject.photo[id])
			{
				txt = '<table cellspacing="0" width="100%" cellpadding="0" border="0"><tr>';
				for(var i=id; i < (id +3); i++)
				{
					if(myJSONObject.photo[i])
					{
						txt += '<td width="30%" align="center"><div class="sliderfoto"><a href="' + myJSONObject.photo[i].link + '" class="slidermask" id="slidermask'+ i +'" onmouseover="Gallery.over(this)" onmouseout="Gallery.out(this)"><img id="img_slide" src="'+ myJSONObject.photo[i].smallphoto +'" border="0" cursor: pointer;" ' + myJSONObject.photo[i].smallsize + '"/></a></div></td>';
					}
				}
				txt += '</tr></table>';

				if((id - 3) >= 0)
				{
					var prevval = id - 3;
					if(prevval >= 0)
					{
						l.setAttribute("href", "javascript: Gallery.Init("+ prevval +")");
						l.style.display = "block";
					}
				}

				if((id + 3) <= countrlid)
				{
					var nextval = id + 3;
					if(nextval <= countrlid)
					{
						r.setAttribute("href", "javascript: Gallery.Init("+ nextval +")");
						r.style.display = "block";
					}
				}
			}

		}
		else
		{
			txt = 'No photo!';
		}

		d.style.textAlign = "center";
		d.style.verticalAlign = "middle";

		d.innerHTML = '';
		d.innerHTML = txt;

		this.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 - 50) + "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('Error ' + t.status + ' -- ' + t.statusText);
	},
	PosWin : function(e)
	{
		PosWinY = Event.pointerY(e);
	},
	show: function(src, size, bwidth, bheight)
		{
			this.StartLoading();
			if(document.getElementById('ContLogin'))
				NoLogin();
			var d = document.createElement("div");
			d.setAttribute("id", "MaskBody");
			d.className = "MaskBody";
			d.style.height = document.body.scrollHeight + "px";
			d.style.width = document.body.scrollWidth + "px";

			document.body.appendChild(d);

			var c = document.createElement("div");
			c.setAttribute("id", "ContLogin");
			c.className = "LoginBlock";
			//c.style.display = "none";
			c.style.width = "90%";
			c.style.height = (bheight + 27) + "px";
			c.style.left = "40px";
			c.style.right = "40px";
			//c.style.top = document.body.clientHeight / 2 - 100;
			c.style.top = (PosWinY - 300) + "px";
			document.body.appendChild(c);

			var text = '<table cellpadding="0" cellspacing="0" border="0" style="border: solid 1px #b0b0b2;" width="100%" onclick="Gallery.close();" style="cursor: pointer;">';
			text += '<tr><td style="background-color: #fff; height: 26px;" align="right" valign="middle"><img src="/img/admin/close.gif" border="0" width="20" height="20" style="cursor: pointer;"/>';
			text += '</td></tr><tr bgcolor="#c0c0c0">';
			text += '<td align="center" '+ size +'><img src="' + src + '" border="0" alt="" onclick="Gallery.close();" '+ size +' style="cursor: pointer;"/></td></tr></table>';

			var con = document.getElementById("ContLogin");
			con.innerHTML = text;
			this.EndLoading();
		},
	shownewwin: function(src, bwidth, bheight)
		{
			window.open(src, '' , 'width='+ bwidth +',height='+ bheight +',toolbar=no,location=no,titlebar=no,scrollbars=yes,status=no,resizable=yes');
		},
	close: function()
		{
			if(document.getElementById("ContLogin"))
			{
				var c = document.getElementById("ContLogin");
				document.body.removeChild(c);
			}
			if(document.getElementById("MaskBody"))
			{
				var d = document.getElementById("MaskBody");
				document.body.removeChild(d);
			}
		},
	over: function(id)
		{
			id.className = '';
		},
	out: function(id)
		{
			id.className = 'slidermask';
		}
}

