var TINY={};


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

TINY.box=function(){

var tb_f_event_height = tb_f_event_width = 0;
var tb_f_cn_length = 0;
var tb_cn = null;


	var p,m,b,fn,ic,iu,iw,ih,ia,f=0;
	var ev_file = 'g_ev.php';
var curleft = curtop = 0;
var cal_src_el_h = cal_src_el_w = 0;
	
	return{
		show:function(mev,dy,mnt,yr,u,w,h,a,t){
		
		//modddddd
		//h='300';
var cal_f = "./eventmanager/";
curleft = curtop = 0;
//determine the position of the box that was clicked
var m_event = mev || window.event;
var source_element = m_event.target || m_event.srcElement; 
//var curleft = curtop = 0;
cal_src_el_h = source_element.offsetHeight;
cal_src_el_w = source_element.offsetWidth;

var obj = source_element
if (obj.offsetParent) {
do{
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}while (obj = obj.offsetParent);
}
//end the determination of the position of the box that was clicked



			if(!f){
				p=document.createElement('div'); p.id='mirical_tinybox';
				m=document.createElement('div'); m.id='mirical_tinymask';
				b=document.createElement('div'); b.id='mirical_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='100px';  
				
				if(navigator.appName == 'Netscape'){p.style.height='100px'; }
				if(navigator.appName == 'Microsoft Internet Explorer'){p.style.height='100px'; p.style.overflow = 'visible';}
				
				//p.style.height='180px';
				//alert(navigator.appName);
			}
			this.mask();

ev_url = cal_f+''+ev_file+'?cal_day='+dy+'&cal_month='+mnt+'&cal_year='+yr;





			ic=ev_url; iu=u; iw=w; ih=h; ia=a; this.alpha(m,1,80,3);







			if(t){setTimeout(function(){TINY.box.hide()},1000*t)}
		},
		fill:function(c,u,w,h,a){
			if(u){
				p.style.backgroundImage='';
				var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
				x.onreadystatechange=function(){
					if(x.readyState==4&&x.status==200){TINY.box.psh(x.responseText,w,h,a)}
				};
				x.open('GET',ev_url,1); x.send(null)
			}else{
				this.psh(c,w,h,a)
			}
		},
		psh:function(c,w,h,a){
			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'
			}

tb_cn = document.getElementById('mirical_tinycontent').childNodes;

var iii = "";

var tbcnn = tb_cn[1].childNodes;
tb_f_cn_length = tb_cn.length;

if(tb_f_cn_length>1)
{
iii = tb_cn[1].getAttribute('id');


tb_f_event_height = tb_cn[1].offsetHeight; 
tb_f_event_width = document.getElementById(iii).offsetWidth;
}


//document.getElementById('t_stat').innerHTML += ((tb_cn.length)+"["+iii+"] H:"+tb_f_event_height+" W:"+tb_f_event_width+"<br />");
		},
		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;//do not uncomment


var t = curtop; //t=t<10?10:t;//do not uncomment
if(curtop < ih){t=curtop+(cal_src_el_h);}else{t=curtop-(cal_src_el_h/2)-(ih/2);}
//if(curtop < ih){t=curtop-ih;}else{t=curtop+cal_src_el_h;}//do not uncomment


//document.getElementById('t_stat').innerHTML = t+"<br />";


p.style.top=(t+TINY.page.top())+'px';


var l = curleft; 
if(curleft < iw){l=curleft+cal_src_el_w;}else{l=curleft-iw}
//if(curleft < iw){l=curleft-p.offsetWidth;}else{l=curleft+cal_src_el_w;}//do not uncomment
//p.style.left=(TINY.page.width()/2)-(p.offsetWidth/2)+'px'//do not uncomment
//document.getElementById('l_stat').innerHTML = ('#'+curleft+":"+iw+' : '+cal_src_el_w+" : "+l+" | "+tb_cn.length+" :"+tb_f_cn_length+"[]"+tb_f_event_width+"<br />");

p.style.left=l+'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(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(){TINY.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); p.style.backgroundImage='none'; b.style.display='block'
			}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()
			}
		}
	}
}();

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))
		}
	}
}();

