var tiny={};

tiny.box=function(){
	var p,m,b,fn,ic,iu,iw,ih,ia,f=0;
	return{ w: 0,
	        h: 0,
	        use: false,
	        th:null,
		show:function(c,u,w,h,a,t){
			if(!f){
				p=document.createElement('div'); p.id='tinybox';
				m=document.createElement('div'); m.id='tinymask';
				b=document.createElement('div'); b.id='tinycontent';
				document.body.appendChild(m); document.body.appendChild(p); p.appendChild(b);
				m.onclick=tiny.box.hide; window.onresize=tiny.box.resize; f=1
			}
			if(!a&&!u){
				p.style.width=w?w+'px':'auto'; p.style.height=h?h+'px':'auto';
				p.style.backgroundImage='none'; b.innerHTML=c
			}else{
				b.style.display='none'; p.style.width=p.style.height='100px'
			}
			this.mask();
			ic=c; iu=u; iw=w; ih=h; ia=a; tiny.box.w=w; tiny.box.h=h; tiny.box.use=true; this.alpha(m,1,80,3);
			if(t){setTimeout(function(){tiny.box.hide()},1000*t)}
		},
		fill:function(c,u,w,h,a){
			if(u){//ajax
				p.style.backgroundImage='';
				sajax_do_call(c);
			}else{//output value "c"
				this.psh(c,w,h,a)
			}
		},
		psh:function(c,w,h,a){
		        tiny.box.use=false;
			if(a){
				if(!w||!h){
					var x=p.style.width, y=p.style.height; b.innerHTML=c;
					p.style.width=w?w+'px':''; p.style.height=h?h+'px':'';
					b.style.display='';
					w=parseInt(b.offsetWidth); h=parseInt(b.offsetHeight);
					b.style.display='none'; p.style.width=x; p.style.height=y;
				}else{
					b.innerHTML=c
				}
				this.size(p,w,h)
			}else{
				p.style.backgroundImage='none'
			}
		},
		psh2:function(o,c,w,h,a)
		     { tiny.box.use=false;
		       if(a)
		       { if(!w||!h)
		         { var x=p.style.width, y=p.style.height; o.innerHTML=c;
			   p.style.width=w?w+'px':''; p.style.height=h?h+'px':'';
			   b.style.display='';
			   w=parseInt(b.offsetWidth); h=parseInt(b.offsetHeight);
			   b.style.display='none'; p.style.width=x; p.style.height=y;
			 }
			 else
			 { o.innerHTML=c
			 }
			 this.size(p,w,h)
		       }
		       else
		       { p.style.backgroundImage='none'
		       }
		       tiny.box.resize();
		       setTimeout(function(){tiny.box.resize()},500);
		     },
		hide:function(){
			tiny.box.alpha(p,-1,0,3)
		},
		resize:function(){
			tiny.box.pos(); tiny.box.mask()
		},
		mask:function(){
			m.style.height=tiny.page.total(1)+'px';
			m.style.width=''; m.style.width=tiny.page.total(0)+'px'
		},
		pos:function(){
			var t=(tiny.page.height()/2)-(p.offsetHeight/2); t=t<10?10:t;
			p.style.top=(t+tiny.page.top())+'px';
			p.style.left=(tiny.page.width()/2)-(p.offsetWidth/2)+'px'
		},
		alpha:function(e,d,a){
			clearInterval(e.ai);
			if(d==1){
				e.style.opacity=0; e.style.filter='alpha(opacity=0)';
				e.style.display='block'; this.pos()
			}
			e.ai=setInterval(function(){tiny.box.ta(e,a,d)},20)
		},
		ta:function(e,a,d){
			var o=Math.round(e.style.opacity*100);
			if(o==a){
				clearInterval(e.ai);
				if(d==-1){
					e.style.display='none';
					e==p?tiny.box.alpha(m,-1,0,2):b.innerHTML=p.style.backgroundImage=''
				}else{
					e==m?this.alpha(p,1,100):tiny.box.fill(ic,iu,iw,ih,ia)
				}
			}else{
				var n=Math.ceil((o+((a-o)*.5))); n=n==1?0:n;
				e.style.opacity=n/100; e.style.filter='alpha(opacity='+n+')'
			}
		},
		size:function(ee,w,h){
			ee=typeof ee=='object'?ee:e(ee); clearInterval(ee.si);
			var ow=ee.offsetWidth, oh=ee.offsetHeight,
			wo=ow-parseInt(ee.style.width), ho=oh-parseInt(ee.style.height);
			var wd=ow-wo>w?0:1, hd=(oh-ho>h)?0:1;
			ee.si=setInterval(function(){tiny.box.ts(ee,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); p.style.backgroundImage='none'; b.style.display='block'
			}else{  
			        if(oh!=h){var n=oh+((h-oh)*.5); e.style.height=hd?Math.ceil(n)+'px':Math.floor(n)+'px'}
				if(ow!=w){var n=ow+((w-ow)*.5); e.style.width=wd?Math.ceil(n)+'px':Math.floor(n)+'px'}
				this.pos()
			}
		}
	}
}();

tiny.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))
		}
	}
}();

function tinybox(f)
{ switch(f)
  { case 1:
      tiny.box.show(Array("lang","x_tinybox",""),1,0,0,1);
    break;
  }
}
