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){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();region=this.$D.getRegion(this.thumbContainerID);this.imgHollow.h=region["top"]-this.imgHollow.y;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='"+containerID+"' class='Thumb_Container'>";for(var i=0;i<this.galleryObj.galleryImages.length;i++){toInsert=toInsert+"<img src=\""+this.galleryObj.galleryImages[i].imgThumb+"\" class='Thumbnail' />";}toInsert=toInsert+"</div><div id='"+leftID+"' class='Left_Arrow'>&nbsp;</div><div id='"+rightID+"' class='Right_Arrow'>&nbsp;</div>";this.galleryContainer.innerHTML=this.galleryContainer.innerHTML+toInsert;var thumbContainer=me.$D.get(containerID);actualNode=thumbContainer.firstChild;while(actualNode!=null){anim1=new me.$A(actualNode,{opacity:{to:0.5}},1,YAHOO.util.Easing.easeOut);anim2=new me.$A(actualNode,{opacity:{to:1}},1,YAHOO.util.Easing.easeOut);me.$Ev.on(actualNode,'mouseover',anim1.animate,anim1,true);me.$Ev.on(actualNode,'mouseout',anim2.animate,anim2,true);me.$Ev.on(actualNode,'click',function(){var c=0;tempNode=this.parentNode.firstChild;while(tempNode!=this){c++;tempNode=tempNode.nextSibling;}me.insertImage(c);},true);actualNode=actualNode.nextSibling;}me.$Ev.on(me.$D.get(leftID),'click',function(){me.scrollRightThumbnails(thumbContainer,this);},true);me.$Ev.on(me.$D.get(rightID),'click',function(){me.scrollLeftThumbnails(thumbContainer,this);},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+"\">";if(!/^\s*$/.test(me.galleryObj.galleryImages[id].imgTitle))galleryTilte.lastChild.innerHTML='&nbsp;"'+me.galleryObj.galleryImages[id].imgTitle+'"';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);},scrollLeftThumbnails:function(thumbContainer,obj){var node=thumbContainer.lastChild,elWidth=node.offsetLeft+node.offsetWidth+4;if(elWidth>thumbContainer.parentNode.offsetWidth){var rest=elWidth-(Math.abs(thumbContainer.offsetLeft)+thumbContainer.parentNode.offsetWidth),displace=((rest>thumbContainer.parentNode.offsetWidth&&(rest-thumbContainer.parentNode.offsetWidth)>thumbContainer.lastChild.offsetWidth))?-thumbContainer.parentNode.offsetWidth:-(elWidth-(Math.abs(thumbContainer.offsetLeft)+thumbContainer.parentNode.offsetWidth)),anim=new YAHOO.util.Motion(thumbContainer,{points:{by:[displace,0]}},2,YAHOO.util.Easing.easeNone);anim.animate();}},scrollRightThumbnails:function(thumbContainer,obj){var rest=thumbContainer.offsetLeft+thumbContainer.parentNode.offsetWidth,displace=(rest>0||(rest<0&&Math.abs(rest)<thumbContainer.firstChild.offsetWidth))?Math.abs(thumbContainer.offsetLeft):thumbContainer.parentNode.offsetWidth,anim=new YAHOO.util.Motion(thumbContainer,{points:{by:[displace,0]}},2,YAHOO.util.Easing.easeNone);anim.animate();}};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){}};};
