//相册操作
var Album=
{
    //相册操作
    Album:
    {
        //删除
        Delete:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            Confirm(obj,"确定删除该相册吗?","删除",f1);
            function f1()
            {
                setConfirmMSG("正在执行删除操作...");
                var URL=obj.getAttribute("rel");
                runAjax(URL);
            }
        },
        
        //分享
        Share:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            eval("ShowShareDiv("+obj.getAttribute("value")+")");
        }
    },
    
    
    //照片操作
    Photo:
    {
        //删除照片
        Delete:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            Confirm(obj,"确定删除该照片吗?","删除",f1);
            function f1()
            {
                setConfirmMSG("正在执行删除操作...");
                var URL=obj.getAttribute("rel");
                var options={
					method:'get',
					parameters:"",
					onComplete:
					function(transport)
					{
						var returnvalue=transport.responseText;
						if(returnvalue!="")
						{
							eval(returnvalue);
						}
						else
						{
							if(obj.getAttribute("redirect")!=""&&obj.getAttribute("redirect")!=null)
							{
								location.href=obj.getAttribute("redirect");
							}
						}
					} 
	            }
	            new Ajax.Request(URL,options);
            }
        },
        
        //开始圈人
        Quanren:function()
        {
            var mw=100;
            var mh=120;
	        if(document.getElementById("quanquan"))
	        {
	            return;
	        }
            var event=getEvent();
            var obj=event.srcElement||event.target;
            var eURL=obj.getAttribute("rel");
            var Img=document.getElementById("photo-holder");
            var orgURL=Img.parentNode.getAttribute("href");
            var objP=Img.parentNode.parentNode;
            var orgHTML=objP.innerHTML;
            objP.innerHTML=Img.parentNode.innerHTML;
            Img=document.getElementById("photo-holder");
            Img.setAttribute("orgURL",orgURL);
            
            window.scrollTo(0,0);
            var imgXY=getXY(Img);
            var x0=0;
            var y0=0;
            var returnX=0;
            var returnY=0;
            var ex0=0;
            var ey0=0;
            var zhezhaoceng=document.getElementById("zhezhaoceng");
            if(!zhezhaoceng)
            {
                 zhezhaoceng=document.createElement("DIV");
	        	 zhezhaoceng.setAttribute("id","zhezhaoceng");
	        	 zhezhaoceng.className="zhezhaoceng";
	        	 document.body.appendChild(zhezhaoceng);
            }
            zhezhaoceng.style.backgroundColor="#ffffff";
            zhezhaoceng.style.left=imgXY.X+"px";
            zhezhaoceng.style.top=imgXY.Y+"px";
            zhezhaoceng.style.width=Img.width+"px";
            zhezhaoceng.style.height=Img.height+"px";
            
            var quanObj=document.getElementById("quanquan");
	        if(!quanObj)
	        {
		        quanObj=document.createElement("DIV");
	        	quanObj.setAttribute("id","quanquan");
	        	quanObj.setAttribute("moveable","false");
	        	quanObj.innerHTML="双击圈定<br />移动框可以改变大小";
	        	quanObj.style.backgroundImage="url("+Img.src+")";
	        	quanObj.style.overflow="hidden";
	        	x0=imgXY.X+3;
	        	y0=imgXY.Y+3;
	        	quanObj.style.left=x0+"px";
	        	quanObj.style.top=y0+"px";
		        document.body.appendChild(quanObj);
	        }
	        quanObj.onmousedown=function()
	        {
	            var event=getEvent();
	            quanObj.setAttribute("moveable","true");
	            ex0=event.clientX;
	        	ey0=event.clientY+windowScrollTop();
	       }
            
            quanObj.onmousemove=mmove;
            
            function mmove()
            {
                var event=getEvent();
                var eex0=event.clientX;
                var eey0=event.clientY+windowScrollTop();
               
                var xxx=quanObj.offsetWidth-eex0+x0;
                var yxx=quanObj.offsetHeight-eey0+y0;
        	    if((xxx)<8&&(yxx)<8)
        	    {
        	        quanObj.style.cursor="se-resize";
        	       
        	    }
        	    else
        	    {
        	    quanObj.style.cursor="";
        	    }
                if(eval(quanObj.getAttribute("moveable")))
                {
                    quanObj.innerHTML="";
                    var offsetX=event.clientX-ex0;
                    var offsetY=event.clientY+windowScrollTop()-ey0;
                    
                    ex0=event.clientX;
                    ey0=event.clientY+windowScrollTop();
                    
                    var xxx=quanObj.offsetWidth-ex0+x0;
                    var yxx=quanObj.offsetHeight-ey0+y0;
	        	    if((xxx)<8&&(yxx)<8)
	        	    {   
	        	        if(ex0>(Img.width+imgXY.X-5)||ey0>(Img.height+imgXY.Y-5))
	        	        {
	        	            return;
	        	        }
	        	        quanObj.style.cursor="hand";
	        	        mw=quanObj.offsetWidth+offsetX-xxx+2;
	        	        mh=quanObj.offsetHeight+offsetY-yxx+2;
	        	        
	        	        quanObj.style.width=mw+"px";
	        	        quanObj.style.height=mh+"px";
	        	        return;
	        	    }
	        	    quanObj.style.cursor="";
	        	    
                    x0=x0+offsetX;
	        	    y0=y0+offsetY;
	        	    
	        	    returnX=x0-imgXY.X;
	        	    returnY=y0-imgXY.Y;
	        	    
	        	    //document.title=returnX+","+returnY;
	        	    quanObj.style.backgroundImage="url("+Img.src+")";
	                quanObj.style.backgroundPositionX="-"+returnX+"px";
	                quanObj.style.backgroundPositionY="-"+returnY+"px";
	                quanObj.style.padding="0px 0px 0px 0px";
	                /*firefox*/
	                //var baifenX=Math.round((returnX+50)*100)/Img.width+"%";
	                //var baifenY=Math.round((returnY+60)*100)/Img.height+"%";
	                //var baifenX=Math.round((returnX+quanObj.clientWidth/2)*100/Img.width)+"%";
	                //var baifenY=Math.round((returnY+quanObj.clientHeight/2)*100/Img.height)+"%";
	                var baifenX=Math.round(returnX*mw/(Img.width-mw))+"%"
	                var baifenY=Math.round(returnY*mh/(Img.height-mh))+"%"
	                //document.title=baifenX+","+baifenY;
	                //document.Title=baifenX+":"+baifenY
	                quanObj.setAttribute("style","top:"+y0+"px;left:"+x0+"px;padding:0px;width:"+quanObj.clientWidth+"px;height:"+quanObj.clientHeight+"px;background-repeat:no-repeat;background-image:url("+Img.src+");background-position:"+baifenX+" "+baifenY+"");
	                /*firefox end*/
	        	    if(x0<(imgXY.X+Img.width-quanObj.offsetWidth-2)&&y0<(imgXY.Y+Img.height-quanObj.offsetHeight-2)&&x0>imgXY.X+2&&y0>imgXY.Y+2)
	        	    {
                        quanObj.style.left=x0+"px";
                        quanObj.style.top=y0+"px";
                    }
                    else
                    {
                        x0=x0-offsetX;
	        	        y0=y0-offsetY;
                    }
                }
            }
            quanObj.onmouseup=function()
            {
                quanObj.setAttribute("moveable","false");
            }
            
            quanObj.onmouseout=function()
            {
                quanObj.setAttribute("moveable","false");
            }
            
            quanObj.onselect=function()
            {
                return false;
            }

            function getSmall(x,y)
            {
                if(x>y)
                {
                    return y;
                }
                else
                {
                    return x;
                }
            }
            quanObj.ondblclick=function()
            {
                var w=quanObj.offsetWidth;
                var h=quanObj.offsetHeight;
                var quanBox=document.getElementById("quanquanBox");
	            if(!quanBox)
	            {
		              quanBox=document.createElement("DIV");
	        	      quanBox.setAttribute("id","quanquanBox");
	        	      document.body.appendChild(quanBox);
	            }
				document.body.removeChild(quanObj);
                objP.innerHTML=orgHTML;
                 
				quanBox.innerHTML="";
				quanBox.style.left=x0+"px";
				quanBox.style.top=y0+"px";
				  
				var searchStr="";
				try
				{
					searchStr=eURL.split("?")[1];
				}
				catch(e){}
				searchStr=searchStr.replace(/\action\=[^\&]*/gi,"");
				searchStr="action=Quanquanbox"+"&x="+returnX+"&y="+returnY+"&w="+w+"&h="+h+searchStr;
				new Ajax.Request(RootDir+"/inc/Ajax/album/PhotoOperator.aspx",{method:'get',parameters:searchStr,onComplete:function(transport)
				{
				  quanBox.innerHTML=transport.responseText;
				  var Img=document.getElementById("photo-holder");
				  var parm=Img.getAttribute("value");
				  var parray=parm.split("|");
				  var arr=new Array();
				  for(var ai=0;ai<parray.length;ai++)
				  {
				    arr[arr.length]=parray[ai].split(",")[0];
				  }
				  try
				  {
	                var form=document.forms["quanren"];
			        var inputs=form.quanren_friend;
			        //alert(arr);
				    for(var i=0;i<inputs.length;i++)
                    {
                        for(var j=0;j<arr.length;j++)
                        {
                            if(arr[j]==inputs[i].getAttribute("key"))
                            {
                                inputs[i].parentNode.parentNode.removeChild(inputs[i].parentNode);
                                break;
                            }
                        }                        
                    }
                    }catch(e){}
				}}); 
				var zhezhaoceng=document.getElementById("zhezhaoceng");
				if(zhezhaoceng)
                {
                    document.body.removeChild(zhezhaoceng);
                }         
            }
            quanObj.onselectstart=function()
            {
                return false;
            }
            //var quan="";
        },
        
        quanrenformSearch:function()
        {
            var form=document.forms["quanren"];
            var v=form.name.value;
            var inputs=form.quanren_friend;
            
            for(var i=0;i<inputs.length;i++)
            {
                if(inputs[i].value.indexOf(v)==-1)
                {
                   inputs[i].parentNode.style.display="none";
                }
                else
                {
                    inputs[i].parentNode.style.display="block";
                }
            }
        },
        /* 圈人的表单操作*/        
        quanrenformSelect:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            var form=obj.form;
            form.name.value=obj.value;
            form.n.value=obj.getAttribute("key");
            var chks=form.quanren_friend;
            for(var i=0;i<chks.length;i++)
            {
                if(chks[i]!=obj)
                {
                    chks[i].checked=false;
                }
            }
        },
        
        quanrenformSubmit:function()
        {
            var form=document.forms["quanren"];
            var x=form.x.value;
            var y=form.y.value;
            var r=form.r.value;
            var u=form.u.value;
            var n=form.n.value;
            var w=form.w.value;
            var h=form.h.value;
            var URL=RootDir+"/inc/Ajax/album/PhotoOperator.aspx";
            var options={method:'get',parameters:"action=quan&x="+x+"&y="+y+"&r="+r+"&u="+u+"&n="+n+"&w="+w+"&h="+h,onComplete:function(transport)
					{
						var returnvalue=transport.responseText;

						if(returnvalue=="1")
						{
						   	alert("圈人成功");
						   	location.reload();  
						}
						else
						{
						    alert("圈人失败\n或许是您的好友已经在此照片中被圈了");
						}
						var quanBox=document.getElementById("quanquanBox");
                        document.body.removeChild(quanBox); 
					} 
	            }
	            new Ajax.Request(URL,options);
        },
        
        quanrenformCancle:function()
        {
            var quanBox=document.getElementById("quanquanBox");
            document.body.removeChild(quanBox);
            
        },
        /*圈人的表单操作结束 */
        
        //鼠标在名字上时的效果
        quanquanview:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            var Img=document.getElementById("photo-holder");
            var imgXY=getXY(Img);
            var parm=obj.getAttribute("value");
            var v=parm.split(",");
            var px=parseInt(v[2]);
            var py=parseInt(v[3]);
            var pw=0;
            var ph=0;
            if(v.length>4)
            {
                pw=parseInt(v[4]);
            }
            if(v.length>5)
            {
                ph=parseInt(v[5]);
            }
            var x=imgXY.X+px;
            var y=imgXY.Y+py;
            var zhezhaoceng=document.getElementById("zhezhaoceng");
            if(!zhezhaoceng)
            {
                 zhezhaoceng=document.createElement("DIV");
	        	 zhezhaoceng.setAttribute("id","zhezhaoceng");
	        	 zhezhaoceng.className="zhezhaoceng";
	        	 document.body.appendChild(zhezhaoceng);
            }
            zhezhaoceng.style.backgroundColor="#ffffff";
            zhezhaoceng.style.left=imgXY.X+"px";
            zhezhaoceng.style.top=imgXY.Y+"px";
            zhezhaoceng.style.width=Img.width+"px";
            zhezhaoceng.style.height=Img.height+"px";
            var quanquanviewbox=document.getElementById("quanquanviewbox");
            if(!quanquanviewbox)
            {
                 quanquanviewbox=document.createElement("DIV");
	        	 quanquanviewbox.setAttribute("id","quanquanviewbox");
	        	 document.body.appendChild(quanquanviewbox);
            }
            
            quanquanviewbox.style.left=x+"px";
            quanquanviewbox.style.top=y+"px";
            quanquanviewbox.style.backgroundRepeat="no-repeat";
            quanquanviewbox.style.backgroundImage="url("+Img.src+")";
	        quanquanviewbox.style.backgroundPositionX="-"+px+"px";
	        quanquanviewbox.style.backgroundPositionY="-"+py+"px";
	        if(pw!=0&&ph!=0)
	        {
	            quanquanviewbox.style.width=pw+"px";
                quanquanviewbox.style.height=ph+"px";
	        }
	        quanquanviewbox.style.padding="0px 0px 0px 0px";
	        var baifenX=Math.round(px*100/(Img.width-100))+"%"
	        var baifenY=Math.round(py*100/(Img.height-120))+"%"
	        quanquanviewbox.setAttribute("style","top:"+y+"px;left:"+x+"px;padding:0px;background-repeat:no-repeat;background-image:url("+Img.src+");background-position:"+baifenX+" "+baifenY+"");
	        /*firefox end*/
            obj.onmouseout=function()
            {
                if(quanquanviewbox)
                {
                    document.body.removeChild(quanquanviewbox);
                }
                if(zhezhaoceng)
                {
                    document.body.removeChild(zhezhaoceng);
                }
            }
        },
        ///鼠标在照片上时的效果
        quanquanviewphoto:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            var Img=document.getElementById("photo-holder");
            var imgXY=getXY(Img);
            var parm=obj.getAttribute("value");
            var v=parm.split("|");
            var pw=100;
            var ph=120;
           
            Img.onmousemove=function()
            {
            var event=getEvent();
            var cx=event.clientX;
            var cy=event.clientY+windowScrollTop();
            
            for(var i=0;i<v.length;i++)
            {
                var vs=v[i].split(",");
                var xx=cx-parseInt(vs[2])-imgXY.X;
                var yy=cy-parseInt(vs[3])-imgXY.Y;
                if(vs.length>4)
                {
                    pw=parseInt(vs[4]);
                }
                if(vs.length>5)
                {
                    ph=parseInt(vs[5]);
                }
                if(pw==0)
                {
                    pw=100
                }
                if(ph==0)
                {
                    ph=120
                }
                if(xx>=0&&xx<pw&&yy>=0&&yy<ph)
                {
                    
                    var quanquanviewphotobox=document.getElementById("quanquanviewphotobox");
                    
					if(!quanquanviewphotobox)
					{
						 quanquanviewphotobox=document.createElement("DIV");
						 quanquanviewphotobox.setAttribute("id","quanquanviewphotobox");
						 document.body.appendChild(quanquanviewphotobox);
					}
					var viewx=imgXY.X+parseInt(vs[2])+(pw/2-10);
					var viewy=imgXY.Y+parseInt(vs[3])+(ph/2-10);
					//document.title=pw+","+ph;
					quanquanviewphotobox.style.left=viewx+"px";
					quanquanviewphotobox.style.top=viewy+"px";
					quanquanviewphotobox.innerHTML=vs[1];
					break;
                }
                else
                {
                     var quanquanviewphotobox=document.getElementById("quanquanviewphotobox");
                     if(quanquanviewphotobox)
                     {
                         document.body.removeChild(quanquanviewphotobox);
                     }
                }
            }
            }
            
            obj.onmouseout=function()
            {
                var quanquanviewphotobox=document.getElementById("quanquanviewphotobox");
                if(quanquanviewphotobox)
                {
                    document.body.removeChild(quanquanviewphotobox);
                }
            }
        },
        
        //删除圈圈
        plsodelete:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            Confirm(obj,"确定删除圈人吗?","删除",f1);
            function f1()
            {
                setConfirmMSG("正在执行删除操作...");
                var URL=obj.getAttribute("rel");
                runAjax(URL);
                setTimeout("closeConfirm();location.reload()",500);
            }
        },
        
        //分享
        Share:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            eval("ShowShareDiv("+obj.getAttribute("value")+")");
        },
        
        //评论
        CommentAdd:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            var URL=obj.getAttribute("rel");
            obj.form.onsubmit=function()
            {
                return false;
            }
//            var   oEditor   =   FCKeditorAPI.GetInstance('body1')   ;   
//            var   Content   =   oEditor.GetXHTML(); 
            
            showFloatBox("正在提交评论...");
            var Content = obj.form.body1.value;
            var PhotoID=obj.form.photoid.value;
            var options={method:'post',parameters:"action=CommentAdd&PhotoID="+PhotoID+"&Content="+Content,onComplete:function(transport)
					{
						var returnvalue=transport.responseText;
						eval(returnvalue);
					} 
	            }
	            new Ajax.Request(URL,options);
        },
        
        //回复评论
        ReComment:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            var URL=obj.getAttribute("rel");
            var commentID=0;
            try
            {
                commentID=URL.substr(URL.indexOf("commentid=")).split("=")[1];
            }
            catch(e){}
            
            var objLi=document.getElementById("comment-"+commentID);
            
            var lastObj=objLi.children[objLi.children.length-1].children[objLi.children[0].children.length-1];
            var newlastObj=null;
            if(lastObj.className=="content")
            {
                newlastObj=document.createElement("div");
                objLi.children[objLi.children.length-1].appendChild(newlastObj);
            }
            newlastObj.innerHTML="<textarea class=\"f-text\" id=\"recontent-"+commentID+"\"></textarea><div style=\"padding-left:10px;\"><input type=\"button\" class=\"f-button\"  id=\"recommentconfirm-"+commentID+"\" value=\"确定\" />&nbsp;&nbsp<input class=\"f-button f-alt\" id=\"recommentcancle-"+commentID+"\" type=\"button\" value=\"取消\" /></div>";
           
            
            //取消评论
            document.getElementById("recommentcancle-"+commentID).onclick=function()
            {
                var objLi=document.getElementById("comment-"+commentID);
                var lastObj=objLi.children[objLi.children.length-1].children[objLi.children[0].children.length-1];
                lastObj.parentNode.removeChild(lastObj);
                closeFloatBox();
            }
            //提交评论
            document.getElementById("recommentconfirm-"+commentID).onclick=function()
            {
                var content=document.getElementById("recontent-"+commentID).value;
                var objLi=document.getElementById("comment-"+commentID);
                var lastObj=objLi.lastChild.lastChild;
                showFloatBox("正在提交评论...");
                var URL=RootDir+"/inc/Ajax/album/PhotoOperator.aspx?action=ReComment";
                var options={method:'post',parameters:"action=ReComment&commentID="+commentID+"&Content="+content,onComplete:function(transport)
					{
						var returnvalue=transport.responseText;
						eval(returnvalue);
					} 
	            }
	            new Ajax.Request(URL,options);
            }  
        },
        
        //删除评论
        DelComment:function()
        {
            var event=getEvent();
            var obj=event.srcElement||event.target;
            var URL=obj.getAttribute("rel");
            Confirm(obj,"确定删除该评论吗?","删除",f1);
            function f1()
            {
                setConfirmMSG("正在执行删除操作...");
                runAjax(URL);
            }
        }
    }
}


