var last_open = 0;
var is_hidden = 0;
var stop_hide = 0;
//var tagging_on_picture = true;

function show_pic(id) {
var div = document.getElementById("p_"+id);
var td = document.getElementById('t_'+id);
if (!div) {
  var div = document.createElement("DIV");
  var span = document.createElement("SPAN");
  var img = document.getElementById("o_"+id);
  var gender_class = document.getElementById("c_"+id).className;
  var alt = img.getAttribute("alt");
  var alt_parts = alt.split("#|#");
  var username = alt_parts[0];
  if (alt_parts[1]) var album = alt_parts[1];

  if (album) {
    var img_next  = img.cloneNode(true);
    img_next.alt  = '';
    var img_href  = document.createElement("a");
    img_href.href = '/albums/'+username+'/'+album;
    img_href.appendChild(img_next);
  } else {
    img_href = img.cloneNode(true);
  }
  div.style.position = "absolute";
  div.style.display = "none";
  div.style.width = "110px";
  div.style.height = "110px";
  div.style.backgroundColor = "white";
  div.style.borderWidth = "1px";
  div.style.borderStyle = "solid";
  div.style.borderColor = "#D6DAE4";
  div.setAttribute("id", "p_"+id, 0);
  div.onmouseout = function() { hide_pic(id);}
  div.appendChild(document.createElement("BR"));
  div.appendChild(img_href);
  div.appendChild(document.createElement("BR"));
  span.innerHTML+= '<a href="/albums/'+username+'" class="'+gender_class+'">'+username+'</a><br />';
  div.appendChild(span);
  td.appendChild(div);
}

if (div) {
  if (last_open && last_open!=id) hide_pic(last_open, 'from td');
  var pos = findPos(td);
  div.style.left = pos[0] - 18 + 'px';
  div.style.top = pos[1] - 9 + 'px';
  div.style.display = "block";
  last_open = id;
}
}
function hide_pic(id, ps) {
	var div = document.getElementById('p_'+id);
	if (div) {
	  div.style.display = "none";
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	  curleft+= obj.offsetLeft;
	  curtop+= obj.offsetTop;
	  while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	  }
	}
	return [curleft,curtop];
}
function hidePicChangeBox(type) {
	if (is_hidden == 0 && stop_hide == 0) {
	  if (type < 2) document.body.removeChild(pic_box);
	  if (type > 0) {
		document.body.removeChild(prev_next);
	  }
	  is_hidden = 1;
	}
}
function showPicChangeBox(obj, type, pic_id, s1, box_width, start) {

	
	var arr = document.getElementById('arrows_onload');
	if (arr && arr.style.display != "none") {
		arr.style.display = "none";
	}



	if (type > 0) {
		pos_element = document.getElementById('pink_td');
	} else {
		pos_element = obj;
	}
	if (typeof(pic_box) == 'undefined') {
	  is_hidden = 0;
	  pic_box   = document.createElement('div');
	  pic_box.style.width    = box_width ? box_width + 'px' : '120px';
	  pic_box.style.position = 'absolute';
	  if (type > 0) {
		pic_box.style.height          = '60px';
	  } else {
		pic_box.style.backgroundColor = 'white';
	  }
	  pic_box.onmouseover = function() {
		stop_hide = 1;
		window.setTimeout(function() {stop_hide = 0;}, 100);
	  }
	  pic_box.onmouseout = function() {
		window.setTimeout(function() {hidePicChangeBox(type);}, 1);
	  }
	  if (type < 2) {
		  obj.onmouseout = function() {
			window.setTimeout(function() {hidePicChangeBox(type);}, 1);
		  }
	  }
	  if (typeof setOpacity != 'undefined') {
		setOpacity(pic_box,0.5);
	  }
	  if (type < 2) document.body.appendChild(pic_box);
	}

	//stop_hide = 1;
	//window.setTimeout(function() {stop_hide = 0;}, 100);
	stop_hide = 0;

	var pos = findPos(pos_element);
	if (type > 0 && typeof(prev_next) == 'undefined') {
	  prev_next = pic_box.cloneNode(true);
	  prev_next.onmouseover = pic_box.onmouseover;
	  prev_next.onmouseout  = pic_box.onmouseout;
	  document.body.appendChild(prev_next);
	}


	if (type > 0 && !tagging) {//
	
	  prev_next.style.left = pos[0] + 6 + 'px';
	  prev_next.style.top  = pos[1] + 62 + 'px';
	  var arrowHTML = "<table cellpadding='0' cellspacing='0' border='0' height='100%' width='" + picture_width + "' id ='arrows_onload' style='z-index:800'><TR>";
	  var pic_prev  = obj.getAttribute('pic_prev');
	  var pic_next  = obj.getAttribute('pic_next');
	  if (pic_prev) {
		arrowHTML += "<TD align='left' bgcolor='black'>" +
		"<a href='http://www." + path_domain + "/albums.php?act=picture&id=" +
		pic_prev + "&panel=1#content'><img src='http://pics." + path_domain +
		"/pics/neo/194/arrow_back.gif' border='0'></a></TD>";
	  }

	  arrowHTML += "<TD width='100%' onMouseOver=showBoxOnMove(); tagging = 1;>&nbsp;</TD>";
	  if (pic_next) {
		arrowHTML += "<TD align='right' bgcolor='black'>" +
		"<a href='http://www." + path_domain + "/albums.php?act=picture&id=" +
		pic_next + "&panel=1#content'><img src='http://pics." + path_domain +
		"/pics/neo/194/arrow_next.gif' border='0'></a></TD>";
	  }
	  arrowHTML += "</TR></TABLE>";
	  if (prev_next)
	  {
		   prev_next.innerHTML = arrowHTML;
	  }
	
	}

		if (tagging)
	{
		getElementById('arrows_onload').style.display = 'none';
	}
	if (type < 2) {
	  if (s1 == 0) {
		if (type == 0) {
		  pic_box.style.height = '18px';
		}
		e_text = '';
	  } else if (s1 == 1) {
		pic_box.style.height = '';
		e_text = "<BR><span style='color: red'>" + msg[194][415] + "</span><BR><BR>";
	  } else {
		pic_box.style.height = '';
		e_text = "<BR><span style='color: red'>" + msg[194][239] + "</span><BR><BR>";
	  }
	  pic_box.style.left = pos[0] + 6 + "px";
	  pic_box.style.top  = pos[1] + "px";
	  var txtStyle   = '';
	  var tblBgColor = '';
	  if (type > 0) {
		txtStyle   = " style='font-family: arial; font-size: 26px; color: #ccc;'";
		tblBgColor = " bgcolor='black'";
	  }
	  start_url = start ? "&start=" + start : "";
	  pic_box.innerHTML  = "<TABLE cellpadding='0' cellspacing='0' border='0' height='100%' width='" + box_width + "'" + tblBgColor + "><TR><TD align='left' style='padding-left: 10px;'>" +
	  "<a href='/albums.php?act=change_picture&id=" + pic_id + start_url + "'" + txtStyle + ">" + msg[194][133] + "</a></TD>" +
	  "<TD align='right' style='padding-right: 10px;'>" +
	  "<a href='/albums.php?act=delete_picture_confirmed&id=" + pic_id + start_url +"' onClick=\"return confirm('" + msg[194][143] + "')\"" + txtStyle + ">" + msg[194][141] + "</a></TD></TR></TABLE>" + e_text;
	}

	if (is_hidden == 1) {
	  if (type < 2) document.body.appendChild(pic_box);
	  if (type > 0) document.body.appendChild(prev_next);
	  is_hidden = 0;
	}
}

function getthumb(first_run) {
if (first_run && typeof(is_open) != 'undefined' && is_open == 1) {
  return false;
}
if (first_run) {
  albumpic = document.getElementById('albumpic');
  obj = document.getElementById('piclink');
  var container = obj.previousSibling;
  if (container.hasChildNodes()) {
    container.removeChild(container.firstChild);
  }

  box = document.createElement('div');
  box.style.position = 'absolute';
  box.style.width    = '82px';

  thumb = document.createElement('div');
  thumb.style.overflow = 'auto';
  thumb.style.height   = '332px';

  last = 0;
  user_pics_keys = new Array();
  for (var j in user_pics) {
    user_pics_keys.push(j);
  }
  is_closed = 0;
  is_open   = 1;
}

var pic     = 0;
var key     = 0;
var limit   = last + 25;
var pic_exp = new RegExp('^(http:\\/\\/albums.' + path_domain + '\\/(?:s3\\/)?)3\\/(([\\d\\w]\\/)+)3(.+)', 'gi');
if (limit > user_pics_keys.length) limit = user_pics_keys.length;

for (var i = last; i < limit; i++) {
  pic = document.createElement('img');
  key        = user_pics_keys[i];
  pic.src    = user_pics[key];
  pic.pic_id = key;
  pic.style.cursor  = 'hand';
  pic.style.width   = '60px';
  pic.style.height  = '60px';
  pic.style.border  = '3px solid white';
  pic.onmousedown   = function() {
    document.getElementById('added_pics_id').value = this.pic_id;
    document.getElementById('message').style.visibility = 'visible';
    albumpic.src = this.src.replace(pic_exp, '$12/$22$4');
    obj.previousSibling.removeChild(box);
    is_closed = 1;
  }
  thumb.appendChild(pic);
  thumb.appendChild(document.createElement('br'));
}

if (first_run) {
  var childObj = document.createElement('b');
  childObj.className = 'menu';
  childObj.innerHTML = msg[194][203];
  box.appendChild(childObj);
  box.appendChild(document.createElement('br'));
  box.appendChild(thumb);
  container.appendChild(box);

  var pos = findPos(albumpic);
  box.style.left = pos[0] + 140 + 'px';
  box.style.top  = pos[1] - 16  + 'px';
}

if (user_pics_keys.length > i && !is_closed) {
  last = i;
  window.setTimeout('getthumb(false)', 100);
} else {
  is_open = 0;
}
return false;
}
function set_mouse_handlers() {
	try {
		var img = document.getElementById('img_src');
		var td = document.getElementById('pink_td');


		if (td) {
			td.onmouseout = function() { 
				window.setTimeout(function() {hidePicChangeBox(is_owner);}, 1);
			}
			td.onmouseover = function() { 
				stop_hide = 1;
				window.setTimeout(function() {showPicChangeBox(img, is_owner, pic_id, s1, picture_width);}, 1);
				window.setTimeout(function() {stop_hide = 0;}, 100);
			}
		}
		

		if (img) {
			img.onmouseover = function() { 
				stop_hide = 1;
				window.setTimeout(function() {showPicChangeBox(img, is_owner, pic_id, s1, picture_width);}, 1);
				window.setTimeout(function() {stop_hide = 0;}, 100);
			}
		}
		//showPicChangeBox(img, is_owner, pic_id, s1, picture_width);
	} catch(err) {
	   setTimeout("set_mouse_handlers", 200);
	}
}
function checkPage() { 
	if (document.readyState) {
		if (document.readyState == 'complete') set_mouse_handlers();
		else window.setTimeout("checkPage()", 200);
	}
	if (document.addEventListener) document.addEventListener("DOMContentLoaded", set_mouse_handlers, false);
}

