/*
  wbLiteBox
  Super Lite Stand-Alone Image LightBox
  (c)2008 Holodyn Corporation, Webuddha.com
  Version: 1.1.0
  Release: 020809
*/
function wbLiteBox(){
  this._=function(mo){
    this._de('document.onkeydown','document.wblb._kp(e);');
    if(!mo){
      if(this.img){this.img.onload=function(){};this.img=null;}
      this.over.style.visibility=this.fade.style.visibility='hidden';
    } else if(this._Li(mo))this._ae('document.onkeydown','document.wblb._kp(e);');
    return false;
  };
  this._i=function(){
    if(!document.getElementsByTagName||!this._ds())return;
    this.docb=document.getElementsByTagName("body").item(0);
    this.disp=document.createElement('img');
    this.disp.onclick=function(){document.wblb._();};
    this.cont=document.createElement('div');
    this.cont.setAttribute('id','wblb_cont');
    this.over=document.createElement('div');
    this.over.setAttribute('id','wblb_over');
    this.over.appendChild(this.disp);
    this.over.appendChild(this.cont);
    this.over.onclick=function(){document.wblb._();};
    this.fade=document.createElement('div');
    this.fade.setAttribute('id','wblb_fade');
    this.fade.onclick=function(){document.wblb._();};
    this.docb.insertBefore(this.over, this.docb.firstChild);
    this.docb.insertBefore(this.fade, this.docb.firstChild);
    this.ids=0;this.set=[];
    var lnks=document.getElementsByTagName("a");
    for(i=0;i<lnks.length;i++){
      var lnk=lnks[i];
      if(lnk.getAttribute("href")&&lnk.getAttribute("rel")&&lnk.getAttribute("rel").match(/^wblite/i)){
        lnk.onclick=function(e){return document.wblb._(this);};
        lSn=this._sNm(lnk);lnk.wblbid=this.ids++;
        if(lSn){
          if(!this.set[lSn]){this.set.push(lSn);this.set[lSn]=[];}
          lnk.wblbnm=this.set[lSn].length+1;
          lnk.wblbsn=lSn;lnk.wblbst=this._sNm(lnk,1);
          this.set[lSn].push(lnk);
        }
      }
    }
    lnk=lnks=null;
    this._ae('window.onresize','document.wblb._ds(0,0,1);');
    this._ae('window.onscroll','document.wblb._ds();');
    this._ds();
  };
  this._sd=function(){
    var pW = 0, pH = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
      //Non-IE
      pW = window.innerWidth; pH = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      pW = document.documentElement.clientWidth; pH = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      pW = document.body.clientWidth; pH = document.body.clientHeight;
    }
    return {w:pW,h:pH};
  }
  this._ds=function(w,h,t){
    if(!w&&!h){
      // Scroll Offset, Viewport, and Document Size
      var xS=(window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft),
      yS=(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop),
      wW,wH,pW,pH,B=this._bt; if(B.WebKit&&!document.evaluate){ pW = self['innerWidth']; pH = self['innerHeight']; }
      else if (B.Opera && parseFloat(window.opera.version()) < 9.5) { pW = document.body['clientWidth']; pH = document.body['clientHeight']; }
      else { pW = document.documentElement['clientWidth']; pH = document.documentElement['clientHeight']; }
      if(self.innerHeight){ if(document.documentElement.clientWidth)wW = document.documentElement.clientWidth;
      else wW = self.innerWidth; wH = self.innerHeight; } else if(document.documentElement && document.documentElement.clientHeight){
      wW = document.documentElement.clientWidth; wH = document.documentElement.clientHeight; } else if(document.body){
      wW = document.body.clientWidth; wH = document.body.clientHeight; }
      this.dim={w:pW<wW?pW:wW,h:pH<wH?pH:wH,x:xS,y:yS}; if(this.img&&this.img.ok){this._dx(0,0,1);this._Li();}
    }
    if(t)setTimeout('document.wblb._ds();',50); if(w)return this.dim.x+Math.round(this.dim.w/2-w/2);
    if(h)return this.dim.y+Math.round(this.dim.h/2-(h+this._Ed(this.cont))/2); return (this.dim.w||this.dim.h?true:false);
  };
  this._dx=function(w,h,f){
    if(!this.imx||this.imx.os!=this.img.src||f){
      var tI=this.img,mX=this.dim.w*.85,mY=(this.dim.h-this._Ed(this.cont))*.85,iW=tI.width;iH=tI.height,iS=tI.width/tI.height;
      if(iW>iH){if(iH>mY){iH=mY;iW=iH*iS;}if(iW>mX){iW=mX;iH=iW/iS;}}else{if(iW>mX){iW=mX;iH=iW/iS;}if(iH>mY){iH=mY;iW=iH*iS;}}
      this.imx={w:Math.round((iW?iW:1)),h:Math.round((iH?iH:1)),os:tI.src,ow:tI.width,oh:tI.height,os:iS};
    }
    if(w)return this.imx.w;if(h)return this.imx.h;
  };
  this._Ed=function(mo,x){
    if(mo.clip)tmp=[mo.clip.width,mo.clip.height];
    else if(mo.style.pixelHeight)tmp=[mo.style.pixelWidth,mo.style.pixelHeight];
    else tmp=[mo.offsetWidth,mo.offsetHeight];
    if(tmp[0]||tmp[1])this.edh=tmp;return (x?this.edh[0]:this.edh[1]);
  };
  this._Li=function(mo){
    if(!mo&&this.img&&this.img.ok){
      this.disp.style.width=this.over.style.width=this.cont.style.width=this._dx(1,0)+'px';
      this.disp.style.height=this._dx(0,1)+'px';
      this.over.style.height=this._dx(0,1)+this._Ed(this.cont)+'px';
      this.over.style.left=this._ds(this.imx.w,0)+'px';
      this.over.style.top=this._ds(0,this.imx.h)+'px';
      this.fade.style.left=this.dim.x+'px';
      this.fade.style.width=this.dim.w+'px';
      this.fade.style.top=this.dim.y+'px';
      this.fade.style.height=this.dim.h+'px';
    }
    if(!mo)return true;
    this.over.style.visibility='hidden';
    this.img=document.createElement('img');
    this.img.display='none';
    this.img.onload=function(e){this.ok=1;po=document.wblb;if(po._Li())po.over.style.visibility='visible';else po._();};
    if(mo.title){
      this.disp.alt=mo.title;this.cont.wblbsn=mo.wblbsn;
      this.cont.innerHTML=(this.cont.wblbsn?'<div class=nav>'+mo.wblbnm+' of '+this.set[this.cont.wblbsn].length+'</div>'+'<div class=set>'+mo.wblbst+'</div>':'')+'<div class=img>'+mo.title+'</div>';
    }else this.cont.innerHTML=this.disp.alt='';
    this.disp.wblbsn=mo.wblbsn;this.disp.rel=mo.rel;
    this.disp.wblbid=mo.wblbid;this.disp.src=this.img.src=mo.href;
    this.fade.style.visibility='visible';
    return true;
  };
  this._Ni=function(d){
    if(!this.disp)return;
    var snt=this.disp.wblbsn;if(!snt)return;
    T=this.set[snt].length;if(T<2)return;
    for(var i=0;i<T;i++)
      if(this.disp.wblbid==this.set[snt][i].wblbid){
        if(d)if(++i<T)this._(this.set[snt][i]);else this._(this.set[snt][0]);
          else if(i>0)this._(this.set[snt][i-1]);else this._(this.set[snt][T-1]);
        return true;
      }
  };
  this._sNm=function(mo,o){
    if(!mo.rel)return null;
    var snt=mo.rel.replace(/^wblite/i,'').replace(/^\[(.*)\]$/,'$1').replace(/^\s+|\s+$/,'');
    if(snt)if(o)return snt;else return snt.replace(/\s+/,'_').toLowerCase();else return null;
  };
  this._kp=function(e){
    if(window.event)k=window.event.keyCode;else k=e.keyCode;
    if(k==27||k==32||this.img&&(k==37&&!this._Ni(0))||(k==39&&!this._Ni(1)))this._();
  };
  this._ae=function(oN,eF){
    if(typeof oN!='string')return false;
    if(typeof eF=='function')eF=("'"+eF+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'');
    if(eval('typeof '+oN)!='function')return eval(oN+'= function(e){ '+eF+' }');
    oF=("'"+eval(oN)+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'');
    return eval(oN+'=function(e){'+oF+' '+eF+'}');
  };
  this._de=function(oN,eF){
    if(typeof oN != 'string')return false;
    if(eval('typeof '+oN) != 'function')return true;
    if(typeof eF=='function')eF=("'"+eF+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'');
    var oD=("'"+eval(oN)+"'").replace(/\n|\r/,' ').replace(/^\'.*?\{/,'').replace(/\}\'$/,'').replace(eF,'');
    if(oD.replace(/\s+/,'').length>0)return eval(oN+'=function(e){'+oD+'}');else return eval(oN+'=function(e){}');
  };
  this._bt={
    IE: !!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1),
    Opera: navigator.userAgent.indexOf('Opera') > -1,
    WebKit:navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') === -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  };
  if(typeof document!='object')return null;
  if(typeof document.wblb!=='undefined')return null;
  document.wblb=this;this._ae('window.onload','document.wblb._i();');
};
new wbLiteBox();
