function hide_item(elem)
{
	elem = document.getElementById(elem);
		elem.style.display = 'none';
}


function show_item(elem)
{
	elem = document.getElementById(elem);
		elem.style.display = 'block';
}


function show_hide_item(elem)
{
	elem = document.getElementById(elem);
	if (elem.style.display == 'block')
		elem.style.display = 'none';
	else
		elem.style.display = 'block';
}

function show_img(ind) {
	var el = document.getElementById("gallery");
	el.src = root_path + "/i/upload/event/" + gallery_mode + "/" + gallery[ind-1];
	gallery_page_activate(gallery_current+1, "");
	gallery_current = ind - 1;
	gallery_page_activate(gallery_current+1, "active");
}

function gallery_page_activate(page_ind, class_name) {
	var el = document.getElementById("gallery_" + page_ind);
	if(class_name=="active") {
		el.className = class_name;
		el.innerHTML = "<b>[" + page_ind + "]</b>";
	}
	else {
		el.className = class_name;
		el.innerHTML = "<a href=\"\" onclick=\"show_img(" +page_ind + "); return false;\" class=\"item\"><b>" + page_ind + "</b></a>";
	}
}

function gallery_full_view() {
	var img_src = root_path + "/i/upload/event/original/" + gallery[gallery_current];
	ImgOpen(img_src);
}

var mywin;
var r_id = Math.random();
r_id = Math.round(r_id*10000);

function ImgOpen(url){
  try {
	mywin.close();
  } catch (e){
	// none
  } finally {
	mywin = window.open("","bigPhoto"+r_id,'width=250,height=110,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
	mywin.document.open();
	mywin.document.write("<HTML><body style=overflow:hidden;margin:0px;border:0px;padding:0px;background:#ffffff>");
	mywin.document.write("<table width=100% height=100% border=0 cellspacing=0 cellpadding=0><tr><td align=center>");
	mywin.document.write("<a href='#' title='закрыть окно' style='cursor:hand'><img id=myImg src="+url+" onClick='window.close()' border=0></a><br>");
	mywin.document.write("</td></tr></table>");
	mywin.document.write("<script>window.focus();resizeWindow();function resizeWindow(){window.opener.rWindow(window,document.images.myImg);}</script>");
	mywin.document.write("</body></HTML>");
	mywin.document.close();

  }
  return false;
}

// Open images in popup
var k=0;
var rWin,rImg;

function rWindow(win,img){
	if (img.width > 30 && img.height > 30) {  // размер дефольтной незагруженной картинки обычно менее чем 30x30 
		w = win.innerWidth || win.document.body.clientWidth
		h = win.innerHeight || win.document.body.clientHeight
		win.resizeBy(img.width - w, img.height - h)
	} else {
		k++
		rWin = win
		rImg = img
		setTimeout('rWindow(rWin,rImg)',100);
	}
}

