gConst.kColumnCount=4;
gConst.kUpdateImagesChunkLength=24;
function ImagePager(){
var _1;
var _2;
var _3=0;
var _4=false;
this.iImagesPerPage;
this.iServerImages=null;
this.iImageRootPath=null;
this.iRefIndexHash=[];
this.iDelDupId=null;
this.rebuildRefIndexHash=function(){
this.iRefIndexHash=[];
for(var i=0;i<this.iImageCount;i++){
this.iRefIndexHash[this.iServerImages[i].id]=i;
}
};
this.setImageRootPath=function(_6){
this.iImageRootPath=_6;
};
this.getServerImage=function(_7){
return this.iServerImages[_7];
};
this.getImageRootPath=function(_8){
return this.iImageRootPath;
};
this.setImageTitle=function(_9,_a){
this.iServerImages[this.iRefIndexHash[_9]].title=_a;
};
this.setImagesPerPage=function(_b){
this.iImagesPerPage=_b;
var _c=this.iTopLeftImage-(this.iTopLeftImage%this.iImagesPerPage);
if(this.iTopLeftImage!=_c){
this.iTopLeftImage=_c;
}
this.updateDisplay();
gPage.equaliseColumns();
};
var _d=null;
var _e=null;
var _f=false;
var _10=null;
this.updateFromServer=function(_11){
if(_11!=undefined){
_10=_11;
}
if(_d){
_f=true;
}else{
_d=HTTP.newRequest();
_d.onreadystatechange=function(_12){
gPage.iImagePager.handleUpdateResponse(_12);
};
_d.open("GET",this.getDetailsUrl(),true);
_d.send(null);
_e=window.setTimeout("gPage.iImagePager.abortUpdateRequest();",12000);
}
};
this.handleUpdateResponse=function(){
if(_d.readyState==4){
window.clearTimeout(_e);
if(_d.status==200){
if(_d.getResponseHeader("Content-Type").match(/json/)){
var _13=JSON.parse(_d.responseText);
if(_13!=false&&_13.ok){
iImageCollectionObject=_13;
this.updateImagesArray();
if(_4){
$("image_paging_container").style.display="block";
this.setImageCount(this.iServerImages.length,this.iServerImages.length-1);
}else{
_4=true;
this.finishInit();
}
}
_d=null;
}
if(_f){
_f=false;
this.updateFromServer();
}
}else{
_d.abort();
_d=null;
}
}
};
this.abortUpdateRequest=function(){
if(_d!=null){
_d.abort();
_d=null;
}
};
this.delDup=function(aId){
this.iDelDupId=aId;
if(!aId.match(/^del/)||this.confirmDeleteItem()){
this.doDelDup();
}
};
this.doDelDup=function(){
var _15=this.iDelDupId.match(/^(del|dup)_(\d+)$/);
if(_15){
this.delDupServerImage(_15[1],_15[2]);
}
};
this.delDupServerImage=function(_16,_17){
var _18,_19,_1a;
if(!_1){
this.userFeedbackUpdating();
this.showWorkingAnimation(_17);
_18={action:_16,ref:_17};
this.addDelDupInfo(_18);
_19=JSON.stringify(_18);
_1=HTTP.newRequest();
_1.open("POST",this.getServerDelDupUrl());
_1.setRequestHeader("Content-type","text/plain");
_1.setRequestHeader("Content-length",_19.length);
_1.setRequestHeader("Connection","close");
_1.onreadystatechange=function(){
gPage.iImagePager.handleDelDupImageResponse();
};
_1.send(_19);
_1a=(_16=="del"?"delete":"duplicate");
_2=window.setTimeout("gPage.iImageTimer.delDupRequestTimedOut('"+_1a+"');",10000);
}
};
this.showWorkingAnimation=function(_1b){
var _1c=$("img_anim_"+_1b);
if(!_1c.src.match(/working/)){
_1c.src=gConst.kAjaxImagesDir+"cellWorking.gif";
_1c.style.display="inline";
}
};
this.stopWorkingAnimation=function(_1d){
var _1e=$("img_anim_"+_1d);
if(_1e.src.length>0){
_1e.src="";
_1e.style.display="none";
}
};
this.handleDelDupImageResponse=function(){
var _1f,_20;
if(_1.readyState==4){
window.clearTimeout(_2);
if(_1.status==200){
_1f=JSON.parse(_1.responseText);
if(_1f){
this.stopWorkingAnimation(_1f.ref);
if(_1f.ok){
if(_1f.action=="del"){
this.deleteImage(_1f.ref);
}else{
if(_1f.action=="dup"){
this.duplicateImage(_1f.ref,_1f.newImg);
}
}
this.delDupComplete(_1f);
this.clearUserFeedback();
}else{
this.errorFeedback("server error");
}
}else{
this.errorFeedback("failed");
}
}else{
this.errorFeedback("server error");
}
_1=null;
_2=null;
}
};
this.delDupRequestTimedOut=function(_21){
_1=null;
_2=null;
this.errorFeedback(_21+" request timed out");
};
this.deleteImage=function(_22){
var _23=this.iRefIndexHash[_22];
if(_23!=gConst.kNotDefined){
if(this.iServerImages[_23].selected){
_3--;
this.notifyObserversChanged();
}
this.iServerImages.splice(_23,1);
this.addImageCount(-1,_23-1);
}
};
this.duplicateImage=function(_24,_25){
var _26=this.getImageIndexForRef(_24);
if(_26!=gConst.kNotDefined){
var _27=this.getCopyImage(this.iServerImages[_26],_25);
_27.selected=false;
this.iServerImages.splice(_26+1,0,_27);
this.addImageCount(1,_26+1);
}
};
this.getImageIndexForRef=function(_28){
var _29=$("image_pager_table");
var _2a=_29.getElementsByTagName("td");
var _2b=gConst.kNotDefined;
var _2c=0;
for(var i=0;i<_2a.length;i++){
matches=_2a[i].id.match(this.iCellMatchRegex);
if(matches){
if(matches[2]==_28){
_2b=this.iTopLeftImage+_2c;
break;
}
_2c++;
}
}
return _2b;
};
this.uncheckAll=function(){
var _2e=$("image_pager_table").getElementsByTagName("input");
for(var i=0;i<_2e.length;i++){
if(_2e[i].type=="checkbox"){
_2e[i].checked=false;
}
}
};
this.selectImageChanged=function(_30){
var _31=parseInt(_30.id.replace(/select/,""));
this.iServerImages[this.iTopLeftImage+_31].selected=_30.checked;
_3+=_30.checked?1:-1;
this.notifyObserversChanged();
this.setApplyToSelected(true);
};
this.selectAll=function(_32){
if(this.iServerImages){
for(var i=0;i<this.iServerImages.length;i++){
this.iServerImages[i].selected=_32;
}
this.selectAllVisibleDisplay(_32);
_3=_32?this.iServerImages.length:0;
this.notifyObserversChanged();
}
this.setApplyToSelected(_32);
};
this.selectAllVisible=function(){
for(var i=0;i<this.iImagesPerPage&&this.iTopLeftImage+i<this.iServerImages.length;i++){
if(!this.iServerImages[this.iTopLeftImage+i].selected){
this.iServerImages[this.iTopLeftImage+i].selected=true;
_3++;
}
}
this.selectAllVisibleDisplay(true);
this.setApplyToSelected(true);
this.notifyObserversChanged();
};
this.getSelectedCount=function(){
return _3;
};
this.getSelectedIdList=function(){
var _35=new Array();
for(var i=0;i<this.iServerImages.length;i++){
if(this.iServerImages[i].selected==true){
_35.push(this.iServerImages[i].id);
}
}
return _35;
};
this.selectAllVisibleDisplay=function(_37){
var _38=$("image_pager_table").getElementsByTagName("input");
for(var i=0;i<_38.length;i++){
if(_38[i].type=="checkbox"){
_38[i].checked=_37;
}
}
};
this.updateDisplay=function(){
var _3a,_3b,_3c,_3d;
var _3e=$("image_pager_table");
var _3f=_3e.getElementsByTagName("tr");
var _40=Math.min(this.iTopLeftImage+this.iImagesPerPage,this.iImageCount)-1;
var _41=1+Math.floor((_40)/gConst.kImagesTableCols)%(this.iImagesPerPage/gConst.kImagesTableCols);
for(var i=0;i<_3f.length;i++){
if(_3a=_3f[i].id.match(/(pager|spacer)\-(\d+)/)){
_3b=parseInt(_3a[2]);
_3c=_3a[1]=="pager"?(_3b<_41):(_3b+1<_41);
_3d=this.getDisplayTableRowAttr(_3c);
_3f[i].style.display=_3d;
}
}
var _43=$("image_pager_table").getElementsByTagName("td");
var _44=0;
if(gConst.kIsMSIE6){
$("image_pager_table").style.display="none";
}
for(var i=0;i<_43.length&&_44<this.iImagesPerPage;i++){
_3a=_43[i].id.match(this.iCellMatchRegex);
if(_3a){
var _45=this.iTopLeftImage+_44;
if(_45<this.iImageCount){
if(_3a[2]!=this.iServerImages[_45].id){
this.setCellImage(_43[i],this.iServerImages[_45],true);
}
}else{
if(_3a[2]!=_44){
this.setCellImage(_43[i],this.getNullImage("null"+_44),false);
}
}
_44++;
}
}
if(gConst.kIsMSIE6){
window.setTimeout(function(){
$("image_pager_table").style.display="block";
},500);
}
$("pagingLinks").style.visibility=Math.ceil(this.iImageCount/this.iImagesPerPage)>1?"visible":"hidden";
var _46=this.iTopLeftImage>0?"visible":"hidden";
$("ip_first").style.visibility=_46;
$("ip_prev").style.visibility=_46;
var _47=this.iTopLeftImage+this.iImagesPerPage<this.iImageCount?"visible":"hidden";
$("ip_next").style.visibility=_47;
$("ip_last").style.visibility=_47;
var _48=this.iTopLeftImage/this.iImagesPerPage;
var _49=(gConst.kImagePagerPageLinks-1)/2;
var _4a=Math.ceil(this.iImageCount/this.iImagesPerPage);
for(var i=-_49;i<gConst.kImagePagerPageLinks-_49;i++){
var _4b=$("page"+i);
var _4c=_48+i;
var _4d=(_4c>=0&&_4c<_4a);
if(_4d){
_4c++;
_4b.replaceChild(document.createTextNode(_4c),_4b.firstChild);
}
_4b.style.visibility=_4d?"visible":"hidden";
if(i!=0){
$("pageBar"+i).style.visibility=_4d?"visible":"hidden";
}
}
$("emptyTableNote").style.display="none";
document.cookie="imageIndex="+(this.iTopLeftImage)+"; max-age=3600";
};
this.imageIsVisible=function(_4e){
return (_4e<this.iImageCount&&(_4e>=this.iTopLeftImage&&_4e<(this.iTopLeftImage+this.iImagesPerPage)));
};
this.pageShift=function(_4f){
var _50=this.iTopLeftImage+(this.iImagesPerPage*_4f);
if(_50>=0&&_50<this.iImageCount){
this.iTopLeftImage=_50;
this.updateDisplay();
}
};
this.gotoFirstPage=function(){
this.iTopLeftImage=0;
this.updateDisplay();
};
this.gotoLastPage=function(){
this.iTopLeftImage=Math.floor((this.iImageCount-1)/this.iImagesPerPage)*this.iImagesPerPage;
this.updateDisplay();
};
this.setEmptyTableNote=function(_51){
var _52=$("emptyTableNoteText");
while(_52.hasChildNodes()){
_52.removeChild(_52.firstChild);
}
_52.appendChild(document.createTextNode(_51));
$("emptyTableNote").style.display="block";
};
}
ImagePager.prototype.iTopLeftImage=0;
ImagePager.prototype.iImagesPerPage=null;
ImagePager.prototype.iImageCount=0;
ImagePager.prototype.iCellMatchRegex=null;
ImagePager.prototype.init=function(){
this.updateFromServer();
};
ImagePager.prototype.finishInit=function(){
$("loading_image_pager").style.display="none";
$("image_table_hider").style.display="block";
gPage.equaliseColumns();
$("ip_first").onclick=function(){
gPage.iImagePager.gotoFirstPage();
return false;
};
$("ip_prev").onclick=function(){
gPage.iImagePager.pageShift(-1);
return false;
};
$("ip_next").onclick=function(){
gPage.iImagePager.pageShift(1);
return false;
};
$("ip_last").onclick=function(){
gPage.iImagePager.gotoLastPage();
return false;
};
var _53=(gConst.kImagePagerPageLinks-1)/2;
for(var i=-_53;i<gConst.kImagePagerPageLinks-_53;i++){
if(i!=0){
$("page"+i).onclick=function(){
var m=this.id.match(/[\-0-9]*$/);
gPage.iImagePager.pageShift(m[0]);
return false;
};
}
}
this.iImagesPerPage=gConst.initialIPP;
var _56=$("image_pager_table").getElementsByTagName("input");
for(var i=0;i<_56.length;i++){
if(_56[i].type=="checkbox"){
_56[i].onclick=function(){
gPage.iImagePager.selectImageChanged(this);
};
}
}
this.rebuildRefIndexHash();
this.uncheckAll();
if(gConst.imageIndex){
this.iTopLeftImage=gConst.imageIndex-(gConst.imageIndex%this.iImagesPerPage);
this.updateDisplay();
}
};
ImagePager.prototype.getThumbPath=function(_57,_58){
return this.getImageRootPath()+"thumb/"+_57+".jpg";
};
ImagePager.prototype.updateImagesArray=function(){
var _59=[];
var id;
if(this.iServerImages){
for(var i=0;i<this.iServerImages.length;i++){
if(this.iServerImages[i].id){
_59[this.iServerImages[i].id]=this.iServerImages[i].selected;
}
}
}
this.iImageRootPath=iImageCollectionObject.path;
this.iServerImages=iImageCollectionObject.images;
this.iImageCount=this.iServerImages.length;
for(var i=0;i<this.iServerImages.length;i++){
this.iServerImages[i].selected=_59[this.iServerImages[i].id]?true:false;
}
};
ImagePager.prototype.setImageCount=function(_5c,_5d){
this.iImageCount=_5c;
if(_5d===undefined){
this.iTopLeftImage=Math.max(0,Math.ceil((this.iImageCount-this.iImagesPerPage)/this.iImagesPerPage)*this.iImagesPerPage);
}else{
if(_5d<this.iImageCount&&(_5d<this.iTopLeftImage||_5d+1>(this.iTopLeftImage+this.iImagesPerPage))){
this.iTopLeftImage=Math.max(0,Math.ceil((_5d+1-this.iImagesPerPage)/this.iImagesPerPage)*this.iImagesPerPage);
}
}
this.rebuildRefIndexHash();
this.updateDisplay();
gPage.equaliseColumns();
};
ImagePager.prototype.addImageCount=function(_5e,_5f){
if(_5f===undefined&&this.iTopLeftImage<(this.iImageCount+_5e)){
_5f=this.iTopLeftImage;
}
this.setImageCount(this.iImageCount+_5e,_5f);
if(this.iImageCount==0){
this.tableIsEmpty();
}
};
ImagePager.prototype.setImageMargins=function(_60,aW,aH){
var _63=-1;
if(aW>aH){
_63=Math.round((gConst.kThumbnailMaxSideLength-aH)/2);
}
_60.style.marginTop=_63+"px";
};
ImagePager.prototype.setImageMarginsFromOrigDimensions=function(_64,aW,aH){
var _67=-1;
if(aW>aH){
var _68=aW/gConst.kThumbnailMaxSideLength;
var _69=aH/_68;
_67=Math.round((gConst.kThumbnailMaxSideLength-_69)/2);
}
_64.style.marginTop=_67+"px";
};
if(gConst.kIsMSIE6||gConst.kIsMSIE7){
ImagePager.prototype.getDisplayTableRowAttr=function(_6a){
return _6a?"block":"none";
};
}else{
ImagePager.prototype.getDisplayTableRowAttr=function(_6b){
return _6b?"table-row":"none";
};
}
ImagePager.prototype.confirmDeleteItem=function(){
return true;
};
ImagePager.prototype.addDelDupInfo=function(_6c){
};
ImagePager.prototype.setApplyToSelected=function(_6d){
};
ImagePager.prototype.notifyObserversChanged=function(){
};
ImagePager.prototype.userFeedbackUpdating=function(){
};
ImagePager.prototype.errorFeedback=function(_6e){
gPage.iDialog=new TimedAlert("error",_6e);
gPage.iDialog.display();
};
ImagePager.prototype.clearUserFeedback=function(){
};
ImagePager.prototype.delDupComplete=function(_6f){
};
ImagePager.prototype.initFinished=function(){
};
ImagePager.prototype.iImageCollectionObject=null;
ImagePager.prototype.reset=function(){
iImageCollectionObject=null;
this.iImageRootPath=null;
this.iServerImages=null;
};
ImagePager.prototype.tableIsEmpty=function(){
};


