var _JSONGalleryData;
var gA=infradoxApp, gX=infradoxAjax,
infradoxGallery={initialize:function(tpath,divGalText,labelNoText,divGalItemsContr,makeTextContrVisible,lblHide,lblShow){if(!gX.createXMLHttpRequest()){alert('Not supported. Please upgrade your browser');return;}
var o=this;
o._thumbnailpath=tpath;
o._divGalleryText=divGalText;
o._labelNoTextAvailable=labelNoText;
o._divGalleryItemsContainer=divGalItemsContr;
o._labelHide=lblHide;
o._labelShow=lblShow;
o._parentid;
o._id;
o._glbid;
o._tlid;
o._getTitleCallback;
o._getThumbnailCallback;
o._groupChangeCallback;
o._gallerypropschangeCallback;
o._becallback=null;
o._galleryprops;
o._itemsdatatemplate='gi-itemsdata.html';
o._templateslots='gl-images-content.inc';
o._TOC_addChildren=null;
o._TOC_addChildrenCallback=null;
if(makeTextContrVisible){var e=gete(this._divGalleryText);
if(e) e.style.display="block";}},
putGallery:function(parentid,id,glbid,tlid){if(parentid) this._parentid=parentid;
if(id) this._id=id;
if(glbid) this._glbid=glbid;
if(tlid) this._tlid=tlid;},
getGalleryCoded:function(){return this._tlid+'_'+this._parentid+'_'+this._id+'_'+this._glbid;},
randomizeGroups:function(jGroups,containerId,boxClass,thumbnailClass,captionClass){var e=gete(containerId);
if(!e) return;
e.innerHTML='';
var thumb,parentid=0,data=jGroups.data;
for(var i=0;i<data.length;i++){if(data[i]){if(data[i].parentid!=parentid){if(parentid!=0){this.paintRandomGroupThumbnail(grps,containerId,boxClass,thumbnailClass,captionClass);}
parentid=data[i].parentid;
var grps=new Array();}
grps[grps.length]=data[i];}}
this.paintRandomGroupThumbnail(grps,containerId,boxClass,thumbnailClass,captionClass);},
createThumbnail:function(c,data,level,boxClass,thumbnailClass,captionClass){var box,thumb,s,capt,tn;
box=gA.createDomElement({type:"div",className:boxClass},c);
thumb=gA.createDomElement({type:"div",className:thumbnailClass});
s='';
if(this._getThumbnailCallback){s=this._getThumbnailCallback(level,data);
} else if(data.ref){s='url('+this._thumbnailpath+data.ref+'.jpg)';}
if(s) thumb.style.backgroundImage=s;
if(this._getTitleCallback){s=this._getTitleCallback(level,data);
}else{s=(level==1)?data.parentname:data.title;}
capt=gA.createDomElement({type:"div",className:captionClass,text:""});
capt.id='capt_'+data.ref;
capt.innerHTML=s;
box.appendChild(thumb);
box.appendChild(capt);
return [thumb,capt];},
paintRandomGroupThumbnail:function(grps,containerId,boxClass,thumbnailClass,captionClass){var r,e,thumb,thumbparentnode;
if(!grps) return;
r=gA.randomize(grps.length-1);
e=gete(containerId);
thumb=this.createThumbnail(e,grps[r],1,boxClass,thumbnailClass,captionClass);
if(thumb){thumb[0].id='tli_'+grps[r].parentid;
infradoxLinkHandler.listen(thumb[0].id);
if(thumb[1]){thumb[1].id='cli_'+grps[r].parentid;
infradoxLinkHandler.listen(thumb[1].id);}}},
relayClickToParent:function(e,fHandler){var _id;
if(!e) return;
e=e.parentNode;
if(!e) return;
_id=e.id.replace('_strip_','');
fHandler(_id);},
TOC_makenodevisible:function(){var ul,li;
li=gete('gid_'+this._parentid+'_'+this._id+'_'+this._glbid);
if(li) return;
ul=gete('TOC');
if(!ul.hasChildNodes()) return;
for(var i=0;i<ul.childNodes.length;i++){li=ul.childNodes[i];
if(li&&li.id){if(li.id=='li_'+this._parentid){if(li.className!='selectedGroup'){li.className='selectedGroup';
this.TOC_loadGroupChildren(this._parentid);}
break;}}}},
TOC_changeGroup:function(id,updateTOConly,containerId,boxClass,thumbnailClass,captionClass){var li,s,div,ids,e,ul,ulp,collapse=0;
gA.loadingcontent(1);
e=gete('li_'+id);
if(e){if(e.className=='selectedGroup'){e.className='';
collapse=1;}}
this._updateTOConly=updateTOConly;
this._containerId=containerId;
this._boxClass=boxClass;
this._thumbnailClass=thumbnailClass;
this._captionClass=captionClass;
if(!collapse){ul=gete('TOC');
}else{ul=e;}
if(ul.hasChildNodes()){for(var i=0;i<ul.childNodes.length;i++){li=ul.childNodes[i];
if(li&&li.id){li.className='';
if(li.hasChildNodes()){ids=li.id.split('_');
s='p_'+ids[1]+'_c';
ulp=gete(s);
if(ulp){while(ulp.hasChildNodes()) ulp.removeChild(ulp.childNodes[0]);}}}}}
if(!collapse){this.TOC_loadGroupChildren(id);
}else{gA.loadingcontent(0);}},
TOC_loadGroupChildren:function(id){var o=this;
url=gA.dll+'go?a=disp&t='+this._itemsdatatemplate+'&parentid='+id+'&si='+gA.session+'&rnd='+gA.getTimeStamp();
try {gX.getRequest(url,function(){_JSONGalleryData=eval('('+gX.xmlHttp.responseText+')');
if(o._TOC_addChildren){o._TOC_addChildren();
}else{o.TOC_addChildren();}
});
} catch(err){alert(err);}
gA.loadingcontent(0);},
TOC_addChildren:function(){var parentid,pn,data,li,tn,thumb,e,c,_id;
if(!_JSONGalleryData) return;
parentid=_JSONGalleryData.parentid;
pn=gete('p_'+parentid+'_c');
if(!pn) return;
data=_JSONGalleryData.data;
if(!data) return;
e=gete('li_'+parentid);
if(e) e.className='selectedGroup';
if(this._groupChangeCallback){this._groupChangeCallback(e.id,gA.getInnerText(e));}
for(var i=0;i<data.length;i++){if(data[i]){li=document.createElement('li');
li.id='gid_'+parentid+'_'+data[i].id+'_'+data[i].glbid;
if(data[i].id==this._id){li.className='selectedGallery';}
li.innerHTML=iA.JSONSafeToString(data[i].title);
pn.appendChild(li);
infradoxLinkHandler.listen(li.id);}}
if(this._updateTOConly){if(this._TOC_addChildrenCallback){this._TOC_addChildrenCallback(_JSONGalleryData);}
return;}
c=gete(this._containerId);
if(!c){if(this._TOC_addChildrenCallback){this._TOC_addChildrenCallback(_JSONGalleryData);}
return;}
c.innerHTML='';
for(var i=0;i<data.length;i++){if(data[i]){thumb=infradoxGallery.createThumbnail(c,data[i],2,this._boxClass,this._thumbnailClass,this._captionClass);
if(thumb){_id='xgid_'+parentid+'_'+data[i].id+'_'+data[i].glbid;
thumb[0].id=_id;
thumb[1].id='_strip_'+_id;
infradoxLinkHandler.listen(thumb[0].id);};}}
if(this._TOC_addChildrenCallback){this._TOC_addChildrenCallback(_JSONGalleryData);}},
toggleTextPanel:function(divText,labelHide,labelShow){var style,tn,newNode,e;
e=gete(divText);
if(e){style=e.style;
style.display=style.display?"":"block";
tn=gete('linkToggleTextPanel');
newNode=document.createTextNode(e.style.display?labelHide:labelShow);
tn.replaceChild(newNode,tn.childNodes[0]);}},
hideTextPanel:function(){var e,style,tn,newNode;
e=gete(this._divGalleryText);
if(e){style=e.style;
style.display="";
tn=gete('linkToggleTextPanel');
newNode=document.createTextNode(this._labelShow);
tn.replaceChild(newNode,tn.childNodes[0]);}},
showTextPanel:function(){var e,style,tn,newNode;
e=gete(this._divGalleryText);
if(e){style=e.style;
style.display="block";
tn=gete('linkToggleTextPanel');
newNode=document.createTextNode(this._labelHide);
tn.replaceChild(newNode,tn.childNodes[0]);}},
loadGalleryText:function(id){var o=this;
gX.xmlHttpBusy=0;
url=gA.dll+'go?a=disp&ns=1&t=gl-gallerytext.html&galleryid='+id+'&si='+gA.session+'&rnd='+gA.getTimeStamp();
gX.getRequest(url,function(){o.loadGalleryTextResponse(o);});},
loadGalleryTextResponse:function(o){var gtitle,html=gX.xmlHttp.responseText.split('__________');
if(html.length!=2){alert('The retrieved data appears to be invalid. Your session may have expired.');
return;}
eval('infradoxGallery._galleryprops='+html[0]);
if(o._gallerypropschangeCallback){o._gallerypropschangeCallback();
}else{gtitle=o._galleryprops.title;
gA.showTrail({main:1,mainaslink:0,sub:1,subaslink:0,extended:[{label:gtitle,linkid:null}]},null);
var e=gete(o._divGalleryText);
if(o._galleryprops.desc==''){e.innerHTML=o._labelNoTextAvailable;
o.hideTextPanel();
}else{e.innerHTML=o._galleryprops.desc;}}},
loadCollection:function(glbid,pageNo,params){var s,lip,li,o=this;
gA.loadingcontent(1);
s=params||'&lg=2&ls='+infradoxState.props.data.layout.style+'&so='+infradoxState.props.data.layout.option;
url=gA.dll+'go?a=disp&pt=8&ih=gogloballightbox_'+glbid+'&page='+pageNo+s+'&t='+this._templateslots+'&si='+gA.session+'&rnd='+gA.getTimeStamp();
gX.getRequest(url,function(){infradoxGallery.loadCollectionResponse(o)});
if(pageNo==1){lip=gete('p_'+this._parentid+'_c');
if(lip&&lip.hasChildNodes()){for(var i=0;i<lip.childNodes.length;i++){li=lip.childNodes[i];
if(li&&li.id) li.className='';}}
li=gete('gid_'+this._parentid+'_'+this._id+'_'+this._glbid);
if(li) li.className='selectedGallery';}},
loadCollectionResponse:function(o){var e,s;
gA.loadingcontent(0);
e=gete(infradoxGallery._divGalleryItemsContainer);
if(!e) return;
s=gX.xmlHttp.responseText.split('__________');
if(s.length!=3){alert('The retrieved data appears to be invalid. Please start a new session');
return;}
infradoxState.putPageData(eval('('+s[0]+')'));
infradoxPagination.showpagination();
eval(s[1]);
e.innerHTML=s[2];
infradoxMedia.initialize(content);
o.loadGalleryText(infradoxGallery._id);
scroll(0,0);
if(o._becallback) o._becallback();},
toggleToolbox:function(subfolder){var img=gete('linkToggleToolbox');
var toc=gete('TOC_container');
if(!toc) return;
toc.className=(toc.className=='indexTOCcontainer1')?'indexTOCcontainer0':'indexTOCcontainer1';
if(img) img.src="/images/"+subfolder+"toolbox-gtoc_"+((toc.className=='indexTOCcontainer1')?"1":"0")+".gif";
infradoxState.toggleSetting('_toc');
return 1;}}

