/**
* Work Detail + KiteBox 0.9.1 combination
* @author Mike Healy
*/
var workImage={container:null,init:function(){workImage.container=$('workImage');if(!workImage.container)return;$E.on('workList','mouseover',workImage.swapImage,true);$E.on('workList','mouseout',workImage.swapImage,false);},swapImage:function(ev,show){var tgt=$E.getTarget(ev);if(show){if(!tgt.tagName||tgt.tagName.toLowerCase()!='a')return;var ID=tgt.id.replace(/work/,'');var image=workImages['id'+ID];workImage.container.style.backgroundImage='url('.concat(image).concat(')');}
else{workImage.container.style.backgroundImage='none';}}};var KiteBox=function(container,cfg){this.imageContainer;this.blocker;this.imageListeners=function(action){var img=$('KiteBox_image');if(action.toLowerCase()=='add'){$E.on(img,'click',this.hide,null,this);$E.on(document,'keyup',function(ev){if(ev.keyCode==27)this.hide();},null,this);}
else{$E.removeListener(img,'click');$E.removeListener(document,'keyup');}};this.hide=function(ev){this.imageListeners('remove');this.imageContainer.style.display='none';this.blocker.style.display='none';var img=$('KiteBox_image');if(img)img.parentNode.removeChild(img);};this.loadImage=function(ev){var tgt=$E.getTarget(ev);var count=0;while(tgt.tagName&&tgt.tagName.toLowerCase()!='a'&&count<5){tgt=tgt.parentNode;count++;}
if(!tgt.tagName||tgt.tagName.toLowerCase()!='a')return;if(tgt.href.toLowerCase().search(/(jpe?g|gif|png|bmp)$/)==-1){return;}
else $E.stopEvent(ev);var img=document.createElement('img');img.id='KiteBox_image';img.src=tgt.href;img.alt=tgt.title;$('KiteBox').appendChild(img);this.imageListeners('add');var blocker=$('KiteBox_block');$D.setStyle(blocker,'opacity',0.85);var w=($D.getViewportWidth()>$D.getDocumentWidth())?$D.getViewportWidth():$D.getDocumentWidth();var h=($D.getViewportHeight()>$D.getDocumentHeight())?$D.getViewportHeight():$D.getDocumentHeight();blocker.style.width=w.toString().concat('px');blocker.style.height=h.toString().concat('px');blocker.style.display='block';var scrollY=$D.getDocumentScrollTop();scrollY=scrollY.toString().concat('px');img.parentNode.style.marginTop=scrollY;img.parentNode.style.display='block';};this.constructor=function(container,cfg){var body=document.getElementsByTagName('body')[0];var blocker=document.createElement('div');blocker.id='KiteBox_block';body.appendChild(blocker);var con=document.createElement('div');con.id='KiteBox';body.appendChild(con);this.imageContainer=con;this.blocker=blocker;if(typeof container=='string')container=$(container);this.container=container;$E.on(container,'click',this.loadImage,null,this);};this.constructor(container,cfg);};$E.onDOMReady(function(){workImage.init();var myKB=new KiteBox('gallery');});
