
var Glossary=function(urlBase)
{if(urlBase==undefined)
{urlBase='';}
Glossary.urlBase=urlBase;this.WS_GLOSSARY=urlBase+'ws/glossary/entry.php';this.glossaryPanel=null;this.history=null;};Glossary.last=null;Glossary.prototype.show=function(params,panelX,panelY,panelWidth,zIndex)
{if(this.glossaryPanel!=null)
{this.destroyPanel();}
if(params===null)
return;this.glossaryPanel=new YAHOO.widget.Panel('glossaryPanel',{width:panelWidth+'px',x:panelX,y:panelY,visible:true,draggable:true,close:true,iframe:(document.all&&!top.opera),monitorresize:false,constraintoviewport:true});this.history=[params];this.sendRequest(params);if(zIndex)
{this.glossaryPanel.cfg.setProperty('zIndex',zIndex);}
this.glossaryPanel.subscribe('hide',function(){this.glossaryPanel.cfg.setProperty('zIndex',1);},this,true);};Glossary.prototype.destroyPanel=function()
{this.glossaryPanel.destroy();this.glossaryPanel=null;};Glossary.prototype.sendRequest=function(params)
{Glossary.last=this;this.lastRequest=params;this.glossaryPanel.setHeader('<div class="tl"></div><span id="glossaryTitle">Glossary</span><div class="tr"></div>');this.glossaryPanel.setBody('<div class="glossaryText" id="glossaryText">Loading...</div>');this.glossaryPanel.setFooter('<div id="gl_bl" class="bl"></div><span></span><div id="gl_br" class="br"></div>');this.glossaryPanel.render(document.body);try
{var arr=[];for(var x in params)arr.push(x+'='+params[x]);var url=this.WS_GLOSSARY+'?'+arr.join('&');var callback={scope:this,success:this.processResponse};YAHOO.util.Connect.asyncRequest('GET',url,callback);}
catch(e)
{alert("Failed to retrieve glossary entry, make sure you are using a supported browser.");}};Glossary.prototype.processResponse=function(response)
{var Dom=YAHOO.util.Dom,Evt=YAHOO.util.Event;var result=null,title='Error',content='',images=[];try
{eval('result = '+response.responseText);if(!result.error)
{title=result.title;content=result.content;images=result.images;this.currentEntry=result;}
else
{content=result.error;}}
catch(e)
{title='Error';content='Failed to process entry data.';}
var old;do
{old=content;content=content.replace(/(\[\[)([^(\])]+)(\]\])/,Glossary.makeLink);}while(old!=content);if(images.length>0)content+='<div class="glossary-images">';for(var i=0;i<images.length;i++)
{if(i%3==0){content+='<div class="spacer"></div>';}
var img=images[i];content+='<a title="'+img.imagecaption+'" '
+'href="javascript:Glossary.showImage('+img.imageid+','
+img.width+','+img.height+')">'
+'<img width="75" height="75" src="'+Glossary.urlBase+'img'+img.imageid+'_75x75"></a>';}
if(images.length>0)content+='</div>';Dom.get('glossaryTitle').innerHTML=title;Dom.get('glossaryText').innerHTML=content;var back=Dom.get('glossaryBack');if(back&&(!this.history||this.history.length<=1))
{back.parentNode.removeChild(back);}
else if(!back&&this.history&&this.history.length>1)
{var b=document.createElement('span');b.className='back';b.id='glossaryBack';Dom.get('glossaryPanel').appendChild(b);Evt.addListener('glossaryBack','click',this.back,this,true);}
if(document.all&&!top.opera)
{Dom.get('gl_bl').className='bl';Dom.get('gl_br').className='br';this.glossaryPanel.onDomResize();}};Glossary.prototype.linkClick=function(entryName)
{var params={'name':entryName};this.history.push(params);this.sendRequest(params);};Glossary.prototype.back=function()
{this.history.pop();this.sendRequest(this.history[this.history.length-1]);};Glossary.makeLink=function(full,ob,match,cb)
{match=match.split('|');var entry=match[0];var link=(match[1])?match[1]:entry;return'<a href="javascript:Glossary.last.linkClick(\''+entry+'\')">'+link+'</a>';};Glossary.showImage=function(imageId,w,h)
{var url=Glossary.urlBase+'glossaryimages.php?iid='+imageId;w+=20;h+=100;window.open(url,'glossaryImgWnd','toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=no, width='+w+', height='+h);};