/*
*	show.v1.js
*	@author tml
*	@date 2007-10-01
*/

function _lF(){	
	if(typeof(_photos)=='undefined') return false;
	_pid = this.location.hash.replace('#','');
	var photo = array_search(_pid, _photos);
	if(typeof(photo)=="boolean"){ alert("相簿資訊錯誤，無法觀看相片"); location.href = "/"+_uid+"/"+_aid+"/page1"; }	
	_sno = photo.f-1;
	_lM();
}

function _lM(){
	if(typeof(_photos)!="object" || typeof(_sno)=="undefined") return false;
  _tml("載入中...");
	this.location.hash = _photos[_sno].i;
	_pid = _photos[_sno].i;	
	$("#photo").attr("src", _ps+"/"+_photos[_sno].s);		
	$("#photo_sort").html(_photos[_sno].f);	
	(_photos[_sno].t!="") ? $("#title").html(_photos[_sno].t) : $("#title").html("相片標題");
	(_photos[_sno].d!="") ? $("#ext").html(_photos[_sno].d.ReplaceAll("&lt;br&gt;","<br>")) : $("#ext").html("相片描述");
	 _sM(); 
	 _lInfo(); 
	 $("#photo_note").html(''); $(".fn-area").remove(); $(".fn-area-editing").remove(); _note_flag=false;
	 //ad
	 var now = new Date().getTime();
	 $.getScript("http://www.i-part.com.tw/hook/hooks_ipart.pageview.php?spaceid=591&dt="+now);	 
	 $.get("/_incr_key.php?u="+_uno+"&a="+_aid+"&p="+_pid+"&dt="+now);	 	 	 
	 $("#commentlist").html("載入中...");
	 setTimeout('_rCmt()',1000);
	$("#msg").fadeOut("slow");		
}

//about ajax
function _lInfo(){
	if(_uid=="" || _pid=="") return false;
	$("#upload_dt").html(_photos[_sno].u);
	$.ajax({
    url: '/ajax/ajax_api.php?func=getPhotoInfo&uid='+_uid+'&aid='+_aid+'&pid='+_pid+'&fmt=json',
    type: 'GET',
    dataType: 'json',
    error: function(){
        alert('Error loading JSON INFO document _lInfo()');
    },
    success: function(json){
    	$("#taglist").empty();    	
    	if(json['fav']['id']!='n'){
    		$("#favicon").removeClass(); 	
    		if(json['fav']['id']=='-1'){    					
    			$("#favicon").addClass('si8'); _fid='-1';    			
    		}else{    		  
    			$("#favicon").addClass('si9'); _fid = json['fav']['id'];
    		}
    	}   	
      $("#cmt_cnt").html(String(json['stat']["comment_cnt"])); $("#not_cnt").html(String(json['stat']["note_cnt"])); $("#view_cnt").html(String(json['stat']["view_cnt"])); $("#fav_cnt").html(String(json['stat']["favorite_cnt"]));
      $.each( json['tags'], function(i, tag){
      	if(_login!='1'){ 
  				$("#taglist").append('<dt><div class="txtb">'+tag+'</div></dt>');
  			}else{
  				$("#taglist").append('<dt id="tag'+i+'"><div class="txtb"><a href="/_organize/my_tags_photo.php?tag='+encodeURI(tag)+'" id="tagW'+i+'">'+tag+'</a> <a href="javascript:void(0)" onclick="delTag(\''+i+'\')">[x]</a></div></dt>');
  			}
			});		
    }
	});
	$("#exiflist").empty();
	$("#exiflist").append('<li><div class="txtb">相機品牌：'+_photos[_sno].eb+'</div></li><li><div class="txtb">相機型號：'+_photos[_sno].em+'</div></li>');
}

function rE(){	
	if(typeof(_photos)!="object") return false;	
	if(_uid=="" || _pid=="") return false;	
	if((_photos[_sno].eb=="" && _photos[_sno].em=="") || _photos[_sno].x=="gif") return false;
	$.ajax({
    url: '/ajax/ajax_api.php?func=getPhotoExif&uid='+_uid+'&pl='+_photos[_sno].s+'&fmt=html',
    type: 'GET',
    dataType: 'html',
    timeout: 1000,
    error: function(){
        alert('Error loading HTML EXIF document rE()');
    },
    success: function(html){
    	$("#exiflist").html(html).fadeIn("slow");
    }
	});
}

//login after
function aT(){
	if($("#tagT").html()=="新增標籤"){
		$("#spantaginput").show(); $("#inputtag").focus(); $("#tagT").html("關閉新增標籤");
	}else{
		$("#spantaginput").hide(); $("#tagT").html("新增標籤");
	}
}
function _cT(k){
	if(k=='t'){
		(_photos[_sno].t!="") ? $("#title").html(_photos[_sno].t) : $("#title").html("輸入相片標題");
	}else{
		(_photos[_sno].d!="") ? $("#ext").html(_photos[_sno].d.ReplaceAll("&lt;br&gt;","<br>")) : $("#ext").html("輸入相片描述");
	}
}
//edit title
function initTitle(){
	$("#title").hover(function(){
		$('#title').css("background","#ffffd3");
	},function(){
		$('#title').css("background","#ffffff");
	});	
	$('#title').click(
		function(){
			if(document.getElementById('edit_title')) return false;
			$('#title').html("<input type='text' name='edit_title' id='edit_title' size='50' maxlength='20' value='"+_photos[_sno].t+"'>&nbsp;<input type='button' value='儲存' onclick=\"_eD('t')\">&nbsp;<input type='button' value='取消' onclick=\"_cT('t')\">");
			$('#edit_title').focus();	$('#edit_title').select();
		}
	);
}
//edit ext
function initExt(){
	$("#ext").hover(function(){
		$('#ext').css("background","#ffffd3");
	},function(){
		$('#ext').css("background","#ffffff");
	});	
	$('#ext').click(
		function(){
			if(document.getElementById('edit_ext')) return false;
			var ext = _photos[_sno].d.ReplaceAll("&lt;br&gt;","\n");
			$('#ext').html("<textarea name='edit_ext' id='edit_ext' cols='55' rows='3'>"+ext+"</textarea><br><input type='button' value='儲存' onclick=\"_eD('d')\">&nbsp;<input type='button' value='取消' onclick=\"_cT('d')\">");
			$('#edit_ext').focus();	$('#edit_ext').select();
		}
	);
}
function _eD(v){
	_tml("修改中...");
	var cnt=''; (v=='t') ? cnt=$("#edit_title").val() : cnt=$("#edit_ext").val();
	if(v=='t'){ if(cnt==""){ alert("您的相片需要一個合適的標題哦！"); return false;	}}
	$.ajax({
    url: '/ajax/ajax_api.php',
    data: "func=editPhotoData&uid="+_uid+"&aid="+_aid+"&pid="+_pid+"&cnt="+cnt+"&fmt=html&tp="+v,
    type: 'POST',
    error: function(){
    	alert('更新失敗');
    	$("#msg").fadeOut("slow");
    },
    success: function(html){
    	if(v=='t'){ $('#title').html(cnt); _photos[_sno].t=cnt; }else{ $('#ext').html(cnt.ReplaceAll("\n","<br>")); _photos[_sno].d=cnt.ReplaceAll("\n","&lt;br&gt;")}
    	$("#msg").fadeOut("slow");
    }
	});
}

//我要留言
function setCmt(){	
	if(_cmt_flag) return false;
	if($("#cmt").val().length>200){alert("評論不可超過200字喔"); return false;}	
	if($("#cmt").val().length==0){alert("請填入評論"); return false;}
	_tml("寫入中...");
	$.ajax({
    url: '/ajax/ajax_api.php',
    data: "func=addPhotoCmt&uid="+_uid+"&aid="+_aid+"&pid="+_pid+"&fext="+_photos[_sno].x+"&cmt="+$("#cmt").val()+"&fmt=json",
    type: 'POST',
    dataType: 'json',
    error: function(){
    	alert('新增失敗');
    	$("#msg").fadeOut("slow"); _cmt_flag = false;
    },
    success: function(json){
    	if(json.cmt_id=='-1'){
    		$("#msg").fadeOut("slow");
    		if(!confirm("您必須先完成完整註冊，才能使用本功能喔")){
    			return;
    		}else{
    			location.href = "http://www.i-part.com.tw/register/register_nook.php?f=http://photo.i-part.com.tw";
    		}
    	}else if(json.cmt_id=='-2'){
    		$("#msg").fadeOut("slow");
    		if(!confirm("您必須先完成信箱認證，才能使用本功能喔")){
    			return;
    		}else{
    			location.href = "http://www.i-part.com.tw/register/login_mail_check.php?f=http://photo.i-part.com.tw";
    		}
    	}else if(json.cmt_id=='-3'){
    		$("#msg").fadeOut("slow");
    		alert('你目前被該用戶設定為壞友，無法留言!!');
    	}else{
				html = '<div class="post" id="cmt'+json.cmt_id+'"><div class="ppstsp"><div class="post1"><input type="checkbox" name="cmtChk[]" id="cmtChk[]" value="'+json.cmt_id+'" /></div><div class="post2"><table border="0" cellspacing="0" cellpadding="0">'+  
      	'<tr><td align="center" class="poutg"><a href="'+json.link+'" target="_blank"><img src="'+json.head+'" border="0" /></a></td></tr></table>'+
				'</div><div class="post3"><div><img src="'+_ps+json.gender+'" width="10" height="15" align="absmiddle"><a href="'+json.link+'">'+json.user_nk+'</a><span class="grtxt">('+json.time+')</span></div>'+
				'<p>'+Textout(json.cmt)+'</p></div></div></div>';
    		$("#commentlist").prepend(html);
    		$("#msg").fadeOut("slow"); $("#cmt").val(""); _cmt_flag = false;    	
    		var cnt = new Number($("#cmt_cnt").html());	$("#cmt_cnt").html(cnt+1); cnt=html=null; 	
      }
    }
  }); 
}
//讀留言
function _rCmt(){	
	$.ajax({
    url: '/ajax/ajax_api.php',
    data: "func=getPhotoCmt&uid="+_uid+"&pid="+_pid+"&fmt=json",
    type: 'GET',
    dataType: 'json',
    error: function(){    	
    },
    success: function(json){    	
    	$("#commentlist").empty();    	
      $.each( json, function(i, cmt){      	
      	html = '<div class="post" id="'+((typeof(cmt.cmt_id)=='undefined')?'':'cmt'+cmt.cmt_id)+'"><div class="ppstsp"><div class="post1">'+((typeof(cmt.cmt_id)=='undefined')?'':'<input type="checkbox" name="cmtChk[]" id="cmtChk[]" value="'+cmt.cmt_id+'" />')+'</div><div class="post2"><table border="0" cellspacing="0" cellpadding="0">'+  
      	'<tr><td align="center" class="poutg"><a href="'+cmt.link+'" target="_blank"><img src="'+cmt.head+'" border="0" /></a></td></tr></table>'+
				'</div><div class="post3" ><div><img src="'+_ps+cmt.gender+'" width="10" height="15" align="absmiddle"><a href="'+cmt.link+'">'+cmt.user_nk+'</a><span class="grtxt">('+cmt.time+')</span></div>'+
				'<p>'+Textout(cmt.cmt)+'</p>';
				if(cmt.rp == ''){
					if(typeof(cmt.cmt_id)!='undefined' && _lno == _uno){
						html += '<div id="RP_DIV_'+ cmt.cmt_id +'" name="RP_DIV_'+ cmt.cmt_id +'"><div style="text-align: right;"><a href="javascript:Goreplay(\'RP_DIV_'+ cmt.cmt_id +'\');"><img src="http://photo.i-part.com.tw/images/photo/replay.gif" border="0" /></a></div></div>';
					}
				} else {
					if(cmt.rp_type == 1){
						html += '<div id="secpost"><span class="b">作者回</span>覆['+ cmt.rp_time +']：'+
								 '<p>'+ Textout(cmt.rp) +'</p></div>';
					} else if(cmt.rp_type == 0 && typeof(cmt.cmt_id)!='undefined'){
						html += '<div id="secpost"><span class="b">作者<span class="s">私密</span>回</span>覆['+ cmt.rp_time +']：'+
								 '<p>'+ Textout(cmt.rp) +'</p></div>';
					}
				}				
				html += '</div></div></div>';
    		$("#commentlist").prepend(html);
			});
			html=null;
    }
  });   
}

$.fn.checkAll = function(mode) {
	return this.each(function() {
		this.checked = mode;
	});
};
//留言回複 steven 08-06-26
var now_RP_DIV = -1;
var secretFlag = false;
function Goreplay(DivId){
	if(now_RP_DIV != -1){cancel_rp(now_RP_DIV);}
	cid = DivId.split("RP_DIV_");
	html = '<div id="replay"><span class="b">作者回覆</span>(限300字) <input id="secret'+DivId+'" name="secret'+DivId+'" type="checkbox" value="1" onclick="setSecret(this)" />私密'+
	'<p>'+
	'<textarea name="textarea" rows="5" style="width:395px;font-size:9pt;" id="rp_context'+DivId+'" name="rp_context'+DivId+'"></textarea>'+
	'<div  style="padding-top: 1px;">'+
	'<div style="position: absolute;text-align:left;">'+
	'<div style="position: absolute; width: 185px;line-height: 50%;text-align:left;">'+
	'<img height="17" border="0" align="absmiddle" width="109" style="position: absolute;" onclick="show_ffunc(\''+ cid[1] +'\');" src="http://img.i-part.com.tw/images/faceicon/button_select.gif"/>'+
	'<img height="1" width="110" src="http://img.i-part.com.tw/images/space.gif"/>'+
	'<a onclick="window.open(\'http://www.i-part.com.tw/file/feelings_say.htm\',\'\',\'top=0,resizable=yes,scrollbars=yes,width=540,height=540\');" href="javascript:void(0)">'+
	'<img height="12" border="0" align="absmiddle" width="12" src="http://img.i-part.com.tw/images/help.gif"/>'+
	'使用說明'+
	'</a>'+
	'</div>'+
	
'<div id="div_ffunc_'+ cid[1] +'" style="position: absolute; z-index: 1; display: none;" name="div_ffunc_'+ cid[1] +'">'+
'<table  border="0" cellspacing="0" cellpadding="0">'+
                        '<tr>'+
                        '<td align="left"><img src="http://img.i-part.com.tw/images/faceicon/menu_top_left.gif" width="6" height="4"></td>'+
                        '<td align="center" style="border-top:1px solid #8C8C8C"><img src="http://img.i-part.com.tw/images/space.gif" width="3" height="3"></td>'+
                        '<td align="right"><img src="http://img.i-part.com.tw/images/faceicon/menu_top_right.gif" width="6" height="4"></td>'+

                        '</tr>'+
                        '<tr>'+
                        '<td bgcolor="#FFFFFF" style="border-left:1px solid #8C8C8C"><img src="http://img.i-part.com.tw/images/space.gif" width="5" height="5"></td>'+
                        '<td align="center" bgcolor="#FFFFFF"><table  border="0" cellspacing="0" cellpadding="2">'+
                          '<tr>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_1.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(1,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_2.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(2,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_3.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(3,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_4.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(4,'+ cid[1] +')" style="cursor:hand"></td>'+

                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_5.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(5,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_6.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(6,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_7.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(7,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_8.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(8,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_9.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(9,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_10.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(10,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_11.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(11,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_12.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(12,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td align="right" valign="top" style="padding:0px"><img src="http://img.i-part.com.tw/images/icon_close02.gif" width="14" height="14" border="0" style="cursor:hand" onclick="hide_ffunc('+ cid[1] +')"></td>'+

                          '</tr>'+
                          '<tr>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_13.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(13,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_14.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(14,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_15.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(15,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_16.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(16,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_17.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(17,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_18.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(18,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_19.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(19,'+ cid[1] +')" style="cursor:hand"></td>'+

                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_20.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(20,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_21.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(21,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_22.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(22,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_23.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(23,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_24.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(24,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_25.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(25,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '</tr>'+
						  '<tr>'+
						  '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_26.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(26,'+ cid[1] +')" style="cursor:hand"></td>'+

                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_27.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(27,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_28.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(28,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_29.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(29,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_30.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(30,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_31.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(31,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_32.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(32,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_33.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(33,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_34.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(34,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_35.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(35,'+ cid[1] +')" style="cursor:hand"></td>'+

                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_36.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(36,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_37.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(37,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '<td><img src="http://img.i-part.com.tw/images/feelings/feelings_38.gif" width="20" height="21" align="absmiddle" border="0" onclick="addFeelings(38,'+ cid[1] +')" style="cursor:hand"></td>'+
                          '</tr>'+
                        '</table>'+
                          '</td>'+
                        '<td bgcolor="#FFFFFF" style="border-right:1px solid #8C8C8C"><img src="http://img.i-part.com.tw/images/space.gif" width="5" height="5"></td>'+
                        '</tr>'+
                        '<tr>'+

                        '<td align="left"><img src="http://img.i-part.com.tw/images/faceicon/menu_bottom_left.gif" width="6" height="4"></td>'+
                        '<td align="center" style="border-bottom:1px solid #8C8C8C"><img src="http://img.i-part.com.tw/images/space.gif" width="3" height="3"></td>'+
                        '<td align="right"><img src="http://img.i-part.com.tw/images/faceicon/menu_bottom_right.gif" width="6" height="4"></td>'+
                        '</tr>'+
                      '</table>'+

	'</div>'+
	'</div>'+
	'<div style="padding-left:100px;" align="center">'+
	'<input type="button" onclick="Go_rp(\''+ DivId +'\')" value="&nbsp;確定留言&nbsp;">'+
	'<input type="button" onclick="cancel_rp(\''+ DivId +'\')" value="&nbsp;取消&nbsp;"> </div></p></div>'+
	'';
	//window.document.getElementById(DivId).innerHTML = html;
	$("#"+DivId).html(html);
	now_RP_DIV = DivId;
	html=null;
	//$("#"+DivId).html('');
	
}
function setSecret(obj){
	if(secretFlag)
		secretFlag = false;
	 else 
	 	secretFlag = true;
}
//取消回複
function cancel_rp(DivId){
	html = '<div id="'+ DivId +'" name="'+ DivId +'"><div style="text-align: right;"><a href="javascript:Goreplay(\''+ DivId +'\');"><img src="http://photo.i-part.com.tw/images/photo/replay.gif" border="0" /></a></div></div>';
	$("#"+DivId).html(html);
	html=null;
	now_RP_DIV = -1;
	secretFlag = false
}
//留言回複
function Go_rp(DivId){
	if($("#rp_context"+DivId).val().trim() == ""){
		alert('請輸入回應！');
		return;
	} else {
		var nowTime = getNowTime();
		var rp_wod = $("#rp_context"+DivId).val().trim();
		if(secretFlag){
			html = '<div id="secpost"><span class="b">作者<span class="s">私密</span>回</span>覆['+ nowTime +']：<p>'+ Textout(rp_wod) +'</p></div>';
		} else {
			html = '<div id="secpost"><span class="b">作者回</span>覆['+ nowTime +']：<p>'+ Textout(rp_wod) +'</p></div>';
		}
		$("#"+DivId).html(html);
		html=null;
		cid = DivId.split("RP_DIV_");
		var _SF = 1;
		if(secretFlag){_SF = 0;}
		
		$.ajax({
		    url: '/ajax/ajax_api.php',
		    data: "func=rpPhotoCmt&uid="+_uid+"&uno="+_uno+"&cid="+cid[1]+"&rp="+rp_wod+"&secretFlag="+_SF+"&fmt=json",
		    type: 'POST',
		    dataType: 'json',
		    error: function(){    	
		    },
		    success: function(json){
			}
		});
		
		now_RP_DIV = -1;
		secretFlag = false;
	}
	
	
}
function getNowTime(){
	var d=new Date();
	var year=d.getFullYear();
	var mon=d.getMonth()+1;
	var day=d.getDate();
	var HH=d.getHours();
	var ii=d.getMinutes();
	var ss=d.getSeconds();
	
	if(mon < 10){mon="0"+mon;}
	if(day < 10){day="0"+day;}
	if(HH < 10){HH="0"+HH;}
	if(ii < 10){ii="0"+ii;}
	if(ss < 10){ss="0"+ss;}
	return year+'-'+mon+'-'+day+' '+HH+':'+ii+':'+ss;
}


function _cmtSelAll(obj){
	var t=(obj.checked)?true:false;
	$("input[@type='checkbox']").checkAll(t);
}
function _dCmtAll(){
	if(!confirm("確定刪除所有留言??")) return false;
	var obj = document.getElementById('selAll'); 
	obj.checked=true; _cmtSelAll(obj); _dCmt();
}
//刪除留言
function _dCmt(){
	var i = 0; var cL = new Array();
	$("input[@type='checkbox']").each( 
		function(){ if(this.checked){ cL[i]=this.value; i++; } }
	);
	if(i < 1) {alert("請選Ç要刪除的留言"); return false;}	
	$.ajax({
    url: '/ajax/ajax_api.php',
    data: "func=delCommentData&uid="+_uid+"&aid="+_aid+"&pid="+_pid+"&cmt_in="+cL.join(',')+"&fmt=json",
    type: 'POST',
    dataType: 'json',
    error: function(){
    	alert("刪除回應失敗"); $("#msg").fadeOut("slow");
    },
    success: function(json){
    	var cnt = new Number($("#cmt_cnt").html());
    	$.each( json, function(i, cmt_id){
      	$("#cmt"+cmt_id).remove(); cnt--;
			});
			$("#cmt_cnt").html(cnt.toString()); $("#msg").fadeOut("slow");
			alert("刪除回應成功");
    }
  });
}

//add tag
function setTag(){	
	var posttag = '';
	var tenwordflag = true;
	var tags = $('#inputtag').val();
	if(tags=="") {alert("請輸入標籤"); return false;}
	var reg = /(,|，| |　)+/g;
	var tagArr = tags.split(reg);	
	if(tagArr.length > 10){ alert("標籤不能一次輸入超過10個喔"); return false;}
	for(i=0;i<tagArr.length;i++){
		if(tagArr[i]=="") continue;
		if(tagArr[i].length>10){ tenwordflag=false; break;}
		posttag+= " "+tagArr[i];
	}
	if(!tenwordflag){ alert("單一標籤不能超過十個字喔"); return false;}
	_tml("寫入中...");
	$.ajax({
    url: '/ajax/ajax_api.php',
    data: "func=setPhotoTags&uid="+_uid+"&aid="+_aid+"&pid="+_pid+"&tags="+posttag.trim()+"&fmt=json",
    type: 'POST',
    dataType: 'json',
    error: function(){
    	alert('新增失敗');
    	$("#msg").fadeOut("slow");
    },
    success: function(json){
    	$.each( json, function(i, tag){
  			$("#taglist").append('<dt id="tag'+i+'"><div class="txtb"><a href="/_organize/my_tags_photo.php?tag='+encodeURI(tag)+'" id="tagW'+i+'">'+tag+'</a> <a href="javascript:void(0)" onclick="delTag(\''+i+'\')">[x]</a></div></dt>');
			});
			aT();	$("#msg").fadeOut("slow"); $('#inputtag').val("");		
    }
  });
}

//del tag
function delTag(fno){	
	_tml("刪除中...");		
	$.ajax({
    url: '/ajax/ajax_api.php',
    data: "func=delPhotoTags&uid="+_uid+"&pid="+_pid+"&fno="+fno+"&tag="+encodeURI($("#tagW"+fno).html())+"&fmt=html",
    type: 'POST',
    dataType: 'html',
    error: function(){
    	alert('刪除失敗');
    	$("#msg").fadeOut("slow");
    },
    success: function(html){    	
    	$("#tag"+fno).remove();
    	$("#msg").fadeOut("slow");
    }
  });  
}

//收藏
function mF(){
	$.ajax({
		url: '/ajax/ajax_api.php',
    data: 'func=doFavAction&uid='+_uid+'&aid='+_aid+'&pid='+_pid+'&fid='+_fid+'&ftype=1&fmt=html',
    type: 'POST',
    dataType: 'html',
    timeout: 1000,
    error: function(){
        alert('Error loading HTML document');
    },
    success: function(html){
    	$("#favicon").removeClass();
    	if(_fid==-1){
    		if(html.trim()=="fail"){ alert("收藏相片失敗"); return false;}    	
    		$("#favicon").addClass('si9');
    		_fid = html.trim();
    	}else{
    		if(html.trim()!="ok"){ alert("取消收藏相片失敗"); }
    		$("#btn_fav").attr("value","收藏相片"); _fid= '-1';
    		$("#favicon").addClass('si8');
    	}
    }
	});
}

function _dP(){
	if(typeof(_photos)!="object") return;
	if(!confirm("確定要刪除這一張相片?")) return;
	_tml("刪除中...");	
	$.ajax({
    url: '/ajax/ajax_api.php',
    data: "func=delPhotoData&uid="+_uid+"&aid="+_aid+"&pid="+_pid+"&fmt=html",
    type: 'POST',
    dataType: 'html',
    error: function(){
    	alert('刪除失敗');    
    },
    success: function(html){
    	if(html.trim()=="ok"){
    		if(_pnt > 1){
    			(_photos[_sno+1])?location.hash=_photos[_sno+1].i:location.hash=_photos[_sno-1].i;
    			window.location.reload();
				}else{
	  			window.location.href = "/"+_uid+"/"+_aid+"/page1";
				}
			}else{
			  alert(html.trim());
			}
    }
  });
}

//load note
function _lNote(){
	if(_note_flag) return false;
	$.ajax({
    url: '/ajax/ajax_api.php',
  	data: "func=PhotoNoteList&uid="+_uid+"&aid="+_aid+"&pid="+_pid+"&fmt=html",
  	type: 'GET',
  	dataType: 'html',
  	error: function(){
  		alert('載入便利貼失敗');
  	},
  	success: function(html){
  		$("#photo_note").html(html.trim())
  		_note_flag = true;
  	}
  });
}

//del all note
function _dN(){
	if(!confirm("確定刪除這一張相片所有便利貼?")) return;
	$.ajax({
    url: '/ajax/ajax_api.php',
  	data: "func=PhotoNote&action=deleteAll&uid="+_uid+"&pid="+_pid+"&fmt=html",
  	type: 'POST',
  	dataType: 'html',
  	error: function(){
  		alert('刪除所有便利貼失敗');  	
  	},
  	success: function(html){
  		if(html.trim()=="ok"){
  			$("#photo_note").html("");
  			_note_flag = true;
  			alert("刪除所有便利貼成功");
  		}else{
  			alert("刪除失敗,"+html.trim());
  		}
  	}
  });
}

//illegal
function oIll(){
	$("#ill_content").show();
	$("#ill_content").css("left", 20); 
	$("#ill_content").css("top", document.documentElement.scrollTop+document.body.scrollTop);
	$("#ill_content").draggable();	
}
function cIll(){
	$("#ill_content").fadeOut("slow");
}
function dIll(){
	var oF = document.illFrm;
	if(!oF) return false;
	var opt = -1;
	for(var i=0;i < oF.opt.length; i++){ if(oF.opt[i].checked) {opt=oF.opt[i].value; break; }}	
	if(opt==5){ if(oF.cnt.value.trim()==""){ alert("請填寫檢舉原因"); oF.cnt.focus(); return false;} opt=oF.cnt.value.trim(); }	
	$.ajax({
		url: '/ajax/ajax_api.php',
  	data: 'func=setIllegalData&uid='+_uid+'&aid='+_aid+'&pid='+_pid+'&fext='+_photos[_sno].x+'&opt='+opt+'&fmt=html',    
    type: 'POST',
    dataType: 'html',
    timeout: 1000,
    error: function(){
        alert('Error loading HTML document');
    },
    success: function(html){
    	if(html.trim()=="ok"){
    		alert("檢舉相片成功");
    		$("#ill_content").fadeOut("slow");
    	}else{
    	  alert("檢舉失敗,"+html.trim());
    	}
    }
	});	
}

//rotate
function getRoateImage(){
	return _ps+"/"+_photos[_sno].s.replace("t.","m.");
}

function reloadRoateImage(){
	alert('reload image');
}

//forward
function _rO(){
	if(typeof(_photos)!="object" || isNaN(_sno)) return false;	
	this.location.href = "/photo_allsize.php?d="+_uid+"&a="+_aid+"&p="+_pid+"&x="+_photos[_sno].x+"&t=t";
}

function _rS(){
  if(typeof(_photos)!="object" || isNaN(_sno)) return false;	
	this.location.href = "/slideshow.php?d="+_uid+"&a="+_aid+"&p="+_pid;
}

//ctrl
function _sM(){
	$("#sp1,#sp2,#sp3,#sp4").css("border","2px solid #fff");	
	switch(_sno%4){
		case 0:		 
			if(typeof(_photos[_sno])=="object"){ $("#sp1").attr("src", _ps+"/"+_photos[_sno].s.replace("t.","m.")); _scroll[0]=_sno; $("#sp1").css("border","2px solid #f06e87"); }else{$("#sp1").attr("src","/images/photo/backup.gif"); _scroll[0]=-1;}
			if(typeof(_photos[_sno+1])=="object"){ $("#sp2").attr("src", _ps+"/"+_photos[_sno+1].s.replace("t.","m.")); _scroll[1]=_sno+1;}else{$("#sp2").attr("src","/images/photo/backup.gif"); _scroll[1]=-1;}
			if(typeof(_photos[_sno+2])=="object"){ $("#sp3").attr("src", _ps+"/"+_photos[_sno+2].s.replace("t.","m.")); _scroll[2]=_sno+2;}else{$("#sp3").attr("src","/images/photo/backup.gif"); _scroll[2]=-1;}
			if(typeof(_photos[_sno+3])=="object"){ $("#sp4").attr("src", _ps+"/"+_photos[_sno+3].s.replace("t.","m.")); _scroll[3]=_sno+3;}else{$("#sp4").attr("src","/images/photo/backup.gif"); _scroll[3]=-1;}
		break;
		case 1:		 
			if(typeof(_photos[_sno-1])=="object"){ $("#sp1").attr("src", _ps+"/"+_photos[_sno-1].s.replace("t.","m.")); _scroll[0]=_sno-1; }else{$("#sp1").attr("src","/images/photo/backup.gif"); _scroll[0]=-1;}
			if(typeof(_photos[_sno])=="object"){ $("#sp2").attr("src", _ps+"/"+_photos[_sno].s.replace("t.","m.")); _scroll[1]=_sno; $("#sp2").css("border","2px solid #f06e87");}else{$("#sp2").attr("src","/images/photo/backup.gif"); _scroll[1]=-1;}
			if(typeof(_photos[_sno+1])=="object"){ $("#sp3").attr("src", _ps+"/"+_photos[_sno+1].s.replace("t.","m.")); _scroll[2]=_sno+1;}else{$("#sp3").attr("src","/images/photo/backup.gif"); _scroll[2]=-1;}
			if(typeof(_photos[_sno+2])=="object"){ $("#sp4").attr("src", _ps+"/"+_photos[_sno+2].s.replace("t.","m.")); _scroll[3]=_sno+2;}else{$("#sp4").attr("src","/images/photo/backup.gif"); _scroll[3]=-1;}
		break;
		case 2:			
			if(typeof(_photos[_sno-2])=="object"){ $("#sp1").attr("src", _ps+"/"+_photos[_sno-2].s.replace("t.","m.")); _scroll[0]=_sno-2;}else{$("#sp1").attr("src","/images/photo/backup.gif"); _scroll[0]=-1;}
			if(typeof(_photos[_sno-1])=="object"){ $("#sp2").attr("src", _ps+"/"+_photos[_sno-1].s.replace("t.","m.")); _scroll[1]=_sno-1;}else{$("#sp2").attr("src","/images/photo/backup.gif"); _scroll[1]=-1;}
			if(typeof(_photos[_sno])=="object"){ $("#sp3").attr("src", _ps+"/"+_photos[_sno].s.replace("t.","m.")); _scroll[2]=_sno; $("#sp3").css("border","2px solid #f06e87");}else{$("#sp3").attr("src","/images/photo/backup.gif"); _scroll[2]=-1;}
			if(typeof(_photos[_sno+1])=="object"){ $("#sp4").attr("src", _ps+"/"+_photos[_sno+1].s.replace("t.","m.")); _scroll[3]=_sno+1;}else{$("#sp4").attr("src","/images/photo/backup.gif"); _scroll[3]=-1;}
		break;
		case 3:
		  if(typeof(_photos[_sno-3])=="object"){ $("#sp1").attr("src", _ps+"/"+_photos[_sno-3].s.replace("t.","m.")); _scroll[0]=_sno-3;}else{$("#sp1").attr("src","/images/photo/backup.gif"); _scroll[0]=-1;}
			if(typeof(_photos[_sno-2])=="object"){ $("#sp2").attr("src", _ps+"/"+_photos[_sno-2].s.replace("t.","m.")); _scroll[1]=_sno-2;}else{$("#sp2").attr("src","/images/photo/backup.gif"); _scroll[1]=-1;}
			if(typeof(_photos[_sno-1])=="object"){ $("#sp3").attr("src", _ps+"/"+_photos[_sno-1].s.replace("t.","m.")); _scroll[2]=_sno-1;}else{$("#sp3").attr("src","/images/photo/backup.gif"); _scroll[2]=-1;}
			if(typeof(_photos[_sno])=="object"){ $("#sp4").attr("src", _ps+"/"+_photos[_sno].s.replace("t.","m.")); _scroll[3]=_sno; $("#sp4").css("border","2px solid #f06e87");}else{$("#sp4").attr("src","/images/photo/backup.gif"); _scroll[3]=-1;}
		break;
	}	
}
function _rPre(){		
	if(_scroll[0]==0) return; $("#sp1,#sp2,#sp3,#sp4").css("border","2px solid #fff");
	var sn = _scroll[0];
	if(typeof(_photos[sn-4])=="object"){ $("#sp1").attr("src", _ps+"/"+_photos[sn-4].s.replace("t.","m.")); _scroll[0]=sn-4; }else{$("#sp1").attr("src","/images/photo/backup.gif"); _scroll[0]=-1;}
	if(typeof(_photos[sn-3])=="object"){ $("#sp2").attr("src", _ps+"/"+_photos[sn-3].s.replace("t.","m.")); _scroll[1]=sn-3; }else{$("#sp2").attr("src","/images/photo/backup.gif"); _scroll[1]=-1;}
	if(typeof(_photos[sn-2])=="object"){ $("#sp3").attr("src", _ps+"/"+_photos[sn-2].s.replace("t.","m.")); _scroll[2]=sn-2; }else{$("#sp3").attr("src","/images/photo/backup.gif"); _scroll[2]=-1;}
	if(typeof(_photos[sn-1])=="object"){ $("#sp4").attr("src", _ps+"/"+_photos[sn-1].s.replace("t.","m.")); _scroll[3]=sn-1; }else{$("#sp4").attr("src","/images/photo/backup.gif"); _scroll[3]=-1;}
}
function _rNex(){	
	if(_scroll[3]==-1 || (_scroll[3]==_pnt-1)) return; $("#sp1,#sp2,#sp3,#sp4").css("border","2px solid #fff");
	var sn = _scroll[3];
	if(typeof(_photos[sn+1])=="object"){ $("#sp1").attr("src", _ps+"/"+_photos[sn+1].s.replace("t.","m.")); _scroll[0]=sn+1; }else{$("#sp1").attr("src","/images/photo/backup.gif"); _scroll[0]=-1;}
	if(typeof(_photos[sn+2])=="object"){ $("#sp2").attr("src", _ps+"/"+_photos[sn+2].s.replace("t.","m.")); _scroll[1]=sn+2; }else{$("#sp2").attr("src","/images/photo/backup.gif"); _scroll[1]=-1;}
	if(typeof(_photos[sn+3])=="object"){ $("#sp3").attr("src", _ps+"/"+_photos[sn+3].s.replace("t.","m.")); _scroll[2]=sn+3; }else{$("#sp3").attr("src","/images/photo/backup.gif"); _scroll[2]=-1;}
	if(typeof(_photos[sn+4])=="object"){ $("#sp4").attr("src", _ps+"/"+_photos[sn+4].s.replace("t.","m.")); _scroll[3]=sn+4; }else{$("#sp4").attr("src","/images/photo/backup.gif"); _scroll[3]=-1;}
}
function _rL(v){ if(_scroll[v]!=-1){_sno=_scroll[v];_lM();}}
function _lfFi(){ if(_sno==0) return false;	_sno = 0;	_lM(); }
function _lPr(){ if(_sno==0) return false;	_sno--;_lM(); }
function _lNe(){ if(_sno==(_pnt-1)) return false;	_sno++;	_lM(); }
function _lLa(){ if(_sno==(_pnt-1)) return false;_sno = _pnt-1;_lM();}

//other && lib
function _tml(msg){
	$("#msg").css("left", $(document).width()-120); 
	$("#msg").css("top", document.documentElement.scrollTop+document.body.scrollTop);
	$("#msg").fadeIn("fast"); $("#msg").html(msg);
}

function array_search(needle,haystack){
	for(var i in haystack){	if(haystack[i].i==needle) return haystack[i];	}	return false;
}