/**	Create by olmiha@gmail.com	**/
/**
*	$Id: slide.js,v 1.4 2008-02-13 10:07:55 miha Exp $
*/


Gallery = {
	ListingEvents: function(id)
	{
		Loading.StartLoading();

		var d = false;
		if($('eventcontent'))
			d = $('eventcontent');
		var l = false;
		if($('prevEv'))
			l = $('prevEv');
		var r = false;
		if($('nextEv'))
			 r = $('nextEv');
		var lp = false;
		if($('prevpreviw'))
			lp = $('prevpreviw');
		var rp = false;
		if($('nextpreviw'))
			rp = $('nextpreviw');
		var txt = '';
		var countphoto = myJSONObjectEvent.photo.length;
		var countrlid = myJSONObjectEvent.photo.length - 1;

		if(l)
			l.style.display = "none";
		if(r)
			r.style.display = "none";
		if(lp)
			lp.style.display = "none";
		if(rp)
			rp.style.display = "none";

		if(countphoto)
		{
			if(id >= 0 && myJSONObjectEvent.photo[id])
			{
				var cntlist = myJSONObjectEvent.photo[id].countlist;

				txt = '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr>';
				for(var i=id; i < (id + cntlist); i++)
				{
					if(myJSONObjectEvent.photo[i])
					{
						txt += '<td align="left" style="padding: 0 10px;">';
						//txt += '<table cellspacing="0" cellpadding="0" border="0" class="sliderfoto"><tr>';
						//txt += '<td align="center">';
						//txt += '<a href='+ myJSONObjectEvent.photo[i].link +' id="slidermask'+ i +'" onmouseover="Gallery.over(this)" onmouseout="Gallery.out(this)">';
						txt += '<img ';
						//txt += ' class="opacityImg" onmouseover="fadeOpacity(this.id, \''+stl+'\')" onmouseout="fadeOpacity.back(this.id)"';
						txt += ' src="'+ myJSONObjectEvent.photo[i].photo +'" border="0" ' + myJSONObjectEvent.photo[i].size;
						txt += 'title="'+ myJSONObjectEvent.photo[i].caption +'"';
						txt += '/>';
						//txt += '</a></td>';
						//txt += '</tr>';
						txt += '</td>';
					}
				}
				txt += '</tr></table>';

				// Divs
				/*txt = '<ul>';
				for(var i=id; i < (id + cntlist); i++)
				{
					if(myJSONObjectEvent.photo[i])
					{
						txt += '<li>';
						txt += '<img id="imgc'+i+'"';
						txt += ' class="opacityImg" onmouseover="fadeOpacity(this.id, \''+stl+'\'); doTooltip(event,'+ i +');" onmouseout="fadeOpacity.back(this.id); hideTip();"';
						txt += ' src="'+ myJSONObjectEvent.photo[i].photo +'" ' + myJSONObjectEvent.photo[i].size;
						txt += 'title="'+ myJSONObjectEvent.photo[i].caption +'"';
						txt += '/>';
						txt += '</li>';
					}
				}
				txt += '</ul>';*/

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

				if(countphoto > (id + cntlist) && r)
				{
					var nextval = id + cntlist;
					r.setAttribute("href", "javascript: Gallery.ListingEvents("+ nextval +")");
					r.style.display = "block";
				}
			}
		}
		else
		{
			txt = 'No photo!';
		}

		if(d)
		{
			d.style.textAlign = "center";
			d.style.verticalAlign = "middle";

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

		Loading.EndLoading();
	},
	Listing: function(id)
	{
		Loading.StartLoading();

		var d = false;
		if($('cartscontent'))
			d = $('cartscontent');
		var l = false;
		if($('prev'))
			l = $('prev');
		var r = false;
		if($('next'))
			 r = $('next');
		var lp = false;
		if($('prevpreviw'))
			lp = $('prevpreviw');
		var rp = false;
		if($('nextpreviw'))
			rp = $('nextpreviw');
		var txt = '';
		var countphoto = myJSONObject.photo.length;
		var countrlid = myJSONObject.photo.length - 1;

		if(l)
			l.style.display = "none";
		if(r)
			r.style.display = "none";
		if(lp)
			lp.style.display = "none";
		if(rp)
			rp.style.display = "none";

		if(countphoto)
		{
			if(id >= 0 && myJSONObject.photo[id])
			{
				var cntlist = myJSONObject.photo[id].countlist;

				/*txt = '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr>';
				for(var i=id; i < (id + cntlist); i++)
				{
					if(myJSONObject.photo[i])
					{
						txt += '<td align="center" style="padding: 0 5px;">';
						txt += '<table cellspacing="0" cellpadding="0" border="0" class="sliderfoto"><tr>';
						txt += '<td align="center">';
						txt += '<a href='+ myJSONObject.photo[i].link +' id="slidermask'+ i +'" onmouseover="Gallery.over(this)" onmouseout="Gallery.out(this)">';
						txt += '<img id="imgc'+i+'"';
						txt += ' class="opacityImg" onmouseover="fadeOpacity(this.id, \''+stl+'\')" onmouseout="fadeOpacity.back(this.id)"';
						txt += ' src="'+ myJSONObject.photo[i].smallphoto +'" border="0" cursor: pointer;" ' + myJSONObject.photo[i].smallsize + '"/>';
						txt += '</a></td>';
						txt += '</tr>';
						if(myJSONObject.photo[i].logoview)
							txt += '<tr><td align="right" style="padding-top: 10px;"><img src="/img/sms.gif" width="47" height="21" border="0"/></td></tr>';
						txt += '</table></td>';
					}
				}
				txt += '</tr></table>';*/

				// Divs
				txt = '<ul>';
				for(var i=id; i < (id + cntlist); i++)
				{
					if(myJSONObject.photo[i])
					{
						txt += '<li class="sex'+ myJSONObject.photo[i].sex +'">';
						txt += '<img id="imgc'+i+'"';

						if(myJSONObject.photo[i].avtorizuser)
						{
							txt += ' class="png" ';
							txt += 'onmouseover="doTooltip(event,'+ i +');" onmouseout="hideTip();"';
						}
						else
							txt += ' class="opacityImg" ';

						if(myJSONObject.photo[i].smallphoto)
							txt += ' src="/'+ myJSONObject.photo[i].smallphoto +'" ';
						else
						{
							if(myJSONObject.photo[i].sex == 'f')
								txt += ' src="/img/quen.png" ';
							else
								txt += ' src="/img/king.png" ';
						}
						txt += 'width="90" height="120"/>';
						txt += '</li>';
					}
				}
				txt += '</ul>';

				if(countrlid >= (id - cntlist) && l && myJSONObject.photo[0].avtorizuser)
				{
					var prevval = id - 1;
					if(prevval >= 0)
					{
						l.setAttribute("href", "javascript: Gallery.Listing("+ prevval +")");
						l.style.display = "block";
					}
				}

				if(countphoto > (id + cntlist) && r && myJSONObject.photo[0].avtorizuser)
				{
					var nextval = id + 1;
					r.setAttribute("href", "javascript: Gallery.Listing("+ nextval +")");
					r.style.display = "block";
				}
			}
		}
		else
		{
			txt = 'No photo!';
		}

		if(d)
		{
			d.style.textAlign = "center";
			d.style.verticalAlign = "middle";

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

		Loading.EndLoading();
	},
	show: function(src, bwidth, bheight)
		{
			Loading.StartLoading();
			if(document.getElementById('ContLogin'))
				this.close();
			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" width='+ bwidth +' height='+ bheight +'><img src="' + src + '" border="0" alt="" onclick="Gallery.close();" width='+ bwidth +' height='+ bheight +' style="cursor: pointer;"/></td></tr></table>';

			var con = document.getElementById("ContLogin");
			con.innerHTML = text;
			Loading.EndLoading();
		},
	showprev: function(src, prewidth, preheight, idp, big_photo, bigwidth, bigheight, captiontxt)
	   {
			var lp = false;
			if($('prevpreviw'))
				lp = $('prevpreviw');
			var rp = false;
			if($('nextpreviw'))
				rp = $('nextpreviw');
			var countrlid = myJSONObject.photo.length - 1;

	       if($('photoprev'))
	       {
				$('photoprev').innerHTML = '';
				$('photoprev').innerHTML = '<img src="'+ src +'" width="'+ prewidth +'" height="'+ preheight +'" border="0">';

				$('previewcaption').innerHTML = '';
				$('previewcaption').innerHTML = captiontxt;

				$('show_big').innerHTML = '';
				$('show_big').innerHTML = '<a href="javascript: Gallery.shownewwin(\''+ big_photo +'\','+ bigwidth +','+ bigheight +');"><img src="/img/lupa.gif" width="24" htight="23" border="0" title=""/></a>';

				if($('imgc' + idp))
				{
					var i = $('imgc' + idp);
					i.className = '';
					i.setAttribute("onmouseover", '');
					i.setAttribute("onmouseout", '');
				}

				if(lp)
				{
					if(idp > 0)
					{
						lp.setAttribute("href", "javascript: Gallery.InitOne("+ (idp - 1) +")");
						lp.style.display = "block";
					}
					else
						lp.style.display = "none";
				}

				if(rp)
				{
					if(idp < 9 && (countrlid != idp))
					{
						rp.setAttribute("href", "javascript: Gallery.InitOne("+ (idp + 1) +")");
						rp.style.display = "block";
					}
					else
						rp.style.display = "none";
				}
	       }
	   },
	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';
		},
	showinfo: function()
	{

	}
}

