/* Tiny / POP Box edited by Marijus v1 */

var POP={};

function T$(i){return document.getElementById(i)}

POP.box=function(){
	var d,s,m,b,f,con=0;
	return{
		show:function(c,u,w,h,a,cl,t){
            if(!f){                 
				m=this.cDiv('pop_mask');
                                
                d=this.cDiv('pop_blc'); d1=this.cDiv('pop_brc'); d2=this.cDiv('pop_tlc'); d3=this.cDiv('pop_trc');                
                d4=this.cDiv('pop_tb'); d5=this.cDiv('pop_rb'); d6=this.cDiv('pop_bb'); d7=this.cDiv('pop_lb');
                dh=this.cDiv('pop_hol'); dc=this.cDiv('pop_clc');
                da=document.createElement('a'); da.id='pop_close';
                
                s=this.cDiv('pop_size');
                b=this.cDiv('pop_content');
                                
                document.body.appendChild(m);
                document.body.appendChild(d); d.appendChild(d1); d1.appendChild(d2); d2.appendChild(d3);
                d3.appendChild(d4); d4.appendChild(d5); d5.appendChild(d6); d6.appendChild(d7);            
                               
                d7.appendChild(dh); dh.appendChild(s); dh.appendChild(dc); dc.appendChild(da);
                s.appendChild(b); 
                m.onclick=da.onclick=POP.box.hide; /* window.onresize=POP.box.resize;*/ f=1;
			}
			
            da.innerHTML=cl?cl:'CLOSE';
            b.style.display=m.style.display=d.style.display='none';
            s.style.width=s.style.height='100px';
            a==1?s.style.backgroundImage='':s.style.backgroundImage='none';
			this.mask();            
            d.style.display='block';
            this.pos();
            this.fill(c,u,w,h,a);
            if(t){setTimeout(function(){POP.box.hide()},1000*t)}
		},
        cDiv:function(s){
            t=document.createElement('div'); t.id=s;    
            return t;  
        },
        mask:function(){
            m.style.height=POP.page.total(1)+'px';
            m.style.width=''; m.style.width=POP.page.total(0)+'px';
            this.alpha(m,80);
        },
        pos:function(){
            var t=(POP.page.height()/2)-(d.offsetHeight/2); t=t<10?10:t;
            d.style.top=(t+POP.page.top())+'px';
            d.style.left=(POP.page.width()/2)-(d.offsetWidth/2)+'px'
        },
		fill:function(c,u,w,h,a){
			if(u){
				var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
				x.onreadystatechange=function(){
					if(x.readyState==4&&x.status==200){POP.box.psh(x.responseText,w,h,a)}
				};
				x.open('GET',c,1); x.send(null)
			}else{
				this.psh(c,w,h,a)
			}
		},
		psh:function(c,w,h,a){			
			b.style.visibility='hidden';
            b.style.display='block';
            if(!w||!h){
			    var x=s.style.width, y=s.style.height; b.innerHTML=c;
				s.style.width=w?w+'px':''; s.style.height=h?h+'px':'';
				w=parseInt(b.offsetWidth); h=parseInt(b.offsetHeight);
				s.style.width=x; s.style.height=y;
			}else{
			   b.innerHTML=c
			}
            if(a){
                this.size(s,w,h)
			}else{
                s.style.width=w+'px'; s.style.height=h+'px';
                this.pos();
                 b.style.visibility='visible';
			}
		},        
        size:function(e,w,h){
            e=typeof e=='object'?e:T$(e); clearInterval(e.si);
            var ow=e.offsetWidth, oh=e.offsetHeight,
            wo=ow-parseInt(e.style.width), ho=oh-parseInt(e.style.height);
            var wd=ow-wo>w?0:1, hd=(oh-ho>h)?0:1;
            e.si=setInterval(function(){POP.box.ts(e,w,wo,wd,h,ho,hd)},20)
        },
        ts:function(e,w,wo,wd,h,ho,hd){
            var ow=e.offsetWidth-wo, oh=e.offsetHeight-ho;
            if(ow==w&&oh==h){
                clearInterval(e.si); s.style.backgroundImage='none'; b.style.visibility='visible';
            }else{
                if(ow!=w){var n=ow+((w-ow)*.5); e.style.width=wd?Math.ceil(n)+'px':Math.floor(n)+'px'}
                if(oh!=h){var n=oh+((h-oh)*.5); e.style.height=hd?Math.ceil(n)+'px':Math.floor(n)+'px'}
                this.pos()
            }
        },
		hide:function(){
            POP.box.alpha(m,0);
            d.style.display='none';
		},
		resize:function(){
			POP.box.pos(); POP.box.mask()
		},        
		alpha:function(e,o){
            clearInterval(e.p);
            if (e.style.opacity == null)
                if (e.style.display == 'none') {
                    e.style.opacity=0;
                    e.style.filter='alpha(opacity=0)'
                } else {
                    e.style.opacity=1;
                    e.style.filter='alpha(opacity=1)'
                }
            e.style.display == 'none'?e.style.display = 'block':'';
            e.p=setInterval(function(){POP.box.at(e,o)},20)
        },
        at:function(e,o){
            var r=Math.round(e.style.opacity*100);
            if(r==o){
                clearInterval(e.p);
                if (o==0) e.style.display='none';
            }else{
                var n=Math.ceil((r+((o-r)*.5))); n=n==1?0:n;
                e.style.opacity=n/100; e.style.filter='alpha(opacity='+n+')'
            }
        }
	}
}();

POP.page=function(){
	return{
		top:function(){return document.documentElement.scrollTop||document.body.scrollTop},
		width:function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},
		height:function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},
		total:function(d){
			var b=document.body, e=document.documentElement;
			return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):
			Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
		}
	}
}();
