function View(id)
{
	if (id == 1)
	{

	}
	if (id == 2)
	{
		if(document.getElementById('table_forms').style.display == "")
		{
			document.getElementById('table_forms').style.display = "none";
		}
		else
		{
			document.getElementById('table_forms').style.display = "";
		}
	}
}

function delMyFoto(pid)
{
	location.href = 'gallery.php?pid='+pid+'&savename=2&btn=9';
}

function getGal(gid, pid, n)
{
	location.href = 'gallery.php?&gid='+gid+'&pid='+pid+'&n='+i;
}
function toGal(gid, pid)
{
	location.href = 'gallery.php?gid='+gid+'&pid='+pid;
}

function vote(gid, rate, pid, f)
{
	location.href = 'gallery.php?btn=8&fvote=1&gid='+gid+'&pid='+pid+'&rate='+rate+'&f='+f;
}

function showFiltr(sort, count)
{
	location.href = 'gallery.php?sort='+sort+'&count='+count;
}

function showGal(gid)
{
	location.href = 'gallery.php?btn=8&gid='+gid;
}

function marks(id,type)
{
	var url = '/guide/img/photogallery/';
	if (!document.images)
   {
     return false;
   }
  for (i=1;i<=id;i++)
   {
     if (type=="show")
      {
        document.images["mark"+i].src=url+'but_'+i+'.gif';
      }
     else if (type=="hide")
      {
        document.images["mark"+i].src=url+'but_'+i+'_gray.gif';
      }
   }
}

function marks2(id,type)
{
	var url = '/guide/img/photogallery/';
	if (!document.images)
	{
		return false;
	}
	if(slect)
	{
		if(id<slect)
		{
			id=slect;
			type='show';
		}
	}

	for (i=1;i<=id;i++)
	{
		if (type=="show")
		{
			document.images["mark2"+i].src=url+'but_'+i+'.gif';
		}
		else if (type=="hide")
		{
			if(slect)
			{
				if(i>slect)
				{
					document.images["mark2"+i].src=url+'but_'+i+'_gray.gif';
				} else document.images["mark2"+i].src=url+'but_'+i+'.gif';
			}else document.images["mark2"+i].src=url+'but_'+i+'_gray.gif';
		}
	}
}

	var PhotoGallery = Class.create();
	PhotoGallery.prototype = {
		per_page : 4,
		gallery_id : null,
		photos : null,
		item_id : null,
		item_page : null,
		base_url : null,
		initialize : function(div_id, gallery_id, photos, item_id, base_url, btn) {
			this.gallery_id = gallery_id;
			this.photos = photos;/* {"id":1, "src":"file.jpg"} */
			this.base_url = base_url;
			this.btn = btn;
			this.div_id = div_id;
			this.item_id = item_id;
			var item_id_position = 0;
			for ( var j = 0; j < photos.length; j++)
				if (item_id == photos[j].id) {
					item_id_position = j;
					break;
				}
			this.item_page = Math.floor(item_id_position / this.per_page);
		},
		nextPage : function() {
			//this.item_page = this.photos.length > (this.item_page + 1) * this.per_page ? this.item_page + 1 : this.item_page;
			this.item_page = this.photos.length > (this.item_page + 1) + this.per_page ? this.item_page + 1 : this.item_page;
			this.render();
		},
		prevPage : function() {
			if (this.item_page > 0)
			{
				this.item_page = this.item_page > 0 ? this.item_page - 1 : 0;
				this.render();
			}
		},
		render_nav : function() {
            /*
			if (this.photos.length > (this.item_page + 1) * this.per_page) {
				$('g_next_photo').show();
			} else {
				$('g_next_photo').hide();
			}
			if (this.item_page > 0) {
				$('g_prev_photo').show();
			} else {
				$('g_prev_photo').hide();
			}
			*/
		},
		render : function(flag)
		{
			if (flag)
			{
				for ( var i = 0; i < this.photos.length; i++)
				{
					if (this.item_id == this.photos[i].id && i>this.per_page)
					{
						this.item_page = i-this.per_page;
						break;
					}
				}
			}
			var img, href;
			var pcontent = '', subscribe = 'Фотографии: <b>';
            for ( var i = 0; i < this.photos.length; i++)
			{
				href = 'gallery.php?btn='+this.btn+'&pid='+this.photos[i].id+'&gid='+this.photos[i].gid;
				if (this.item_id == this.photos[i].id)
				{
					subscribe += ' <span class=\"txt_on\">' + (i + 1) + '</span> ';
				} else {
					subscribe += ' <a href="' + href + '" class="txt_off">' + (i + 1) + '</a> ';
				}
				//if (i >= this.item_page * this.per_page && i < (this.item_page * this.per_page + this.per_page) + 1)
                //alert(i +'>='+ this.item_page+' && '+ i +'<'+ (this.item_page + this.per_page + 1));
				if (i >= this.item_page && i < (this.item_page + this.per_page) + 1)
				{
					img = '<a href="'+href+'"><img src="'+this.base_url+'/'+this.photos[i].src+'" border="0"></a>';
					pcontent += '<td style="' + (this.item_id == this.photos[i].id ? 'border: 1px solid red; ' : '')
							+ 'width: 85px; height: 90px;" align="center">' + img + '</td>';
				}  else
				{
					//break;
				}
			}
			var html_content = '<table border="0" cellpadding="0" cellspacing="0" style="text-align: center;" align="center">'
					+ '<tr>' + pcontent + '</tr>' + '</table>';

			if (document.getElementById(this.div_id))
			{
				document.getElementById(this.div_id).innerHTML = html_content;
			}
			if (document.getElementById('gallery_num'))
			{
				document.getElementById('gallery_num').innerHTML = subscribe + '</b>';
			}
			this.render_nav();
		}
	};
