
var gpgembd=null;var gfnEmbdPhotoGalleryNum=null;function EmbdPG(){var self=this;this.imgLoader=new ImagePreloader(function(bLoaded,image){self.imageLoaderCallBack(bLoaded,image)});this.opacityFadeEffect=null;this.photoPath=null;this.photos=null;this.photoDescriptions=null;this.loadingNum=0;this.fContentMode=false;this.contentModeCallback=null;this.currentPhotoNum=-1;this.overlay=null;this.centerLeftPos=0;this.staticLeftPos=0;this.centerWidth=480;this.centeredDivMode=false;this.filemode=true;this.nextTitle=null;this.uriPhotoNextTitle=null;this.oldBodyBg=null;this.overlayDisabled=false;this.overlayAnimation=true;this.preferredWidth=0;this.preferredHeight=0;this.loadedPhoto=null;this.loadingScreenAnimationDone=false;this.busy=false;this.imageLoadingIndicator="/images/pgembd/loading.gif";this.imagePrevPhoto="/images/pgembd/prev.gif";this.imageNextPhoto="/images/pgembd/next.gif";this.imageClose="/images/pgembd/close.gif";this.delayedPSTimer=null;this.fCloseButtonAtTop=false;this.fPNGCloseButton=false;this.xPNGCloseButtonOffset=0;this.yPNGCloseButtonOffset=0;this.borderWidth=10;}
EmbdPG.prototype.setCloseButtonAtTop=function(state){this.fCloseButtonAtTop=state;}
EmbdPG.prototype.setPNGCloseButton=function(state,xOffset,yOffset){this.fPNGCloseButton=state;this.xPNGCloseButtonOffset=xOffset;this.yPNGCloseButtonOffset=yOffset;}
EmbdPG.prototype.setBorderWidth=function(width){this.borderWidth=width;}
EmbdPG.prototype.getOverlayTargetElement=function(){return document.body;}
EmbdPG.prototype.createOverlay=function(cxPhoto,cyPhoto,iStartPhoto){if(this.overlayAnimation){return this.createOverlayAnimated(cxPhoto,cyPhoto,iStartPhoto);}}
EmbdPG.prototype.createOverlayAnimated=function(cxPhoto,cyPhoto,iStartPhoto){this.queuedImage=null;this.fadeUpCP=true;this.loadingScreenAnimationDone=false;this.blurAnyInput();this.closeEmbeddedPhotoGallery();this.preferredWidth=cxPhoto+0;this.preferredHeight=cyPhoto+30;var centeredDiv=this.getOverlayTargetElement();if(!centeredDiv)
centeredDiv=document.getElementById("wrap");if(!centeredDiv)
return;var st=getPageScrollTop();var wsz=getWindowSize();var y=Math.floor((wsz[1]-this.preferredHeight)/2);if(y<0)
y=0;if(this.yPNGCloseButtonOffset<0){y-=this.yPNGCloseButtonOffset;}
var self=this;if(!this.overlayDisabled){if(!this.overlay){this.overlay=document.createElement("div");this.overlay.id="overlay_pgembd";this.overlay.className="overlay_pgembd";this.overlay.onclick=function(){self.closeEmbeddedPhotoGallery();return false;};var h=getPageHeight();if(h<st[1]+wsz[1]){h=st[1]+wsz[1];}
if(h<y+st[1]+this.preferredHeight){h=y+st[1]+this.preferredHeight+this.borderWidth;}
this.overlay.style.height=h+"px";this.overlay.style.width=getWindowSize()[0]+"px";}else{if(this.overlay.filters)
this.overlay.filters.alpha.opacity=0;this.overlay.style.opacity=0;var h=getPageHeight();if(h<st[1]+wsz[1]){h=st[1]+wsz[1];}
if(h<y+st[1]+this.preferredHeight){h=y+st[1]+this.preferredHeight+this.borderWidth;}
this.overlay.style.height=h+"px";this.overlay.style.width=getWindowSize()[0]+"px";}
document.body.className="overlay";centeredDiv.appendChild(this.overlay);}
this.loadingNum=iStartPhoto;var self=this;this.fnKeyPress=function(ev){return self.keyPress(ev)};this.fnWindowResize=function(ev){return self.windowResize(ev)};dw_Event.add(document.body,"keyup",this.fnKeyPress,false);dw_Event.add(window,"keyup",this.fnKeyPress,false);dw_Event.add(window,"resize",this.fnWindowResize,false);var overlayEffect=new OpacityFadeEffect(0.4);overlayEffect.startFadeEffect(this.overlay,null,false,function(){self.overlayAnimationCallback()},0.7);return true;}
EmbdPG.prototype.overlayAnimationCallback=function(){var content=document.createElement("div");content.id="content_pgembd";content.className="content_pgembd_loading";if(this.photos&&this.photos.length==1){var self=this;content.onclick=function(){self.closeEmbeddedPhotoGallery();return false;};}
var left=0;var st=getPageScrollTop();var wsz=getWindowSize();left=Math.floor((wsz[0]-(200))/2)+this.centerLeftPos;if(left<0)
left=0;content.style.marginLeft=left+"px";var y=Math.floor((wsz[1]-200)/2);if(y<0)
y=0;if(this.yPNGCloseButtonOffset<0){y-=this.yPNGCloseButtonOffset;}
content.style.top=(y+st[1])+"px";document.body.appendChild(content);this.fadeInLoadingContent();}
EmbdPG.prototype.fadeInLoadingContent=function(){var content=document.getElementById("content_pgembd");if(this.opacityFadeEffect==null){this.opacityFadeEffect=new OpacityFadeEffect();}
var self=this;this.opacityFadeEffect.startFadeEffect(content,null,false,function(){self.waitForPhoto()});}
EmbdPG.prototype.waitForPhoto=function(){this.loadingScreenAnimationDone=true;if(this.loadedPhoto)
this.animatePhotoContent(this.loadedPhoto);else if(this.fContentMode)
this.contentModeCallback();}
EmbdPG.prototype.animatePhotoContent=function(image){var content=document.getElementById("content_pgembd");content.className="content_pgembd_loaded";var st=getPageScrollTop();if(this.yPNGCloseButtonOffset<0){st[1]-=this.yPNGCloseButtonOffset;}
var wsz=getWindowSize();var content=document.getElementById("content_pgembd");var cy=content.clientHeight||content.offsetHeight;var self=this;var effect=new SetHeightDoubleElementEffect(content,cy,image.height+(this.borderWidth*2),null,0,0,function(){self.overlayAnimationHeightCallback()},false,0.5,false,wsz[1],st[1]);effect.startEffect();}
EmbdPG.prototype.overlayAnimationHeightCallback=function(){var wsz=getWindowSize();var content=document.getElementById("content_pgembd");var cx=content.clientWidth||content.offsetWidth;var self=this;var effect=new SetWidthElementEffect(content,cx,this.loadedPhoto.width+(this.borderWidth*2),function(){self.overlayAnimationWidthCallback()},0.5,wsz[0],this.centerLeftPos);effect.startEffect();}
EmbdPG.prototype.overlayAnimationWidthCallback=function(){var elPhoto=document.getElementById("pgembd_photo");var cxHoverButton=Math.floor(this.loadedPhoto.width/2)-(this.borderWidth*2);var cyHoverButton=this.loadedPhoto.height;if(elPhoto){elPhoto.width=this.loadedPhoto.width;elPhoto.height=this.loadedPhoto.height;elPhoto.src=this.loadedPhoto.src;if(this.photos.length>1){var elPrev=document.getElementById("pgembd_hoverbutton_area_prev");elPrev.style.width=cxHoverButton+"px";elPrev.style.height=cyHoverButton+"px";var elNext=document.getElementById("pgembd_hoverbutton_area_next");elNext.style.width=cxHoverButton+"px";elNext.style.height=cyHoverButton+"px";}
setElementsByIdsDisplayInline("pgembd_photo");setElementsByIdsDisplayBlock("pgembd_photo_over","pgembd_hoverbutton_area_prev","pgembd_hoverbutton_area_next");}else{var content=document.getElementById("content_pgembd");var str="<div style='background: white; position: relative; padding: 0px;'>";if(this.photos.length>1){str+="<img id='pgembd_hoverbutton_prev' src='"+this.imagePrevPhoto+"' />";str+="<img id='pgembd_hoverbutton_next' src='"+this.imageNextPhoto+"' />";str+="<div id='pgembd_hoverbutton_area_prev' class='pgembd_hoverbutton' style=\"width: "+cxHoverButton+"px; height: "+cyHoverButton+"px\">&nbsp;</div>";str+="<div id='pgembd_hoverbutton_area_next' class='pgembd_hoverbutton' style=\"width: "+cxHoverButton+"px; height: "+cyHoverButton+"px\">&nbsp;</div>";}
str+="<div id='pgembd_photo_over' style='position: absolute; z-index: 2000; visibility: visible; background: white; top: "+this.borderWidth+"px; left: "+this.borderWidth+"px; filter:alpha(opacity=100); -moz-opacity:1.0; opacity:1.0; width: "+this.loadedPhoto.width+"px; height: "+this.loadedPhoto.height+"px'></div>";str+="<img id='pgembd_photo' style='border: "+this.borderWidth+"px solid white; vertical-align: center;' src='"+this.loadedPhoto.src+"' width='"+this.loadedPhoto.width+"' height='"+this.loadedPhoto.height+"' alt='' />";str+="</div>";if(this.photos.length>1){str+="<div id='pgembd_photoselector' class='pgembd_photoselector'><ul>";for(var i=0;i<this.photos.length;i++){str+="<li><a id='photosel_"+i+"' onclick='gfnEmbdPhotoGalleryNum("+i+"); return false;' href='javascript:void(0);'><span>"+(i+1)+"</span></a></li>";}
str+="</ul></div>";var self=this;gfnEmbdPhotoGalleryNum=function(num){self.photoGalleryNum(num);return false;};content.innerHTML=str;var el=document.getElementById("pgembd_hoverbutton_area_prev");el.onclick=function(){self.photoGalleryPrev(el);return false};el.onmouseover=function(){self.nextPrevMouseOver(el);};el.onmouseout=function(){self.nextPrevMouseOut(el);};var el2=document.getElementById("pgembd_hoverbutton_area_next");el2.onclick=function(){self.photoGalleryNext(el2);return false;};el2.onmouseover=function(){self.nextPrevMouseOver(el2);};el2.onmouseout=function(){self.nextPrevMouseOut(el2);};var el3=document.getElementById("pgembd_photoselector");el3.onmouseover=function(){self.selectPhotoMouseOver(el3)};el3.onmouseout=function(){self.selectPhotoMouseOut(el3)};}else
content.innerHTML=str;}
this.fadeInPhoto(this.loadedPhoto);}
EmbdPG.prototype.selectPhotoMouseOver=function(el){if(this.delayedPSTimer){clearTimeout(this.delayedPSTimer);this.delayedPSTimer=null;}
JSFX.fadeUpElem("pgembd_photoselector",10,50);}
EmbdPG.prototype.selectPhotoMouseOut=function(el){if(this.delayedPSTimer==null){var self=this;this.delayedPSTimer=setTimeout(function(){self.selectPhotoFadeout()},100);}}
EmbdPG.prototype.selectPhotoFadeout=function(){JSFX.fadeDownElem("pgembd_photoselector",10);this.delayedPSTimer=null;}
EmbdPG.prototype.nextPrevMouseOver=function(el){JSFX.fadeUpElem(el.id=="pgembd_hoverbutton_area_prev"?'pgembd_hoverbutton_prev':'pgembd_hoverbutton_next',10,80);this.selectPhotoMouseOver();}
EmbdPG.prototype.nextPrevMouseOut=function(el){JSFX.fadeDownElem(el.id=="pgembd_hoverbutton_area_prev"?'pgembd_hoverbutton_prev':'pgembd_hoverbutton_next',10);this.selectPhotoMouseOut();}
EmbdPG.prototype.keyPress=function(e){var srcElement=e?(e.target?e.target:e.srcElement):event.srcElement;var keyCode=getKeyCode(e);if(srcElement&&srcElement.nodeName!='TEXTAREA'&&srcElement.nodeName!='INPUT'){if(keyCode==37){this.photoGalleryPrev();return false;}else if(keyCode==32||keyCode==39){this.photoGalleryNext();return false;}else if(keyCode==27){this.closeEmbeddedPhotoGallery();return false;}}
return true;}
EmbdPG.prototype.windowResize=function(e){var st=getPageScrollTop();var wsz=getWindowSize();var h=getPageHeight();if(h<st[1]+wsz[1]){h=st[1]+wsz[1];}
if(this.overlay){this.overlay.style.height=h+"px";this.overlay.style.width=getWindowSize()[0]+"px";var content=document.getElementById("content_pgembd");if(content){var cx=content.clientWidth||content.offsetWidth;var cy=content.clientHeight||content.offsetHeight;var left=Math.floor((wsz[0]-(cx))/2)+this.centerLeftPos;if(left<0)
left=0;content.style.marginLeft=left+"px";var y=Math.floor((wsz[1]-cy)/2);if(y<0)
y=0;if(this.yPNGCloseButtonOffset<0){y-=this.yPNGCloseButtonOffset;}
var top=(y+st[1]);content.style.top=top+"px";var cp=document.getElementById("pgembd_cp");if(cp){if(this.fCloseButtonAtTop){cp.style.top=(top+this.yPNGCloseButtonOffset)+"px";}else
cp.style.top=(top+this.loadedPhoto.height+(this.borderWidth*2)-33)+"px";cp.style.marginLeft=(left+this.loadedPhoto.width+(this.borderWidth*2)+this.xPNGCloseButtonOffset)+"px";}}}
return true;}
EmbdPG.prototype.loadEmbeddedPhotoGallery=function(cxPhoto,cyPhoto,iStartPhoto,path,photos){if(this.busy)return;this.busy=true;this.loadedPhoto=null;this.filemode=true;this.photoPath=path;this.photos=new Array();for(var i=4;i<arguments.length;i++){this.photos.push(arguments[i]);}
var flashDivs=document.getElementsByTagName("div");for(var i=0;i<flashDivs.length;i++){if(flashDivs[i].className=="flash"){flashDivs[i].style.visibility="hidden";}}
this.createOverlay(300,300,iStartPhoto);this.imgLoader.preload(path+this.photos[iStartPhoto]);}
EmbdPG.prototype.loadEmbeddedPhotoGalleryDB=function(cxPhoto,cyPhoto,iStartPhoto,pgid,photos){if(this.busy)return;this.busy=true;this.loadedPhoto=null;this.filemode=false;this.pgid=pgid;this.photos=new Array();for(var i=4;i<arguments.length;i++){this.photos.push(arguments[i]);}
var flashDivs=document.getElementsByTagName("div");for(var i=0;i<flashDivs.length;i++){if(flashDivs[i].className=="flash"){flashDivs[i].style.visibility="hidden";}}
this.createOverlay(300,300,iStartPhoto);this.getPhotoWithPid(this.pgid,this.photos[iStartPhoto]);}
EmbdPG.prototype.closeEmbeddedPhotoGallery=function(){if(this.busy)return;var overlay=document.getElementById("overlay_pgembd");var content=document.getElementById("content_pgembd");var el=this.getOverlayTargetElement();var elCP=document.getElementById("pgembd_cp");if(el&&content){if(!this.overlayDisabled&&overlay){document.body.className="";el.removeChild(overlay);}else if(this.overlayDisabled)
document.body.className="";content.parentNode.removeChild(content);if(elCP)
elCP.parentNode.removeChild(elCP);var flashDivs=document.getElementsByTagName("div");for(var i=0;i<flashDivs.length;i++){if(flashDivs[i].className=="flash"){flashDivs[i].style.visibility="visible";}}
dw_Event.remove(document.body,"keyup",this.fnKeyPress,false);dw_Event.remove(window,"keyup",this.fnKeyPress,false);dw_Event.remove(window,"resize",this.fnWindowResize,false);}}
EmbdPG.prototype.imageLoaderCallBack=function(bLoaded,image){if(this.loadedPhoto){var fDiffSize=image.width!=this.loadedPhoto.width||image.height!=this.loadedPhoto.height;this.loadedPhoto=image;var elPhotoOver=document.getElementById("pgembd_photo_over");setElementsByIdsVisible("pgembd_photo_over");var self=this;this.opacityFadeEffect.startFadeEffect(elPhotoOver,null,false,function(){if(fDiffSize){setElementsByIdsDisplayNone("pgembd_photo","pgembd_cp","pgembd_hoverbutton_area_prev","pgembd_hoverbutton_area_next");setElementsByIdsDisplayNone("pgembd_photo_over");self.animatePhotoContent(image);}else{var elPhoto=document.getElementById("pgembd_photo");elPhoto.src=image.src;self.fadeInPhoto(image);}});}else{this.loadedPhoto=image;if(this.loadingScreenAnimationDone){this.animatePhotoContent(image);}}}
EmbdPG.prototype.fadeInBackground=function(image){var content=document.getElementById("content_pgembd");if(this.opacityFadeEffect==null){this.opacityFadeEffect=new OpacityFadeEffect();}
var self=this;this.opacityFadeEffect.startFadeEffect(content,null,false,function(){self.fadeInPhoto(image)});}
EmbdPG.prototype.fadeInPhoto=function(image){var el=document.getElementById("photosel_"+this.currentPhotoNum);if(el)
el.className="";this.currentPhotoNum=this.loadingNum;el=document.getElementById("photosel_"+this.currentPhotoNum);if(el)
el.className="active";var elPhoto=document.getElementById('pgembd_photo');if(elPhoto){var content=document.getElementById("content_pgembd");var elPhotoOver=document.getElementById("pgembd_photo_over");if(elPhotoOver.filters)
elPhotoOver.filters.alpha.opacity=100;elPhotoOver.style.opacity=1.0;elPhotoOver.style.width=image.width+"px";elPhotoOver.style.height=image.height+"px";elPhotoOver.style.visibility="visible";var self=this;this.opacityFadeEffect.startFadeEffect(elPhotoOver,null,true,function(){self.photoOverFadedOut()});if(this.nextTitle){if(image.src.indexOf(this.uriPhotoNextTitle)>=0){var el=document.getElementById("pgembd_photo_title");if(el){el.innerHTML=this.nextTitle;return;}}}
var el=document.getElementById("pgembd_photo_title");if(el)
el.innerHTML="";}}
EmbdPG.prototype.photoOverFadedOut=function(){setElementsByIdsHidden("pgembd_photo_over");var fFirst=false;var content=document.getElementById("content_pgembd");var cp=document.getElementById("pgembd_cp");if(cp&&cp.style.display!="none"){this.busy=false;return;}
if(!cp){fFirst=true;cp=document.createElement("div");cp.id="pgembd_cp";cp.className="pgembd_cp";if(this.fPNGCloseButton){cp.innerHTML="<div><a id='pgembd_close' href='javascript: void(0);'></a></div>";}else
cp.innerHTML="<div style='padding: 8px 0px 0px 8px'><a id='pgembd_close' href='javascript: void(0);'><img src='"+this.imageClose+"' /></a></div>";}
var x=parseInt(content.style.marginLeft);var y=parseInt(content.style.top);x+=this.loadedPhoto.width+(this.borderWidth*2);if(this.fCloseButtonAtTop)
cp.style.top=(y+this.yPNGCloseButtonOffset)+"px";else
cp.style.top=(y+this.loadedPhoto.height+(this.borderWidth*2)-33)+"px";cp.style.marginLeft=(x+this.xPNGCloseButtonOffset)+"px";cp.style.width="0px";if(fFirst){document.body.appendChild(cp);var el=document.getElementById("pgembd_close");var self=this;el.onclick=function(){self.closeEmbeddedPhotoGallery();return false;};}else
cp.style.display="block";var self=this;if(this.fPNGCloseButton){var effect=new OpacityFadeEffect(0.4);effect.startFadeEffect(document.getElementById("pgembd_close"),null,false,function(){self.controlPanelWidthCallback()});}else{var effect=new SetWidthElementEffect(cp,0,34,function(){self.controlPanelWidthCallback()},0.3);effect.startEffect();}}
EmbdPG.prototype.controlPanelWidthCallback=function(){this.windowResize();this.busy=false;}
EmbdPG.prototype.getPhotoWithPid=function(pgid,pid){var self=this;return new AJAXRequest("POST","/photo2.jspax","pgid="+pgid+"&pid="+(pid),"",function(myAJAX){return self.processGetPhotoXML(myAJAX);});}
EmbdPG.prototype.processGetPhotoXML=function(myAJAX){if(myAJAX.readyState==4){if(myAJAX.status==200){var xml=myAJAX.responseXML;if(xml.documentElement){var status=xml.documentElement.getAttributeNode("status").nodeValue;if(status=="OK"){var photoURI=xml.documentElement.getElementsByTagName("uri")[0].firstChild.nodeValue;var titles=xml.documentElement.getElementsByTagName("title");if(titles.length){this.nextTitle=titles[0].firstChild.nodeValue;this.uriPhotoNextTitle=photoURI;}else{this.nextTitle=null;}
if(photoURI){this.imgLoader.preload(photoURI);}}else if(status=="login"){openLoginForm(loggedInNowCallback,"mg",false,1);}}}}}
EmbdPG.prototype.photoGalleryPrev=function(){if(this.currentPhotoNum>0&&!this.busy){this.busy=true;this.loadingNum=this.currentPhotoNum-1;if(this.filemode){if(this.photoDescriptions){this.nextTitle=this.photoDescriptions[this.loadingNum];this.uriPhotoNextTitle=this.photoPath+this.photos[this.loadingNum];}
this.imgLoader.preload(this.photoPath+this.photos[this.loadingNum]);}else
this.getPhotoWithPid(this.pgid,this.photos[this.loadingNum]);}}
EmbdPG.prototype.photoGalleryNext=function(){if(this.currentPhotoNum+1<this.photos.length&&!this.busy){this.busy=true;this.loadingNum=this.currentPhotoNum+1;if(this.filemode){if(this.photoDescriptions){this.nextTitle=this.photoDescriptions[this.loadingNum];this.uriPhotoNextTitle=this.photoPath+this.photos[this.loadingNum];}
this.imgLoader.preload(this.photoPath+this.photos[this.loadingNum]);}else
this.getPhotoWithPid(this.pgid,this.photos[this.loadingNum]);}}
EmbdPG.prototype.photoGalleryNum=function(num){if(num>=0&&num<this.photos.length&&!this.busy){this.busy=true;this.loadingNum=num;if(this.filemode){if(this.photoDescriptions){this.nextTitle=this.photoDescriptions[this.loadingNum];this.uriPhotoNextTitle=this.photoPath+this.photos[this.loadingNum];}
this.imgLoader.preload(this.photoPath+this.photos[this.loadingNum]);}else
this.getPhotoWithPid(this.pgid,this.photos[this.loadingNum]);}}
EmbdPG.prototype.blurAnyInput=function(){var inputs=document.getElementsByTagName('input');if(inputs&&inputs[0]&&inputs[0].blur){inputs[0].blur();}}
EmbdPG.prototype.loadEmbeddedContent=function(cxContent,cyContent,callback){if(this.busy)return;this.busy=true;var flashDivs=document.getElementsByTagName("div");for(var i=0;i<flashDivs.length;i++){if(flashDivs[i].className=="flash"){flashDivs[i].style.visibility="hidden";}}
this.fContentMode=true;this.contentModeCallback=callback;this.createOverlay(300,300,-1);}