
Array.prototype.remove=function(dx)
{if(isNaN(dx)||dx>this.length){return false;}
for(var i=0,n=0;i<this.length;i++)
{if(this[i]!=this[dx])
{this[n++]=this[i]}}
this.length-=1}
var tagframe_top=0,tagselector_top=0,tagresize_top=0,change_num=0;var showcasetag={ie:(navigator.appVersion.indexOf("MSIE")!=-1),ff:(navigator.userAgent.indexOf("Firefox")!=-1),xx:0,yy:0,gwidth:300,gheight:300,frameWidth:166,frameHeight:166,moveable:false,tagging:false,g_image_x:0,g_image_y:0,activeImageMouseX:0,activeImageMouseY:0,effectTagframe:null,effectSelect:null,setWidthAndHeight:function(width,height){try{this.gwidth=width;this.gheight=height;}catch(e){}},tagManager:{tagnum:0,tagInfo:[],isdel:false,showTagInfo:function(tagid){if(showcasetag.tagging==true){return;}
var taginfos=this.getTagInfo(tagid);if(taginfos!="-1"){var tagobj=null;if(!document.getElementById("tag_div")){tagobj=document.createElement("div");document.body.appendChild(tagobj);tagobj.setAttribute("id","tag_div");}else{tagobj=document.getElementById("tag_div");}
tagobj.style.position='absolute';tagobj.style.width="auto";tagobj.style.borderWidth='1px';tagobj.style.padding='5px';tagobj.style.fontColor='#000';tagobj.style.fontWeight='bold';tagobj.style.backgroundColor='#ffffcc';tagobj.innerHTML=taginfos.tagtext;var pos=showcasetag.getPos($("myphoto"));tagobj.style.left=(pos.x+taginfos.tagpos.x)+"px";tagobj.style.top=(pos.y+taginfos.tagpos.y)+"px";tagobj.style.display='';}},hiddenTagInfo:function(){if(showcasetag.tagging==true){return;}
if(document.getElementById("tag_div")){document.getElementById("tag_div").style.display='none';}},showTagArea:function(tagid){if(showcasetag.tagging==true){return;}
var taginfos=this.getTagInfo(tagid);if(taginfos=="-1"){return;}
if(typeof(taginfos.tagpos)!="undefined"&&taginfos!=null){var tagobj=$("tagframe");var pos=showcasetag.getPos($("myphoto"));var maxl=pos.x+this.gwidth;var minl=pos.x;var maxm=pos.y+this.gheight;var minm=pos.y;var left=pos.x+taginfos.tagpos.x+Math.ceil(taginfos.tagpos.width/2);var top=pos.y+taginfos.tagpos.y+Math.ceil(taginfos.tagpos.height/2);if(left>maxl){left=maxl;}
if(left<minl){left=minl;}
if(top>maxm){top=maxm;}
if(top<minm){top=minm;}
tagobj.style.left=(left-taginfos.tagpos.width-10)+"px";tagobj.style.top=(top-taginfos.tagpos.height-10-document.body.scrollTop)+"px";tagobj.style.width=taginfos.tagpos.width+"px";tagobj.style.height=taginfos.tagpos.height+"px";$("tagframeinside").style.width=(taginfos.tagpos.width-10)+"px";$("tagframeinside").style.height=(taginfos.tagpos.height-10)+"px";$("tagframe").style.display='';}},hiddenTagArea:function(){if(showcasetag.tagging==true){return;}
$("tagframe").style.display='none';},addTag:function(tagid,tagtext,tagpos){this.tagInfo.push({tagid:tagid,tagtext:tagtext,tagpos:tagpos});this.tagnum=this.tagInfo.length;var div=document.createElement("div");var div1=document.createElement("div");var div2=document.createElement("div");div.className="tagline";div1.className='tagline1';div2.className='tagline2';div.setAttribute("id","t_"+tagid);div2.setAttribute("id",tagid);div1.setAttribute("tagid",tagid);div.appendChild(div1);div1.innerHTML=tagtext;if(this.isdel==true){div2.innerHTML="(删除)";div2.onclick=function(){var tid=this.getAttribute("id");showcasetag.deletetag(tid);}}
div1.onmouseover=function(){var tid=this.getAttribute("tagid");showcasetag.tagManager.showTagArea(tid);}
div1.onmouseout=function(){showcasetag.tagManager.hiddenTagArea();}
div.appendChild(div2);$("tagboxs").appendChild(div);},delTag:function(tagid){var length=this.tagInfo.length;for(var i=0;i<length;i++){if(this.tagInfo[i]!=null&&this.tagInfo[i].tagid==tagid){this.tagInfo[i]=null;}}
var obj=document.getElementById("t_"+tagid);obj.parentNode.removeChild(obj);this.tagnum=this.tagInfo.length;showcasetag.tagManager.hiddenTagInfo();if(document.getElementById("tagboxs").getElementsByTagName("div").length==0){document.getElementById("tagboxs").innerHTML="暂无标记";}
var photoname=$("photo_name").value;if(!photosArray[photoname]){return;}
var length=photosArray[photoname].length;for(var i=0;i<length;i++){if(photosArray[photoname][i][0]==tagid){photosArray[photoname].remove(i);}}},getTagInfo:function(tagid){var length=this.tagInfo.length;for(var i=0;i<length;i++){if(this.tagInfo[i]!=null&&this.tagInfo[i].tagid==tagid){return this.tagInfo[i];}}
return"-1";},findTag:function(image,event){if(showcasetag.tagging==true){return;}
if($('tag_div')){var obj=$("tag_div");obj.parentNode.removeChild(obj);}
if(imageArrayLightbox.length>1)
showcasetag.changeCursorStyle(event,image);var pos=showcasetag.getPos(image);var mpos=showcasetag.getMousePos(event);activeImageMouseX=mpos.x-pos.x;activeImageMouseY=mpos.y-pos.y;cur_tag_num=-1;flag=-1;var length=this.tagInfo.length;for(i=0;i<length;i++){if(this.tagInfo[i]==null){continue;}
temp_distance_x=Math.abs(this.tagInfo[i].tagpos.x-activeImageMouseX);temp_distance_y=Math.abs(this.tagInfo[i].tagpos.y-activeImageMouseY);temp_distance_sum=temp_distance_x+temp_distance_y;if(temp_distance_x<83&&temp_distance_y<83){flag++;if(flag==0)min_distance_sum=temp_distance_sum;if(temp_distance_sum<=min_distance_sum){min_distance_sum=temp_distance_sum;cur_tag_num=i;}}}
if(cur_tag_num>=0){tag_div=document.createElement('div');tag_div.style.position='absolute';tag_div.style.width="auto";tag_div.style.borderWidth='1px';tag_div.style.padding='5px';tag_div.style.fontColor='#000';tag_div.style.fontWeight='bold';tag_div.style.backgroundColor='#ffffcc';tag_div.style.display='';tag_div.style.left=pos.x+parseInt(this.tagInfo[cur_tag_num].tagpos.x)+"px";tag_div.style.top=pos.y+parseInt(this.tagInfo[cur_tag_num].tagpos.y-document.body.scrollTop)+"px";tag_div.setAttribute('id',"tag_div");document.body.appendChild(tag_div);tag_div.innerHTML=this.tagInfo[cur_tag_num].tagtext;}}},updateMoveDiv:function(){$("size_4").style.display="";pos=showcasetag.getPos($("tagframe"));$("size_4").style.top=(pos.y+showcasetag.frameHeight+10)+"px";if(document.body.scrollTop!=0){tagresize_top=pos.y+showcasetag.frameHeight+10+document.body.scrollTop;}else{tagresize_top=pos.y+showcasetag.frameHeight+10;;}
$("size_4").style.left=(pos.x+showcasetag.frameWidth+10)+"px";},getMousePos:function(e){var posx=0;var posy=0;if(!e)var e=window.event;if(e.pageX){posx=e.pageX;posy=e.pageY;}
else if(e.clientX&&document.body.scrollLeft){posx=e.clientX+document.body.scrollLeft;posy=e.clientY+document.body.scrollTop;}
else if(e.clientX&&document.documentElement.scrollLeft){posx=e.clientX+document.documentElement.scrollLeft;posy=e.clientY+document.documentElement.scrollTop;}
else if(e.clientX){posx=e.clientX;posy=e.clientY;}
return{x:posx,y:posy};},getPos:function(e)
{var left=0;var top=0;var scrolls=this.get_scroll(e);while(e.offsetParent){left+=e.offsetLeft+(e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);top+=e.offsetTop+(e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);e=e.offsetParent;}
left+=e.offsetLeft+(e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);top+=e.offsetTop+(e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);left=left-scrolls.left;top=top-scrolls.top;return{x:left,y:top};},get_scroll:function(o)
{var of=new Array();var x=0;var y=0;if(o.parentNode!=null)
{var par=o.parentNode
while(par!=document.body)
{x+=par.scrollLeft;y+=par.scrollTop;par=par.parentNode;}}
return{left:x,top:y};},startDrag:function(e){var theEvent=window.event||e;var tagframe=$('tagframe');var selector=$('selector');tagframe_x0=theEvent.clientX;tagframe_y0=theEvent.clientY;tagframe_x1=parseInt(tagframe.offsetLeft);tagframe_y1=parseInt(tagframe.offsetTop);selector_x0=theEvent.clientX;selector_y0=theEvent.clientY;selector_x1=parseInt(selector.offsetLeft);selector_y1=parseInt(selector.offsetTop);document.onmousemove=hh_drag
document.onmouseup=ss_drag
document.onselectstart=function(){return false}
this.moveable=true;if(this.ff){this.xx=document.documentElement.scrollLeft+theEvent.layerX;this.yy=document.documentElement.scrollTop+theEvent.layerY;if(document.documentElement.scrollTop>0){this.yy=theEvent.layerY-document.documentElement.scrollTop;}
if(document.documentElement.scrollLeft>0){this.xx=theEvent.layerX-document.documentElement.scrollLeft;}}
if(this.ie){this.xx=document.documentElement.scrollLeft+theEvent.offsetX;this.yy=document.documentElement.scrollTop+theEvent.offsetY;if(document.documentElement.scrollTop>0){this.yy=theEvent.offsetY-document.documentElement.scrollTop;}
if(document.documentElement.scrollLeft>0){this.xx=theEvent.offsetX-document.documentElement.scrollLeft;}}},stopDrag:function(e){var theEvent=window.event||e;if(this.moveable){if(this.tagging){image=$('myphoto');var tagframe=$('tagframe');tagframe.style.left=theEvent.clientX-this.xx+"px";tagframe.style.top=theEvent.clientY-this.yy+"px";var pos=this.getPos(image);this.activeImageMouseX=parseInt(tagframe.style.left)+this.frameWidth/2-pos.x;this.activeImageMouseY=parseInt(tagframe.style.top)+this.frameHeight/2-pos.y+document.body.scrollTop;this.updateFrame(image,this.activeImageMouseX,this.activeImageMouseY);this.updateMoveDiv();}
this.moveable=false;}
document.onmouseup=null;document.onmousemove=null;document.onselectstart=function(){return true}},drag:function(e){var theEvent=window.event||e;if(this.moveable){var image=$('myphoto');var tagframe=$('tagframe');var selector=$('selector');$('selector').style.display='none';tagframe.style.left=theEvent.clientX-this.xx+"px";tagframe.style.top=theEvent.clientY-this.yy+"px";this.updateMoveDiv();var imgpos=this.getPos(image);if(parseInt(tagframe.style.left)<imgpos.x||parseInt(tagframe.style.left)+this.frameWidth>imgpos.x+image.width||parseInt(tagframe.style.top)<(imgpos.y-document.body.scrollTop)||parseInt(tagframe.style.top)+this.frameHeight>(imgpos.y+image.height-document.body.scrollTop)){this.stopDrag(theEvent);this.moveable=false;return false;}
selector.style.left=theEvent.clientX-this.xx+"px";selector.style.top=theEvent.clientY-this.yy+"px";}
return false;},updateFrame:function(image,imageMouseX,imageMouseY){this.g_image_x=this.activeImageMouseX;this.g_image_y=this.activeImageMouseY;var imgpos=this.getPos(image);imageMinX=imgpos.x;imageMinY=imgpos.y;imageMaxX=imageMinX+image.width;imageMaxY=imageMinY+image.height;frameX=imgpos.x+imageMouseX;frameY=imgpos.y+imageMouseY;if(frameX<imageMinX+(this.frameWidth/2))
frameX=imageMinX+(this.frameWidth/2)+5;if(frameY<imageMinY+(this.frameHeight/2))
frameY=imageMinY+(this.frameHeight/2)+5;if(frameX>imageMaxX-(this.frameWidth/2))
frameX=imageMaxX-(this.frameWidth/2)-5;if(frameY>imageMaxY-(this.frameHeight/2))
frameY=imageMaxY-(this.frameHeight/2)-5;var tagMinX=frameX-(this.frameWidth/2)-8;var tagMinY=frameY-(this.frameHeight/2)-8-document.body.scrollTop;$('tagframe').style.left=tagMinX+"px";$('tagframe').style.top=tagMinY+"px";tagframe_top=tagMinY<0?0:tagMinY;if(imageMouseX<this.gwidth){$('selector').style.left=(tagMinX+this.frameWidth+16+10)+"px";}else{$('selector').style.left=(tagMinX-this.gwidth-(this.frameWidth/2))+"px";}
$('selector').style.top=tagMinY<0?0:tagMinY+"px";tagselector_top=tagMinY<0?0:tagMinY;if(document.body.scrollTop!=0){tagframe_top+=document.body.scrollTop;tagselector_top+=document.body.scrollTop;}
$('selector').style.display='';$('tagframe').style.display='';$('tag_text').value="";FindTagText();},startTag:function(){this.tagging=true;},reset:function(){this.frameWidth=165;this.frameHeight=165;var pos=this.getPos($("myphoto"));$("tagframe").style.left=(pos.x+10)+'px';$("tagframe").style.top=(pos.y+10)+'px';$("tagframe").style.height="165px";$("tagframe").style.width="165px";$("tagframeinside").style.width="160px";$("tagframeinside").style.height="160px";},imageClick:function(event,image){var mousepos=this.getMousePos(event);var pos=this.getPos(image);this.activeImageMouseX=mousepos.x-pos.x;this.activeImageMouseY=mousepos.y-pos.y+document.body.scrollTop;if(this.tagging==false){if(imageArrayLightbox.length>1){var intWidth=image.width;var array_num=imageArrayLightbox.length-1;var intLeft=image.getBoundingClientRect()["left"]-2;if(activeImageMouseX>intWidth/2){change_num=change_num+1;}else{change_num=change_num-1;}
if(change_num>array_num){change_num=0;}else if(change_num<0){change_num=array_num;}
image.src=imageArrayLightbox[change_num][0];}
return false;}
this.updateFrame(image,this.activeImageMouseX,this.activeImageMouseY);this.updateMoveDiv();return false;},tagok:function(){this.tagging=false;if(this.g_image_x<(this.frameWidth/2)){this.g_image_x=(this.frameWidth/2);}
if(this.g_image_x>this.gwidth-(this.frameWidth/2)){this.g_image_x=this.gwidth-(this.frameWidth/2);}
if(this.g_image_y<(this.frameHeight/2)){this.g_image_y=(this.frameHeight/2);}
if(this.g_image_y>(this.gheight-this.frameHeight/2)){this.g_image_y=(this.gheight-this.frameHeight/2);}
var g_image_x=this.g_image_x;var g_image_y=this.g_image_y;var ww=this.frameWidth;var hh=this.frameHeight;var url="/ajax/showcase.php";var par=[];var pars="act=addtag";var case_id=$("case_id").value;if(case_id==""){return;}
var tagtext=$("tag_text").value;par.push(pars);pars="x="+g_image_x;par.push(pars);pars="y="+g_image_y;par.push(pars);pars="width="+showcasetag.frameWidth;par.push(pars);pars="height="+showcasetag.frameHeight;par.push(pars);pars="tagtext="+encodeURIComponent(tagtext);par.push(pars);pars="case_id="+case_id;par.push(pars);var photo_name=$("photo_name").value;pars="photo_name="+photo_name;par.push(pars);pars=par.join("&");var ajax=new Ajax.Request(url,{method:"post",parameters:pars,onComplete:function(e){showcasetag.taghidden();var temp=eval("("+e.responseText+")");if(temp.rtn_code=="nosession"){}else if(temp.rtn_code=="1"){$("tagmsginfo").innerHTML="标记成功";new Effect.Highlight("tagmsginfo",{afterFinish:function(){$("tagmsginfo").style.display='none';$("tagmsginfo1").style.display=""}});try{showcasetag.tagManager.addTag(temp.tagid,temp.tagtext,{x:g_image_x,y:g_image_y,width:ww,height:hh});if(!photosArray[photo_name]){photosArray[photo_name]=[];}
photosArray[photo_name][photosArray[photo_name].length]=[temp.tagid,temp.tagtext,g_image_x,g_image_y,ww,hh];var length=alltags.length;for(var i=0;i<length;i++){if(alltags[i]==temp.tagtext){return;}}
alltags.push(temp.tagtext);}catch(e){e.message}}else if(temp.rtn_code=="0"){$("tagmsginfo").innerHTML="标记失败";new Effect.Highlight("tagmsginfo",{afterFinish:function(){$("tagmsginfo").style.display='none';$("tagmsginfo1").style.display=""}});}
$("tag_text")="";}});this.g_image_x=0;this.g_image_y=0;},tagcancel:function(){$("tagmsginfo").innerHTML="取消标记";new Effect.Highlight("tagmsginfo",{afterFinish:function(){$("tagmsginfo").style.display='none';$("tagmsginfo1").style.display=""}});this.tagging=false;this.taghidden();},deletetag:function(tagid){var url="/ajax/showcase.php";var par=[];var pars="act=deltag";var case_id=$("case_id").value;if(case_id==""){return;}
par.push(pars);pars="case_id="+case_id;par.push(pars);pars="tagid="+tagid;par.push(pars);pars=par.join("&");var deltagid=tagid;var ajax=new Ajax.Request(url,{method:"post",parameters:pars,onComplete:function(e){var temp=eval("("+e.responseText+")");if(temp.rtn_code=="nosession"){}else if(temp.rtn_code=="1"){showcasetag.tagManager.delTag(deltagid);var objs=$("sel_"+deltagid);objs.parentNode.removeChild(objs);}}});},taghidden:function(){$('selector').style.display='none';$('tagframe').style.display='none';$("size_4").style.display="none";},changeCursorStyle:function(event,image){var event=window.event||event;activeImageMouseX=mousePosX(event)-findX(image);activeImageMouseY=mousePosY(event)-findY(image);if(activeImageMouseX>image.width/2){if(!image.style.cursor.match("next"))
image.style.cursor='url("'+static_url_prefix+'/images/common/next.cur"), pointer';if(image.alt!="点击跳到下一张")
image.alt="点击跳到下一张";}
else if(activeImageMouseX<=image.width/2){if(!image.style.cursor.match("pre"))
image.style.cursor='url("'+static_url_prefix+'/images/common/prev.cur"), pointer';if(image.alt!="点击跳到上一张")
image.alt="点击跳到上一张";}}};function hh_drag(event){showcasetag.drag(event);}
function ss_drag(event){showcasetag.stopDrag(event);}