var TagDisplay={refSize:13000};function drawMemberTag(tag){var out='<a class="plain" href="'+tag.profileUrl+'">'+escapeXML(tag.tag)+'</a>';return out;}
function drawTags(photo){var tagsDiv=$(tagsIdFromPhotoId(photo.id));if(!tagsDiv)return;var tags=photo.tags;if(tags&&tags.length){var content='';var tagContentArr=[];var meTagCount=dojo.filter(tags,function(tag){return(tag.uhid==curUhid);}).length;for(var i=0;i<tags.length;i++){var tag=tags[i];tagContent='<span class="photoTagItem">';tagContent+='<span class="photoTag" onmouseover="showTagFrameById('+tag.photo_id+','+tag.tag_id+')" onmouseout="hideTagFrame()">';if(tag.uhid!='0'){tagContent+=drawMemberTag(tag);}else{tagContent+=escapeXML(tag.tag);}
tagContent+='</span>';if(tagger&&tagger.currentView!=2){var owned=(photo.photo_owner==curUhid);var tagged=(tag.tagger_uhid==curUhid);var isMe=(tag.uhid==curUhid);if(owned||tagged||isMe){var checkRemove='';tagContent+=' (';if(isMe){if(meTagCount<=1){checkRemove="if (!confirm('Deleting this tag will remove this photo from \\'Photos of You\\'.  Do you want to continue?')) return false; ";}
if(photo.perms&&document.getElementById('tagPermsBox')){tagContent+='<a class="plain" href="javascript:;"  onclick="tagger.showPermsBox(this, \'Save\', function() { imageArr[heart.indexOfKey(imageArr, \'id\', '+photo.id+')].perms = tagger.getBoxPerms(); tagger.updateTagPerms('+photo.id+', '+photo.photo_owner+'); return false; }, imageArr[heart.indexOfKey(imageArr, \'id\', '+photo.id+')].perms);">edit tag</a> | ';checkRemove+="tagger.hidePermsBox(); ";}}
tagContent+='<a class="plain" href="javascript:;" onclick="'+checkRemove+'tagger.removeTag('+tag.photo_id+','+tag.tag_id+','+photo.photo_owner+');">delete tag</a>)';}}
if(i<(tags.length-1)){tagContent+=', ';}
tagContent+='</span>';tagContentArr.push(tagContent);}
content+=tagContentArr.join('');tagsDiv.innerHTML=content;}
else{tagsDiv.innerHTML="";}}
function scaleTagToImg(tag,photo,img){if(photo.type===0||tag.scaledToImg)return;img=img||$(imgIdFromPhotoId(photo.id));scaleTag(tag,TagDisplay.refSize,TagDisplay.refSize,img.width,img.height);tag.scaledToImg=true;}
function scaleTagFromImg(tag,photo,img){if(photo.type===0||!tag.scaledToImg)return;img=img||$(imgIdFromPhotoId(photo.id));scaleTag(tag,img.width,img.height,TagDisplay.refSize,TagDisplay.refSize);tag.scaledToImg=false;}
function scaleTag(tag,fromWidth,fromHeight,toWidth,toHeight){var scaleX=toWidth/fromWidth;var scaleY=toHeight/fromHeight;tag.tl_x=Math.round(tag.tl_x*scaleX);tag.tl_y=Math.round(tag.tl_y*scaleY);tag.br_x=Math.round(tag.br_x*scaleX);tag.br_y=Math.round(tag.br_y*scaleY);if(tag.br_x>toWidth)tag.br_x=toWidth;if(tag.br_y>toHeight)tag.br_y=toHeight;}
function showTagFrame(tag,photo,img){if(tag===curTagShowing)return;curTagShowing=tag;scaleTagToImg(tag,photo);var borderWidth=3;var imgOffset=dojo.coords(img,true);var frame=$('tagFrame');frame.style.borderWidth=borderWidth+"px";frame.style.left=(imgOffset.x+tag.tl_x-borderWidth)+'px';frame.style.top=(imgOffset.y+tag.tl_y-borderWidth)+'px';frame.style.height=(tag.br_y-tag.tl_y)+'px';frame.style.width=(tag.br_x-tag.tl_x)+'px';var label=$('tagLabel');var labelContent=$('tagLabelContent');label.style.left=frame.style.left;label.style.top=(imgOffset.y+tag.br_y)+'px';labelContent.innerHTML=escapeXML(tag.tag);document.body.appendChild(frame);document.body.appendChild(label);show(frame);show(label);}
function showTagFrameById(photoId,tagId){var iPhoto=heart.indexOfKey(imageArr,"id",photoId);if(iPhoto<0)return;var photo=imageArr[iPhoto];var imgId=imgIdFromPhotoId(photo.id);var tags=photo.tags;var iTag=heart.indexOfKey(tags,"tag_id",tagId);if(iTag<0)return;showTagFrame(tags[iTag],photo,$(imgId));}
function hideTagFrame(){if(curTagShowing){curTagShowing=null;hide($('tagFrame'));hide($('tagLabel'));}}
function tagHasCoords(tag,x,y,photo){scaleTagToImg(tag,photo);return x>tag.tl_x&&x<=tag.br_x&&y>tag.tl_y&&y<=tag.br_y;}
function getTagFromCoords(tags,x,y,photo){for(var i=0;i<tags.length;++i){if(tagHasCoords(tags[i],x,y,photo)){return tags[i];}}
return null;}
function tag_handlePhotoMouseMove(photoId,e){var iPhoto=heart.indexOfKey(imageArr,"id",photoId);if(iPhoto<0)return;var photo=imageArr[iPhoto];var tags=photo.tags;if(tags&&tags.length){dojo.fixEvent(e);var x=e.layerX;var y=e.layerY;var tag=getTagFromCoords(tags,x,y,photo);if(tag){showTagFrame(tag,photo,e.target);}else{hideTagFrame();}}}
function tag_handlePhotoLinkClick(photoId){return!(tagger&&tagger.showing()&&(tagger.photoId==photoId));}