<!--
var MSIE = false;
var agent = navigator.userAgent;
if (/MSIE/.test(agent)) MSIE = true;
function hideStatus(n) {
	if (!n) n = 'statusDiv';
	if (o = getObj(n))
		o.style.display='none';
}
function unhtml(n) {
  s = '';
  while (s != n) {
    s = n;
    n = n.replace(/<br\/?>/ig, "\n").replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  }
  return n;
}
function nl2br(n) {
  s = '';
  while (s != n) { s = n; n = n.replace("\n", '<br>'); }
  return n;
}
var photoOld = new Array();
var photoEmpty = new Array();
photoEmpty['Title'] = '無題';
photoEmpty['Desc'] = 'この写真に説明文を追加';
function editPhoto(t) {
  if (!(o = getObj('photo'+t))) return false;
  if (!(d = getObj('photo'+t+'Edit'))) return false;
  if (!(f = getObj('photo'+t+'Form'))) return false;
  n = o.innerHTML;
  photoOld[t] = n;
  if (n == photoEmpty[t]) n = '';
  else n = unhtml(n);
  f.value = n;
  o.style.display = 'none';
  d.style.display = 'block';
  f.select();
  f.focus();
}
function editSave(t) {
  if (!(o = getObj('photo'+t))) return false;
  if (!(f = getObj('photo'+t+'Form'))) return false;
  s = ''; n = f.value;
  post = 'photo[id]=' + photoId + '&photo[' + t + ']=' + encodeURIComponent(n);
  postHTTP(root + 'upd_ph/', post);
  if (n == '') n = photoEmpty[t];
  else n = nl2br(n);
  if (t == 'Title')
    document.title = document.title.replace(photoOld[t], n);
  o.innerHTML = n;
  editCancel(t);
}
function editCancel(t) {
  if (!(o = getObj('photo'+t))) return false;
  if (!(d = getObj('photo'+t+'Edit'))) return false;
  o.style.display = 'block';
  d.style.display = 'none';
}
function confirm_rotate(an, flop, flip) {
	location.href = root + 'upd_ph/?id=' + photoId + '&rotate=' + an + '&flip=' + flip + '&flop=' + flop + '&backUrl=' + encodeURIComponent(location.href);
//	alert('an: ' + an + ', flop: ' + flop + ', flip: ' + flip);
}
function discard_rotate() {
	hideRotate();
}
function openRotate(pid) {
	sendToFriendHide();
	hideGroups();
	hideAlbums();
	var rand = Math.round(Math.random()*1000000);
	var img = root + 'nocache' + rand + '/files/photos/' + userId + '/' + pid + '_d.jpg';
	o = getObj('albumPostDiv');
	nd = document.createElement('div');
	nd.innerHTML = '<div class="b c03 pb5">写真を回転させ[OK]を押してください。</div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="280" height="240" id="Splash" align="middle"><param name="allowScriptAccess" value="sameDomain"><param name="movie" value="http://'+http_host+root+'image_rotate.swf?img_url='+img+'"><param name="quality" value="high"><param name="bgcolor" value="#F3F3F3"><embed src="http://'+http_host+root+'image_rotate.swf?img_url='+img+'" quality="high" bgcolor="#F3F3F3" width="280" height="240" name="splash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></object>'
	+'<br/><a href="#" onclick="hideRotate(); return false;">キャンセル</a>';
	o.appendChild(nd);
	displayRotate();
}
function hideRotate() {
	disableNotes = false;
	o = getObj('albumPostDiv');
	for (i = o.childNodes.length - 1; i >= 0; i--)
		o.removeChild(o.childNodes[i]);
	o.style.display = 'none';
}
function displayRotate() {
	disableNotes = true;
	o = getObj('albumPostDiv');
	r = getObj('root');
	o.style.top = getOffsetTop(r) + 20;
	o.style.border = '1px solid black';
	o.style.backgroundColor = 'white';
	o.style.padding = '5px';
	setStyleRec(o, 'zIndex', '5');
	setStyleRec(o, 'display', 'inline');
	l = getOffsetLeft(r);
	if (r.offsetWidth > o.offsetWidth)
		l += (r.offsetWidth - o.offsetWidth) / 2;
	else
		l += 10;
	o.style.left = l;
}
// albums start
var albumsTimer = -1;
function noHideAlbums() { albumsTimer = -1; }
function startHideAlbums() { checkHideAlbums(30); }
function checkHideAlbums(time) {
	if (time) albumsTimer = time;
	if (albumsTimer >= 0) {
		albumsTimer--;
		if (!albumsTimer) hideAlbums();
		else setTimeout('checkHideAlbums()', 50);
	}
}
function openAlbum(pid) {
	sendToFriendHide();
	hideGroups();
	hideAlbums();
	if (albumsTimer > 0) {
		albumsTimer = -1;
		return;
	}
	o = getObj('albumPostDiv');
	nd = document.createElement('div');
	nd.style.margin = '10px';
	nd.innerHTML = 'ロード中...';
	o.appendChild(nd);
	displayAlbums();
	getHTML(root + 'alb_ph/alb_list/0/' + pid, showAlbums); 
}
function doCreateAlbum() {
	f = getObj('newAlbumForm');
	if (!f['title'] || !f['title'].value || f['title'].value == '') {
		alert('アルバム名を入力してください。');
		return false;
	}
	postdata = 'folder[title]=' + encodeURIComponent(f['title'].value) + '&folder[description]=' + encodeURIComponent(f['description'].value);
	postHTTP(root + 'alb_ph/alb_create/0/' + photoId, postdata);
	hideAlbums();
	return false;
}
function createAlbum() {
	hideAlbums();
	o = getObj('albumPostDiv');
	nf = document.createElement('form');
	nf.id = 'newAlbumForm';
	nf.style.padding = '5px';
	addEvent(nf, 'submit', doCreateAlbum);
	nf.action = 'javascript:void(0);';
	o.appendChild(nf);
	nd = document.createElement('div');
	nd.innerHTML = '題名:';
	nf.appendChild(nd);
	ni = document.createElement('input');
	ni.style.width = '200px';
	ni.type = 'text';
	ni.name = 'title';
	nf.appendChild(ni);
	nd = document.createElement('div');
	nd.innerHTML = '説明:';
	nf.appendChild(nd);
	ni = document.createElement('textarea');
	ni.style.width = '200px';
	ni.rows = '4';
	ni.name = 'description';
	nf.appendChild(ni);
	nb = document.createElement('br');
	nf.appendChild(nb);
	ns = document.createElement('input');
	ns.className = 'kno';
	ns.type = 'submit';
	ns.value = '追加';
	nf.appendChild(ns);
	nr = document.createElement('input');
	nr.className = 'kno';
	nr.type = 'button';
	nr.value = 'キャンセル';
	addEvent(nr, 'click', hideAlbums);
	nf.appendChild(nr);
	displayAlbums();
	ns.style.display = 'inline';
	nr.style.display = 'inline';
	checkHideAlbums(100);
}
function showAlbums(text) {
	sendToFriendHide();
	hideAlbums();
	o = getObj('albumPostDiv');
	nd = document.createElement('div');
	nd.style.padding = '5px';
	nd.innerHTML = '<b>アルバムへ写真を追加</b><br>この写真を追加するアルバムを以下より選択してください。<br>新しくアルバムを作成して追加する場合は、[新規アルバム]を<br>選択してください。';
	o.appendChild(nd);
	nd = document.createElement('hr');
	o.appendChild(nd);
	nd = document.createElement('div');
	nd.style.padding = '5px';
	if (MSIE) nd.style.cursor = 'hand'; else nd.style.cursor = 'pointer';
	nd.innerHTML = '新規アルバム';
	addEvent(nd, 'click', createAlbum);
	addEvent(nd, 'mouseover', albumMouseOver);
	addEvent(nd, 'mouseout', albumMouseOut);
	o.appendChild(nd);
	sepaAdd = true;
	albums = text.split("\n");
	for (i in albums) {
		album = albums[i].split(' = ');
		if (album.length < 3) continue;
		if (album[0].length == 0) continue;
		if (sepaAdd) {
			nd = document.createElement('hr');
			o.appendChild(nd);
			sepaAdd = false;
		}
		nd = document.createElement('div');
		nd.albumId = album[0];
		if (album[2] == 1) nd.inAlbum = 1;
		nd.style.padding = '5px';
		if (MSIE) nd.style.cursor = 'hand'; else nd.style.cursor = 'pointer';
		nd.innerHTML = album[1] + (album[2] == '1' ? ' [削除]' : '');
		addEvent(nd, 'click', selAlbum);
		addEvent(nd, 'mouseover', albumMouseOver);
		addEvent(nd, 'mouseout', albumMouseOut);
		o.appendChild(nd);
	}
	addEvent(o, 'mouseover', noHideAlbums);
	addEvent(o, 'mouseout', startHideAlbums);
	displayAlbums();
	checkHideAlbums(100);
}
function selAlbum(e) {
	if (!(o = getEventObj(e))) return false;
	if (o.inAlbum)
		getHTML(root + 'alb_ph/delete/' + o.albumId + '/' + photoId + '/');
	else
		getHTML(root + 'alb_ph/post/' + o.albumId + '/' + photoId + '/');
	hideAlbums();
}
function albumMouseOver(e) {
	if (!(o = getEventObj(e))) return false;
	o.style.backgroundColor = '#eeeeee';
	noHideGroups();
}
function albumMouseOut(e) {
	if (!(o = getEventObj(e))) return false;
	o.style.backgroundColor = '';
	startHideAlbums();
}
function displayAlbums() {
	disableNotes = true;
	o = getObj('albumPostDiv');
	r = getObj('root');
	o.style.top = getOffsetTop(r) + 20;
	o.style.border = '1px solid black';
	o.style.backgroundColor = 'white';
	o.style.padding = '5px';
	setStyleRec(o, 'zIndex', '5');
	setStyleRec(o, 'display', 'block');
	l = getOffsetLeft(r);
	if (r.offsetWidth > o.offsetWidth)
		l += (r.offsetWidth - o.offsetWidth) / 2;
	else
		l += 10;
	o.style.left = l;
}
function hideAlbums() {
	disableNotes = false;
	o = getObj('albumPostDiv');
	if (!o) return;
	for (i = o.childNodes.length - 1; i >= 0; i--)
		o.removeChild(o.childNodes[i]);
	o.style.display = 'none';
}
// albums end
// groups start
var groupsTimer = -1;
function noHideGroups() { groupsTimer = -1; }
function startHideGroups() { checkHideGroups(30); }
function checkHideGroups(time) {
	if (time) groupsTimer = time;
	if (groupsTimer >= 0) {
		groupsTimer--;
		if (!groupsTimer) hideGroups();
		else setTimeout('checkHideGroups()', 50);
	}
}
function openGroup(pid) {
	sendToFriendHide();
	hideGroups();
	if (groupsTimer > 0) {
		groupsTimer = -1;
		return;
	}
	o = getObj('groupPostDiv');
	nd = document.createElement('div');
	nd.style.margin = '10px';
	nd.innerHTML = 'ロード中...';
	o.appendChild(nd);
	displayGroups();
	getHTML(root + 'grp_ph/groups/0/' + pid, showGroups); 
}
function showGroups(text) {
	hideAlbums();
	hideGroups();
	o = getObj('groupPostDiv');
	groups = text.split("\n");
	groupsAdded = 0;
	for (i in groups) {
		group = groups[i].split(' = ');
		if (group.length < 3) continue;
		groupsAdded++;
		nd = document.createElement('div');
		nd.groupId = group[0];
		if (group[2] == 1) nd.inGroup = 1;
		nd.style.padding = '5px';
		if (MSIE) nd.style.cursor = 'hand'; else nd.style.cursor = 'pointer';
		nd.innerHTML = group[1] + (group[2] == '1' ? ' [削除]' : '');
		addEvent(nd, 'click', selGroup);
		addEvent(nd, 'mouseover', groupMouseOver);
		addEvent(nd, 'mouseout', groupMouseOut);
		o.appendChild(nd);
	}
	if (groupsAdded == 0) {
		nd = document.createElement('div');
		nd.style.padding = '5px';
		nd.innerHTML = 'あなたはグループに未参加です* <a href="groups/">グループ</a>';
		o.appendChild(nd);
	}
	addEvent(o, 'mouseover', noHideGroups);
	addEvent(o, 'mouseout', startHideGroups);
	displayGroups();
	checkHideGroups(100);
}
function selGroup(e) {
	if (!(o = getEventObj(e))) return false;
	if (o.inGroup)
		getHTML(root + 'grp_ph/delete/' + o.groupId + '/' + photoId + '/');
	else
		getHTML(root + 'grp_ph/post/' + o.groupId + '/' + photoId + '/');
	hideGroups();
}
function groupMouseOver(e) {
	if (!(o = getEventObj(e))) return false;
	o.style.backgroundColor = '#eeeeee';
	noHideGroups();
}
function groupMouseOut(e) {
	if (!(o = getEventObj(e))) return false;
	o.style.backgroundColor = '';
	startHideGroups();
}
function displayGroups() {
	disableNotes = true;
	o = getObj('groupPostDiv');
	r = getObj('root');
	o.style.top = getOffsetTop(r) + 20;
	o.style.border = '1px solid black';
	o.style.backgroundColor = 'white';
	o.style.padding = '5px';
	setStyleRec(o, 'zIndex', '5');
	setStyleRec(o, 'display', 'block');
	l = getOffsetLeft(r);
	if (r.offsetWidth > o.offsetWidth)
		l += (r.offsetWidth - o.offsetWidth) / 2;
	else
		l += 10;
	o.style.left = l;
}
function hideGroups() {
	disableNotes = false;
	o = getObj('groupPostDiv');
	if (!o) return;
	for (i = o.childNodes.length - 1; i >= 0; i--)
		o.removeChild(o.childNodes[i]);
	o.style.display = 'none';
}
// groups end
function addEvent(obj, ev, eh) {
	if (obj.addEventListener) obj.addEventListener(ev, eh, false);
	else if (obj.attachEvent) obj.attachEvent('on' + ev, eh);
}
function getEventObj(e) {
	if (e.originalTarget) return e.originalTarget;
	else if (e.srcElement) return e.srcElement;
	else return false;
}
// dynamic tags manage
function delTag(e, pid, tag) {
	if (!(o = getEventObj(e))) return false;
	o = o.parentNode;
	o.parentNode.removeChild(o);
	o = getObj('tagsList');
	while (o.childNodes.length) {
		t = o.childNodes[o.childNodes.length - 1];
		if (t.nodeName != 'SPAN')
			o.removeChild(t);
		else
			break;
	}
	o = o.childNodes[o.childNodes.length - 1];
	if (o.childNodes.length)
		t = o.childNodes[o.childNodes.length - 1];
	getHTML(root + 'upd_ph/?id='+photoId+'&delTag=' + encodeURIComponent(tag));
}
function showAddTag() {
	o = getObj('addTagDiv');
	setStyleRec(o, 'display', 'inline');
	o = getObj('tagInput');
	o.focus();
}
function hideAddTag() {
	o = getObj('addTagDiv');
	setStyleRec(o, 'display', 'none');
}
function doAddTag(tag) {
	hideAddTag();
	o = getObj('tagsList');
	a = getObj('addSpan');
	ns = document.createElement('span');
	ns.innerHTML = '<a href="'+userId+'/photos/tags/' + encodeURIComponent(tag) + '/">@</a>&nbsp;<a href="photos/tags/' + encodeURIComponent(tag) + '/">' + tag + '</a>'
	+ '&nbsp;[<a href="#" onclick="if (confirm(' + "'" + 'この写タグを本当に削除してもよろしいですか?' + "'" + ')) delTag(event, '+photoId+', ' + "'" + tag + "'" + '); return false;">x</a>]<br/>';
	o.insertBefore(ns, a);
	getHTML(root + 'upd_ph/?id='+photoId+'&addTag=' + encodeURIComponent(tag));
}
//-->
