TINY={};

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

TINY.box=function(){
	var p,m,b,pi='tinybox',mi='tinymask',bi='tinycontent';
	return{
		show:function(c,w,h,o){
			if(!T$(pi)){
				p=document.createElement('div'); p.id=pi;
				m=document.createElement('div'); m.id=mi;
				b=document.createElement('div'); b.id=bi;
				document.body.appendChild(m); document.body.appendChild(p); p.appendChild(b);
				window.onresize=TINY.box.position; m.onclick=TINY.box.hide
			}
			p.style.opacity=0; p.style.filter='alpha(opacity=0)';
			p.style.display=m.style.display=''; this.fill(c,w,h);
			TINY.alpha.set(m,o.maskOpacity||80,4); setTimeout(function(){TINY.alpha.set(p,100,4)}, 500)
		},
		fill:function(c,w,h,a){
			if(a){
				var h=b.innerHTML, x=p.style.width, y=p.style.height;
				if(w||h){
					p.style.width=w?w+'px':''; p.style.height=h?h+'px':'';
					b.innerHTML=c;
					w=parseInt(b.offsetWidth); h=parseInt(b.offsetHeight)
				}
				p.style.width=x; p.style.height=y; b.innerHTML='';
				TINY.size.set(p.id,w,h,5);
				setTimeout(function(){b.innerHTML=c}, 500)
			}else{
				b.innerHTML=c;
				this.size(w,h);
				this.position()
			}
		},
		hide:function(){
			clearTimeout(p.tw); TINY.alpha.set(p,0,4);
			clearTimeout(m.tw); setTimeout(function(){TINY.alpha.set(m,0,4)}, 500)
		},
		size:function(w,h){
			p.style.width=p.style.height='';
			w=w||parseInt(b.offsetWidth); h=h||parseInt(b.offsetHeight);
			p.style.width=w+'px'; p.style.height=h+'px'
		},
		position:function(){
			var h=TINY.page.height(), w=TINY.page.width(),
			v=(h/2)-(p.offsetHeight/2)+TINY.page.top();
			p.style.top=v>25?v+'px':'25px';
			p.style.left=(w/2)-(p.offsetWidth/2)+'px';
			var h=TINY.page.height(), w=TINY.page.width();
			m.style.height=h+'px'; m.style.width=w+'px'
		}
	}
}();

TINY.page=function(){
	return{
		width:function(){return self.innerWidth||document.documentElement.clientWidth},
		height:function(){return self.innerHeight||document.documentElement.clientHeight},
		top:function(){return self.pageYOffset||document.documentElement.scrollTop}
	}
}();

TINY.style=function(){
	return{
		get:function(e,p){
			e=typeof e=='object'?e:$(e);
			return e.currentStyle?e.currentStyle[p]:document.defaultView.getComputedStyle(e,null).getPropertyValue(p)
		}
	}
}();

TINY.alpha=function(){
	return{
		set:function(e,a,s){
			e=typeof e=='object'?e:T$(e);
			var o=e.style.opacity||TINY.style.get(e,'opacity'),
			d=a>o*100?1:-1; e.style.opacity=o; clearInterval(e.ai);
			e.ai=setInterval(function(){TINY.alpha.tw(e,a,d,s)},20)
		},
		tw:function(e,a,d,s){
			var o=Math.round(e.style.opacity*100);
			if(o==a){
				clearInterval(e.ai); if(!o){e.style.display='none'}
			}else{
				var n=o+Math.ceil(Math.abs(a-o)/s)*d; e.style.opacity=n/100;
				e.style.filter='alpha(opacity='+n+')'
			}
		}
	}
}();

TINY.size=function(){
	return{
		set:function(e,w,h,s){
			e=typeof e=='object'?e:T$(e);
			var ow=e.offsetWidth, oh=e.offsetHeight,
			wo=e.style.width?ow-parseInt(e.style.width):ow-parseInt(TINY.style.get(e,'width')),
			ho=e.style.height?oh-parseInt(e.style.height):oh-parseInt(TINY.style.get(e,'height'));
			if(ow!=w-wo||oh!=h-ho){
				var wd=ow-wo>w?-1:1, hd=(oh-ho>h)?-1:1; clearInterval(e.si);
				e.si=setInterval(function(){TINY.size.tw(e,w,wo,wd,h,ho,hd,s)},20)
			}
		},
		tw:function(e,w,wo,wd,h,ho,hd,s){
			var ow=e.offsetWidth-wo, oh=e.offsetHeight-ho;
			if(ow==w&&oh==h){clearInterval(e.si)}
			else{
				if(ow!=w){e.style.width=ow+(Math.ceil(Math.abs(w-ow)/s)*wd)+'px'}
				if(oh!=h){e.style.height=oh+(Math.ceil(Math.abs(h-oh)/s)*hd)+'px'}
				TINY.box.position()
			}
		}
	}
}();
