/*
*	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
	 $.getScript("http://www.i-part.hk/hook/hooks_ipart.pageview.php?spaceid=591");	
	 var now = new Date().getTime();
	 $.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.hk/register/register_nook.php?f=http://photo.i-part.hk";
    		}
    	}else if(json.cmt_id=='-2'){
    		$("#msg").fadeOut("slow");
    		if(!confirm("您必須先完成信箱認證，才能使用本功能喔")){
    			return;
    		}else{
    			location.href = "http://www.i-part.hk/register/login_mail_check.php?f=http://photo.i-part.hk";
    		}
    	}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>'+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>'+cmt.cmt+'</p></div></div></div>';
    		$("#commentlist").prepend(html);
			});
			html=null;
    }
  }); 
}

$.fn.checkAll = function(mode) {
	return this.each(function() {
		this.checked = mode;
	});
};
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());
    	}
    }
	});	
}

//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;
}