function HDW_Image_Gallery(xmlUrl,ImageGalleryId){var me=this;me.$D=YAHOO.util.Dom;me.$Ev=YAHOO.util.Event;me.$E=YAHOO.util.Easing,me.$A=YAHOO.util.Anim;me.$C=YAHOO.util.Connect;me.$Ev.onAvailable(ImageGalleryId,function(){me.constructor(xmlUrl,ImageGalleryId);},this);}HDW_Image_Gallery.prototype={constructor:function(xmlUrl,ImageGalleryId){this.galleryObj;this.galleryContainer=YAHOO.util.Dom.get(ImageGalleryId);this.readImageGalleryXML(xmlUrl);},readImageGalleryXML:function(xmlUrl){var me=this,respObj={success:function(o){me.xmldoc=o.responseXML.documentElement;me.readXMLContainer();me.insertGallery();},failure:function(){}},request=me.$C.asyncRequest('GET',xmlUrl,respObj);},readXMLContainer:function(){var galleryTitle="",galleryTitleNode=this.xmldoc.getElementsByTagName('gallery_title')[0],imgsInGallery=Array(),imgThumb,imgFile,imgCloseup,imgTitle,titleValue='';XMLImage=this.xmldoc.getElementsByTagName('image');if(galleryTitleNode!=null&&galleryTitleNode.hasChildNodes()){galleryTitle=galleryTitleNode.firstChild.nodeValue;}for(var j=0;j<XMLImage.length;j++){imgThumb=XMLImage[j].getElementsByTagName('thumb')[0];imgFile=XMLImage[j].getElementsByTagName('file')[0];imgCloseup=XMLImage[j].getElementsByTagName('closeup')[0];imgTitle=XMLImage[j].getElementsByTagName('title')[0];if(imgThumb==null||imgThumb.getAttribute('src')==null)throw("Thumbnails is required");if(imgFile==null||imgFile.getAttribute('src')==null)throw("Image file is required");imgCloseup=(imgCloseup==null||imgCloseup.getAttribute('src')==null)?imgFile:imgCloseup;if(imgTitle.hasChildNodes())titleValue=imgTitle.firstChild.nodeValue;imgsInGallery.push({imgThumb:imgThumb.getAttribute('src'),imgFile:imgFile.getAttribute('src'),imgCloseup:imgCloseup.getAttribute('src'),imgTitle:titleValue});}if(imgsInGallery.length>0)this.galleryObj={galleryTitle:galleryTitle,galleryImages:imgsInGallery};},insertGallery:function(){var region=this.$D.getRegion(this.galleryContainer),toInsert;this.imgHollow={x:region["left"],y:region["top"],w:region["right"]-region["left"],h:region["bottom"]-region["top"]};this.titleID=this.insertTitle();region=this.$D.getRegion(this.titleID);this.imgHollow.h-=region["bottom"]-this.imgHollow.y;this.imgHollow.y=region["bottom"];if(this.galleryObj.galleryImages.length>0){this.imgContainerID=this.$D.generateId([],'imgContainer');toInsert="<div class='Center_Image' id='"+this.imgContainerID+"' style='visibility:hidden'>&nbsp;</div>";this.galleryContainer.innerHTML+=toInsert;this.thumbContainerID=this.insertThumbnails();this.insertImage(0);}},insertTitle:function(){var titleID=this.$D.generateId([],'galleryTitle');this.galleryContainer.innerHTML=this.galleryContainer.innerHTML+"<div id='"+titleID+"' class='Gallery_Title'><span></span></div>";return titleID;},insertThumbnails:function(){var me=this,anim1,anim2,containerID=me.$D.generateId([],'thumbContainer'),leftID=me.$D.generateId([],'leftArrow'),rightID=me.$D.generateId([],'rightArrow'),toInsert,toInsert="<div id='"+leftID+"' class='Left_Arrow'>&nbsp;</div><div id='"+rightID+"' class='Right_Arrow'>&nbsp;</div>";this.galleryContainer.innerHTML=this.galleryContainer.innerHTML+toInsert;var leftRegion=me.$D.getRegion(me.$D.get(leftID)),Y=(me.imgHollow.h-(leftRegion['bottom']-leftRegion['top']))/2;me.$D.setY([leftID,rightID],me.imgHollow.y+Y);me.$Ev.on(me.$D.get(leftID),'click',function(){if(me.galleryObj.actual!=0){me.insertImage(me.galleryObj.actual-1);}else{me.insertImage(me.galleryObj.galleryImages.length-1);}},true);me.$Ev.on(me.$D.get(rightID),'click',function(){if(me.galleryObj.actual+1!=me.galleryObj.galleryImages.length){me.insertImage(me.galleryObj.actual+1);}else{me.insertImage(0);}},true);return containerID;},insertImage:function(id){var me=this,yPos,galleryTilte=me.$D.get(me.titleID),imgContainer=me.$D.get(me.imgContainerID),toInsert="<img src=\""+me.galleryObj.galleryImages[id].imgFile+"\">";me.galleryObj.actual=id;if(!/^\s*$/.test(me.galleryObj.galleryImages[id].imgTitle)){galleryTilte.lastChild.innerHTML='&nbsp;"'+me.galleryObj.galleryImages[id].imgTitle+'" <span style="padding-left:10px;">'+(me.galleryObj.actual+1)+'/'+(me.galleryObj.galleryImages.length)+'</span>';}else{galleryTilte.lastChild.innerHTML='';}me.$Ev.purgeElement(imgContainer,true);imgContainer.style.visibility='hidden';imgContainer.innerHTML=toInsert;me.$Ev.addListener(imgContainer.firstChild,'click',function(){window.open(me.galleryObj.galleryImages[id].imgCloseup,'img');});me.$Ev.addListener(imgContainer.firstChild,'load',function(){var anim,region=me.$D.getRegion(this),imgDimension={x:0,y:0,w:(region["right"]-region["left"]),h:(region["bottom"]-region["top"])},imgContMargin=40;if(imgDimension.w>=me.imgHollow.w){imgDimension.h=Math.round(imgDimension.h*(me.imgHollow.w-imgContMargin)/imgDimension.w);imgDimension.w=me.imgHollow.w-imgContMargin;}if(imgDimension.h>=me.imgHollow.h){imgDimension.w=Math.round(imgDimension.w*(me.imgHollow.h-imgContMargin)/imgDimension.h);imgDimension.h=me.imgHollow.h-imgContMargin;}yPos=me.imgHollow.y+(me.imgHollow.h-imgDimension.h)/2;me.$D.setY(imgContainer,yPos);this.width=this.height=1;imgContainer.style.visibility='visible';anim=new me.$A(imgContainer.childNodes[0],{width:{to:imgDimension.w},height:{to:imgDimension.h}},1,YAHOO.util.Easing.easeOut);anim.animate();},true);}};
if (document.addEventListener){window.addEventListener ('load',function(){try{LoadGalleries();}catch(e){}},false);}else if(document.attachEvent){window.attachEvent ("onload",function(){try{LoadGalleries();}catch(e){}});}else{window["onload"]=function(){try{LoadGalleries();}catch(e){}};};
