NG.Photogallery=function(){};NG.Photogallery.instantiate=function(c){var a=function(){};a.prototype=this;var b=new a();b.initialize(c);return b};NG.Photogallery.initialize=function(e){this.cmsID=e;this.node=document.getElementById("photogallery-"+e);this.page=-1;this.photo=-1;this.pageButtons=new Array;this.commentPrompt="Write a comment here...";this.filter="";var d=this.node.getElementsByTagName("img");var c=this;for(var b=0;b<d.length;b++){NG.addEventListener(d[b],"click",function(){c.open(this)})}if(NG.getElementsByClassName(this.node,"search").length>0){NG.addEventListener(NG.getElementsByClassName(this.node,"search")[0].getElementsByTagName("a")[0],"click",function(){c.filter=this.previousSibling.value;c.reloadPage()})}var a=NG.getElementsByClassName(this.node,"nav")[0].getElementsByTagName("span");for(var b=0;b<a.length;b++){if(NG.hasClass(a[b],"button")){if(NG.hasClass(a[b],"button-first")){NG.addEventListener(a[b],"click",function(){c.toFirstPage()})}else{if(NG.hasClass(a[b],"button-left")){NG.addEventListener(a[b],"click",function(){c.toPreviousPage()})}else{if(NG.hasClass(a[b],"button-right")){NG.addEventListener(a[b],"click",function(){c.toNextPage()})}else{if(NG.hasClass(a[b],"button-last")){NG.addEventListener(a[b],"click",function(){c.toLastPage()})}}}}}else{if(NG.hasClass(a[b],"navpage")){NG.addEventListener(a[b],"click",function(){c.toPage(parseInt(this.innerHTML)-1)});if(NG.hasClass(a[b],"navpage-total")){this.lastPage=parseInt(a[b].innerHTML)-1;this.lastPageButton=a[b]}else{this.pageButtons[parseInt(a[b].innerHTML)-1]=a[b]}}}}this.toPage(0)};NG.Photogallery.toFirstPage=function(){this.toPage(0)};NG.Photogallery.toNextPage=function(){this.toPage(this.page+1)};NG.Photogallery.toPreviousPage=function(){this.toPage(this.page-1)};NG.Photogallery.toLastPage=function(){this.toPage(this.lastPage)};NG.Photogallery.reloadPage=function(){this.toPage(this.page)};NG.Photogallery.toPage=function(c){var b=this;var a=NGUrl.thisRequest();a.addArgument("gallery[id]",this.cmsID,true);a.addArgument("gallery[action]","page",true);a.addArgument("gallery[page]",c,true);a.addArgument("gallery[query]",this.filter,true);var d=new NG.AJAX(a,function(e){b.updatePage(e)});d.send()};NG.Photogallery.updatePage=function(g){var f=this;var b=g.responseXML.documentElement;var h=parseInt(b.getElementsByTagName("page")[0].getAttribute("page"));this.viewSize={};this.viewSize.width=b.getAttribute("maxwidth");this.viewSize.height=b.getAttribute("maxheight");this.comments=b.getAttribute("comments")==1;this.commentsAllowed=b.getAttribute("commentsallowed")==1;if(this.pageButtons[this.page]!=null){NG.delClass(this.pageButtons[this.page],"navpage-selected")}this.page=h;if(this.pageButtons[this.page]){NG.addClass(this.pageButtons[this.page],"navpage-selected")}if(this.page==this.lastPage){NG.addClass(this.lastPageButton,"navpage-selected")}else{NG.delClass(this.lastPageButton,"navpage-selected")}var a=NG.getElementsByClassName(this.node,"body")[0];while(a.getElementsByTagName("img").length>0){a.removeChild(a.getElementsByTagName("img")[0])}this.photos=[];this.total=parseInt(b.getAttribute("total"));for(var e=0;e<b.childNodes.length;e++){if(b.childNodes[e].nodeType==3){continue}var h=b.childNodes[e];break}for(var e=0;e<h.childNodes.length;e++){if(h.childNodes[e].nodeType==3){continue}var c=document.createElement("img");var d=parseInt(h.childNodes[e].getAttribute("index"));this.photos[d]=h.childNodes[e].getAttribute("id");c.src=h.childNodes[e].getAttribute("thumb");c.title=h.childNodes[e].getAttribute("caption");c.fullSrc=h.childNodes[e].getAttribute("src");c.fullWidth=h.childNodes[e].getAttribute("width");c.fullHeight=h.childNodes[e].getAttribute("height");c.galleryIndex=d;NG.addEventListener(c,"click",function(){f.open(this.galleryIndex)});a.appendChild(c)}};NG.Photogallery.open=function(b){if(this.popup==null){var c=this;this.popup=document.createElement("table");this.popup.cellPadding=0;this.popup.cellSpacing=0;this.popup.appendChild(document.createElement("tbody"));this.popup.lastChild.appendChild(document.createElement("tr"));this.popup.lastChild.lastChild.appendChild(document.createElement("td"));this.popup.root=this.popup.lastChild.lastChild.lastChild;this.popup.style.position="absolute";NG.addClass(this.popup,"photogallery");NG.addClass(this.popup,"photogallery-window");var a=this.popup.root;a.appendChild(document.createElement("div"));NG.addClass(a.lastChild,"header");a.lastChild.style.whiteSpace="nowrap";a.lastChild.appendChild(document.createElement("div"));NG.addClass(a.lastChild.lastChild,"button");NG.addClass(a.lastChild.lastChild,"button-close");NG.addEventListener(a.lastChild.lastChild,"click",function(){c.close()});a.lastChild.appendChild(document.createElement("h1"));a.lastChild.lastChild.innerHTML=this.node.firstChild.firstChild.innerHTML;a.lastChild.appendChild(document.createElement("div"));a.lastChild.appendChild(document.createElement("div"));NG.addClass(a.lastChild.lastChild,"divider");a.appendChild(document.createElement("div"));NG.addClass(a.lastChild,"body");a.lastChild.appendChild(document.createElement("div"));NG.addClass(a.lastChild.lastChild,"nav");a.lastChild.lastChild.appendChild(document.createElement("span"));NG.addClass(a.lastChild.lastChild.lastChild,"button");NG.addClass(a.lastChild.lastChild.lastChild,"button-first");NG.addEventListener(a.lastChild.lastChild.lastChild,"click",function(){c.firstPhoto()});a.lastChild.lastChild.appendChild(document.createElement("span"));NG.addClass(a.lastChild.lastChild.lastChild,"button");NG.addClass(a.lastChild.lastChild.lastChild,"button-left");NG.addEventListener(a.lastChild.lastChild.lastChild,"click",function(){c.previousPhoto()});a.lastChild.lastChild.appendChild(document.createElement("span"));a.lastChild.lastChild.lastChild.innerHTML="Previous";NG.addClass(a.lastChild.lastChild.lastChild,"navpage");NG.addClass(a.lastChild.lastChild.lastChild,"navpage-first");NG.addEventListener(a.lastChild.lastChild.lastChild,"click",function(){c.previousPhoto()});a.lastChild.lastChild.appendChild(document.createElement("span"));a.lastChild.lastChild.lastChild.innerHTML="Next";NG.addClass(a.lastChild.lastChild.lastChild,"navpage");NG.addClass(a.lastChild.lastChild.lastChild,"navpage-last");NG.addEventListener(a.lastChild.lastChild.lastChild,"click",function(){c.nextPhoto()});a.lastChild.lastChild.appendChild(document.createElement("span"));NG.addClass(a.lastChild.lastChild.lastChild,"button");NG.addClass(a.lastChild.lastChild.lastChild,"button-right");NG.addEventListener(a.lastChild.lastChild.lastChild,"click",function(){c.nextPhoto()});a.lastChild.lastChild.appendChild(document.createElement("span"));NG.addClass(a.lastChild.lastChild.lastChild,"button");NG.addClass(a.lastChild.lastChild.lastChild,"button-last");NG.addEventListener(a.lastChild.lastChild.lastChild,"click",function(){c.lastPhoto()});a.lastChild.appendChild(document.createElement("div"));NG.addClass(a.lastChild.lastChild,"imgholder");a.lastChild.lastChild.style.width=this.viewSize.width+"px";a.lastChild.lastChild.appendChild(document.createElement("img"));if(this.comments){a.lastChild.appendChild(document.createElement("div"));NG.addClass(a.lastChild.lastChild,"comments");if(this.commentsAllowed){a.lastChild.appendChild(document.createElement("textarea"));a.lastChild.lastChild.innerHTML=this.commentPrompt;NG.addClass(a.lastChild.lastChild,"initial");NG.addEventListener(a.lastChild.lastChild,"focus",function(){if(this.value==c.commentPrompt){this.value="";NG.delClass(this,"initial")}});a.lastChild.appendChild(document.createElement("div"));NG.addClass(a.lastChild.lastChild,"button");NG.addClass(a.lastChild.lastChild,"button-submit");NG.addEventListener(a.lastChild.lastChild,"click",function(){c.submitComment()})}}}this.toPhoto(b)};NG.Photogallery.close=function(){if(this.shade){this.shade.close()}this.photo=-1;document.body.removeChild(this.popup)};NG.Photogallery.firstPhoto=function(){this.toPhoto(0)};NG.Photogallery.previousPhoto=function(){this.toPhoto(this.photo-1)};NG.Photogallery.nextPhoto=function(){this.toPhoto(this.photo+1)};NG.Photogallery.lastPhoto=function(){this.toPhoto(this.total-1)};NG.Photogallery.toPhoto=function(c){if(c<0||c>=this.total||c==this.photo){return}var b=this;var a=NGUrl.thisRequest();a.addArgument("gallery[id]",this.cmsID,true);a.addArgument("gallery[action]","photo",true);a.addArgument("gallery[photo]",c,true);a.addArgument("gallery[query]",this.filter,true);var d=new NG.AJAX(a,function(e){b.updatePhoto(e,c)});d.send()};NG.Photogallery.updatePhoto=function(d,k){if(d.responseXML==null){return}var e=this;var a=(d.responseXML.documentElement.firstChild.nodeType==3?d.responseXML.documentElement.firstChild.nextSibling:d.responseXML.documentElement.firstChild);this.photo=k;this.photoid=a.getAttribute("id");NG.getElementsByClassName(this.popup.root,"header")[0].getElementsByTagName("h1")[0].innerHTML=a.getAttribute("caption")+(a.getAttribute("caption")==""?"":"&nbsp;|&nbsp;")+(this.photo+1)+" of "+this.total;NG.getElementsByClassName(this.popup.root,"imgholder")[0].getElementsByTagName("img")[0].src=a.getAttribute("src");if(a.parentNode.getAttribute("download")){var j=function(){var f=NGUrl.thisRequest();f.addArgument("gallery[id]",e.cmsID,true);f.addArgument("gallery[action]","download",true);f.addArgument("gallery[photo]",e.photoid,true);f.redirect()};NG.addClass(NG.getElementsByClassName(this.popup.root,"imgholder")[0].getElementsByTagName("img"),"downloadable");NG.addEventListener(NG.getElementsByClassName(this.popup.root,"imgholder")[0].getElementsByTagName("img"),"click",j)}if(this.comments){var h=NG.getElementsByClassName(this.popup.root,"comments")[0];while(h.childNodes.length>0){h.removeChild(h.lastChild)}for(var g=0;g<a.childNodes.length;g++){if(a.childNodes[g].nodeType==3){continue}h.appendChild(document.createElement("div"));NG.addClass(h.lastChild,"comment");var b=new Date();b.setTime(a.childNodes[g].getAttribute("date")*1000);h.lastChild.innerHTML='<span class="username">'+a.childNodes[g].getAttribute("username")+'</span> said <span class="date">('+this.formatDate(b)+'):</span><div class="text">'+(a.childNodes[g].textContent?a.childNodes[g].textContent:a.childNodes[g].text)+"</div>"}}document.body.appendChild(this.popup);this.popup.style.right=Math.max(0,Math.floor((document.body.clientWidth-this.popup.clientWidth)/2))+"px";this.popup.style.top=Math.max(50,(50+document.body.parentNode.scrollTop))+"px";var c=this.node;while(c.parentNode!=document.body){c=c.parentNode}var l;if(NG.ua.isEng("MSIE")){var l=document.documentElement.clientHeight}else{var l=window.innerHeight}if(c.offsetHeight>l){l=c.offsetHeight}if(this.popup.root.parentNode.parentNode.parentNode.offsetHeight>l){l=this.popup.root.parentNode.parentNode.offsetHeight}this.shade=new NG.Shade(document.body,l,false);document.body.appendChild(this.popup)};NG.Photogallery.submitComment=function(){var a=NG.getElementsByClassName(this.popup.root,"comments")[0].getElementsByTagName("textarea")[0];var c=this;var b=NGUrl.thisRequest();b.addArgument("gallery[id]",this.cmsID,true);b.addArgument("gallery[action]","comment",true);b.addArgument("gallery[photo]",{MediaID:this.photoid},true);b.addArgument("gallery[index]",this.photo,true);b.addArgument("gallery[comment]",a.value,true);var d=new NG.AJAX(b,function(e){c.updatePhoto(e,c.photo)});d.send();NG.addClass(a,"initial");a.value=this.commentPrompt};NG.Photogallery.formatDate=function(a){return a.strftime("%H:%M%P - %d.%m.%Y")};