var i,j,mouseX=0,mouseY=0,gtext="/gtext.php",aS=new Array(),evs,ar=/#([^#.]*)$/,ur=/(.*)#(.*)$/,expl,asb=null;

Array.prototype.inArray=function(v){
	for(var k in this)
		if(this[k]===v)
			return(true);
	return(false);
};

function getElementsByClassName(cl){
	var tc=new RegExp('(^|\\s)'+cl+'(\\s|$)'),rv=new Array(),es=(document.all)?document.all:document.getElementsByTagName("*"),el;
	for(i=0;i<es.length;i++){
		el=es[i];
		if(tc.test(el.className))
			rv.push(el);
	}
	return(rv);
}

function isClassName(o,wn){
	var tc=new RegExp('(^|\\s)'+wn+'(\\s|$)'),cn=o.className;
	return((cn)?cn.match(tc):false);
}

function addClassName(o,wn){
	if(isClassName(o,wn))
		return;
	var cn=o.className;
	if(cn!='')
		o.className+=' '+wn;else o.className+=wn;
}

function rmClassName(o,wn){
	if(!isClassName(o,wn))
		return;
	var cn=o.className,an=new Array(),t=cn.split(' ');
	for(i=0;i<t.length;i++)
		if(t[i]!=wn)
			an.push(t[i]);
	o.className=an.join(' ');
}

function tEvent(e){
	e=e?e:window.event;
	if(!e.preventDefault)
		e.preventDefault=function(){return false;};
	if(!e.stopPropagation)
		e.stopPropagation=function(){if(window.event)window.event.cancelBubble=true;};
	if(e.pageX||e.pageY){
		mouseX=e.pageX;
		mouseY=e.pageY;
	}else if(e.clientX||e.clientY){
		mouseX=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
		mouseY=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;
	}
	return(e);
}

function addEL(o,e,f,b){
	b=(b)?b:false;
	if(o.addEventListener)
		o.addEventListener(e,f,false);
	else if(o.attachEvent)
		o.attachEvent('on'+e,f);
}

function rmEL(o,e,f,b){
	b=(b)?b:false;
	if(o.removeEventListener)
		o.removeEventListener(e,f,false);
	else if(o.detachEvent)
		o.detachEvent('on'+e,f);
}

function getStyle(o,p,q){
	if(window.getComputedStyle)
		return(window.getComputedStyle(o,null).getPropertyValue(p));
	else if(o.currentStyle)
		return(o.currentStyle[q]);
	else return(false);
}

/*
function tcv(c){
	var a,b,cr=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;
	if(a=cr(c)){
		b='#';
		for(i=1;i<4;i++)
			b+=((parseInt(a[i]).toString(16).length==1)?'0':'')+parseInt(a[i]).toString(16);
	} else
		b=c;return(b);
}
*/
function tcv(c){
	var a,b,cr=new RegExp('/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/');
	if(a=c.match(cr)){
		b='#';
		for(i=1;i<4;i++)
			b+=((parseInt(a[i]).toString(16).length==1)?'0':'')+parseInt(a[i]).toString(16);
	} else
		b=c;
	return(b);
}

function replaceText(o,p){
	var q=document.createElement("img");
	q.src=p;
	q.alt=o.innerHTML;
	q.title=o.innerHTML;
	while(o.childNodes.length)
		o.removeChild(o.firstChild);
	o.appendChild(q);
	addClassName(q,'static');
}

function tri(d){
	var a=d.split(":"),os,t=a[0],n=a[1],u,o,s,h,v,cs,st,bs,p,q,x,y;
	switch(t){
		case"TagName":
			os=document.getElementsByTagName(n);
			if(!os)return;
			break;
		case"ClassName":
			os=getElementsByClassName(n);
			if(!os)return;
			break;
		case"Id":
			u=document.getElementById(n);
			if(!u)return;
			os=new Array(u);
			break;
		default:return;
	}
	if(!os[0])return;
	o=os[0];
	var s=new Object();
	if(o!=null){
		if(o.currentStyle){
			h=o.currentStyle;
			s.c=(h['color']!=null)?h['color']:"#000000";
			s.s=(h['fontSize']!=null)?h['fontSize']:'';
			s.w=(h['fontWeight']==700)?'bold':'normal';
			s.b=(h['backgroundColor']!=null)?h['backgroundColor']:'';
			s.f=(h['fontFamily']!=null)?h['fontFamily']:'';
		}else if(window.getComputedStyle){
			v=document.defaultView.getComputedStyle(o,null);
			s.c=tcv(v.getPropertyValue('color'));
			s.s=(v.getPropertyValue('font-size')!=null)?v.getPropertyValue('font-size'):"";
			s.w=(v.getPropertyValue('font-weight')==700)?'bold':'normal';
			s.b=tcv(v.getPropertyValue('background-color'));
			s.f=(v.getPropertyValue('font-family')!=null)?v.getPropertyValue('font-family'):"";
		}
	}
	if(s.c.substr(0,1)=="#")s.c=s.c.substr(1,6);
	if(s.b.substr(0,1)=="#")s.b=s.b.substr(1,6);
	s.s=parseInt(s.s);
	s.f=s.f.split(",")[0];
	st=s.f+"|"+s.s+"|"+s.w+"|"+s.c+"|"+s.b;
	for(i=0;i<os.length;i++){
		q=gtext+"?s="+encodeURI(st)+"&t="+encodeURI(os[i].innerHTML);
		p=new Image();
		p.src=q;
		replaceText(os[i],q);
	}
}

function createTextImages(d){
	var a=d.split(","),k;
	for(k=0;k<a.length;k++)tri(a[k]);
}

function oAsT(e){
	e=tEvent(e);
	evs=(e.srcElement)?e.srcElement:this;
	expl.sh(evs,evs._title);
	return(true);
}

function oAhT(e){
	e=tEvent(e);
	evs=(e.srcElement)?e.srcElement:this;
	expl.hd();
	return(true);
}

function Scr(p){
	this.vd=document.createElement('div');
	this.vd.par=this;
	this.cd=document.createElement('div');
	this.cd.par=this;
	this.bd=document.createElement('div');
	this.bd.par=this;
	this.sd=document.createElement('div');
	this.sd.par=this;
	var sbw;
	this.seo=function(e){
		e=tEvent(e);
		var pa=((e.srcElement)?e.srcElement:this).par;
		with(pa){
			if(!sd.dr&&sd.mo)sd.style.backgroundColor=sd.nc;
			sd.mo=false;
		}
		return(true);
	};
	this.dra=function(e){
		e=tEvent(e);
		var dy;
		dy=asb.sd.sy+mouseY-asb.sd.mdy;
		dy=Math.min(Math.max(asb.sd.miy,dy),asb.sd.may);
		asb.sd.style.top=dy+"px";
		asb.ss(dy/asb.sd.may);
		return false;
	};
	this.ed=function(e){
		e=tEvent(e);
		with(asb){
			sd.dr=false;
			if(!sd.mo)sd.style.backgroundColor=sd.nc;
		}
		rmEL(document,"mousemove",asb.dra,true);
		rmEL(document,"mouseup",asb.ed,true);
		asb=null;
	};
	this.sdr=function(e){
		e=tEvent(e);
		var pa=((e.srcElement)?e.srcElement:this).par;
		pa.sd.mdy=mouseY;
		pa.sd.sy=pa.sd.offsetTop;
		pa.sd.dr=true;
		asb=pa;
		addEL(document,"mousemove",pa.dra,true);
		addEL(document,"mouseup",pa.ed,true);
		e.stopPropagation();
	};
	this.so=function(e){
		e=tEvent(e);
		var src=((e.srcElement)?e.srcElement:this);
		src.mo=true;
		src.style.backgroundColor=src.oc;return(true);
	};
	this.ss=function(p){
		var o=(-1)*Math.round((this.cd.offsetHeight-this.vd.offsetHeight)*(p));
		this.cd.style.top=o+"px";
	};
	this.mw=function(e){
		e=tEvent(e);
		var pa=this.par,dx=10,wd=0,y;
		if(!e)
			e=window.event;
		if(e.wheelDelta)
			wd=-e.wheelDelta/20;
		else if(e.detail)
			wd=e.detail*2;
		if(wd){
			y=pa.sd.offsetTop+wd;
			y=Math.min(Math.max(pa.sd.miy,y),pa.sd.may);
			pa.sd.style.top=y+"px";
			pa.ss(y/pa.sd.may);
		}
	};
	this.sl=function(e){
		e=tEvent(e);
		var pa=((e.srcElement)?e.srcElement:this).par,y;
		e.offY=(e.layerY)?e.layerY:e.offsetY;
		y=e.offY-Math.round(pa.sd.offsetHeight/2);
		y=Math.min(Math.max(y,pa.sd.miy),pa.sd.may);
		pa.sd.style.top=y+"px";
		pa.ss(y/pa.sd.may);
		return false;
	};
	addClassName(this.bd,'slidebar');
	this.bd.style.height=p.offsetHeight+'px';
	addClassName(this.sd,'slider');
	this.sd.miy=0;
	this.sd.dr=false;
	addEL(this.sd,'mousedown',this.sdr);
	addEL(this.sd,'mouseover',this.so);
	addEL(this.sd,'mouseout',this.seo);
	addEL(this.bd,'mousedown',this.sl);
	this.bd.appendChild(this.sd);
	addClassName(this.vd,'sviewport');
	this.vd.style.height=p.offsetHeight+'px';
	addClassName(this.cd,'scontent');
	this.cd.innerHTML=p.innerHTML;
	if(this.cd.addEventListener){
		this.cd.addEventListener("DOMMouseScroll",this.mw,false);
	}
	this.cd.onmousewheel=this.mw;
	this.vd.appendChild(this.cd);
	while(p.childNodes.length)p.removeChild(p.firstChild);
	p.appendChild(this.vd);
	p.appendChild(this.bd);
	sbw=parseInt(getStyle(this.bd,'width','width'));
	this.sd.nc=getStyle(this.sd,'backgroundColor','backgroundColor');
	this.sd.oc=getStyle(this.sd,'color','color');
	this.bd.style.left=(p.offsetWidth-sbw)+'px';
	this.vd.style.width=(p.offsetWidth-sbw-10)+'px';
	this.cd.style.width=(p.offsetWidth-sbw-10)+'px';
	this.gTT=function(){
		this.sd.style.top="0px";
		this.cd.style.top="0px";
	};
	this.rs=function(){
		var g,h;
		if(this.cd.offsetHeight<=this.vd.offsetHeight){
			this.bd.style.visibility='hidden';
			return;
		}
		h=Math.max(Math.round(Math.pow(this.vd.offsetHeight,2)/this.cd.offsetHeight),11);
		this.sd.style.height=h+"px";
		this.sd.may=this.bd.offsetHeight-this.sd.offsetHeight;
		this.bd.style.visibility='visible';
		this.gTT();
	};
	this.gTE=function(t){
		var ic=false,tt=t,o=0,m,s;
		while(tt=tt.parentNode){
			if(tt==this.cd)ic=true;
		}
		if(!ic)return(false);
		tt=t;
		while(tt!=this.cd&&!tt.offsetHeight&&tt.parentNode&&getstyle(s,'display','display')=='inline'){
			tt=tt.parentNode;
		}
		if(tt.offsetParent){
			while(tt!=this.cd){
				o+=tt.offsetTop;
				tt=tt.offsetParent;
			}
		}
		m=this.cd.offsetHeight-this.vd.offsetHeight;
		s=Math.round(o/(m)*this.sd.may);
		this.sd.style.top=Math.min(Math.max(s,0),this.sd.may)+"px";
		this.cd.style.top=((-1)*Math.min(Math.max(o,0),m))+"px";
		return(true);
	};
}

function cTi(){
	var d0,d1,d2;this.t=document.createElement('div');
	this.t.id='title';
	for(i=1;i<6;i++){
		d0=document.createElement('div');
		d0.className='t_sb shaddow'+i;
		d0.id='t_sb'+i;this.t.appendChild(d0);
		d1=document.createElement('div');
		d1.className='t_sc shaddow'+i;
		d1.id='t_sc'+i;this.t.appendChild(d1);
		d2=document.createElement('div');
		d2.className='t_sr shaddow'+i;
		d2.id='t_sr'+i;this.t.appendChild(d2);
	}
	this.l=document.createElement('div');
	this.l.id='title_left';
	this.m=document.createElement('div');
	this.m.id='title_main';
	this.r=document.createElement('div');
	this.r.id='title_right';
	this.t.appendChild(this.l);
	this.t.appendChild(this.m);
	this.t.appendChild(this.r);
	this.t.style.visibility='hidden';
	document.getElementsByTagName('body')[0].appendChild(this.t);
	this.ss=function(w){
		var d0,d1,d2;
		for(i=1;i<6;i++){
			d0=document.getElementById('t_sb'+i);
			d0.style.width=(w-9)+'px';
			d0.style.height='1px';
			d0.style.left=(4+i)+'px';
			d0.style.top=(24+i)+'px';
			d1=document.getElementById('t_sc'+i);
			d1.style.left=(w-5+i)+'px';
			d1.style.top=(20+i)+'px';
			d2=document.getElementById('t_sr'+i);
			d2.style.height='16px';
			d2.style.width='1px';
			d2.style.left=(w-1+i)+'px';
			d2.style.top=(4+i)+'px';
		}
	};
	this.sh=function(s,t){
		var r,u,w,x=-20,y=20,z;
		u=this.m;
		z=this.t;
		u.innerHTML=t;
		w=u.offsetWidth;
		this.r.style.left=(u.offsetWidth+13)+'px';
		while(!s.offsetHeight&&s.parentNode&&getstyle(s,'display','display')=='inline'){
			s=s.parentNode;
		}
		if(s.offsetParent){
			while(s.offsetParent){
				y+=s.offsetTop;
				x+=s.offsetLeft;
				s=s.offsetParent;
			}
		}
		if((x+w)>document.getElementById('divmain').offsetWidth)x=document.getElementById('divmain').offsetWidth-w;z.style.top=y+"px";
		z.style.left=x+"px";
		this.ss(w+26);
		z.style.visibility='visible';
	};
	this.hd=function(){
		this.t.style.visibility='hidden';
	};
}

function goToTop(o){
	while(o=o.parentNode)
		if(isClassName(o,'scrolled')){
			a=o.firstChild.par.gTT();
			return(true);
		}
	return(false);
}

function checkAnchorURL(){
	var j,b,c=document.location.href,d,f,g;
	for(j=0;b=aS[j];j++)b.gTT();
	if(c.match(ur)){
		d=c.match(ur)[2];
		d="_"+d;
		f=(document.getElementById(d))?document.getElementById(d):((document.getElementsByName(d)[0]!=null)?document.getElementsByName(d)[0]:null);
		if(g=f)
			while(g=g.parentNode)
				if(isClassName(g,'scrolled'))
					g.firstChild.par.gTE(f);
	}
}

function aCl(e){
	e=tEvent(e);
	var s=false,t=null,src=(e.srcElement)?e.srcElement:this,n,tt;
	while(!src.isPA&&src.parentNode){
		src=src.parentNode;
	}
	if(!src.isPA)return;
	n=src.href.match(ar)[1];
	if(n=='_top'){
		if(goToTop(src))return(e.preventDefault());
	}else{
		n="_"+n;
		t=(document.getElementById(n))?document.getElementById(n):((document.getElementsByName(n)[0]!=null)?document.getElementsByName(n)[0]:null);
		if(t!=null){
			tt=t;
			while(tt=tt.parentNode)
				if(isClassName(tt,'scrolled')){
					tt.firstChild.par.gTE(t);
					s=true;
				}
			if(s){
				e.preventDefault();
				document.location.href="#"+src.href.match(ar)[1];
				return false;
			}
		}
	}
	return true; 
}

function ma(){
	var dl=document.location.href,aA=document.getElementsByTagName('a'),osA=new Array(),oA,o,ct=false;
	if(dl.match(ur))dl=dl.match(ur)[1];
	for(i=0;o=aA[i];i++)
		while(o.parentNode){
			if(isClassName(o.parentNode,'scrolled')){
				osA.push(aA[i]);
				break;
			}
			o=o.parentNode;
		}
	for(i=0;oA=osA[i];i++){
		if(oA.href){
			if(oA.href.match(ar)&&oA.href.match(ur)){
				if(dl===oA.href.match(ur)[1]){
					oA.isPA=true;
					addEL(oA,'click',aCl);
					if(!isClassName(oA,'static')){
						if('_top'==oA.href.match(ur)[2])
							addClassName(oA,'toplink');
						else
							addClassName(oA,'pagelink');
					}
				}
			}else if((oA.hostname!=document.domain)&&(!isClassName(oA,'static'))){
				ct=true;addClassName(oA,"extlink");
				if(oA.title!=''){
					oA._title=oA.title;
					oA.title='';
				}else oA._title=oA.href;addEL(oA,'mouseover',oAsT);
				addEL(oA,'mouseout',oAhT);
			}
		}
	}
	if(ct){
		expl=new cTi();
	}
}

function createScrollers(){
	var s=getElementsByClassName('scrolled'),sd;
	for(var k=0;sd=s[k];k++){
		aS.push(new Scr(sd));
	}
	ma();
}

function ccs(o){
	var a=o.innerHTML,b=o.id,d,x,y,f,g;
	while(o.childNodes.length)o.removeChild(o.firstChild);
	x=o.offsetWidth;
	y=o.offsetHeight;
	o.style.width=(x+5)+"px";
	o.style.height=(y+5)+"px";
	for(i=0;i<5;i++){
		d=document.createElement('div');
		d.style.backgroundImage='url(/img/'+b+'_s.png)';
		d.style.position='absolute';
		d.style.width=x+'px';
		d.style.height=y+'px';
		d.style.top=d.style.left=(i+1)+'px';
		addClassName(d,'shaddow'+(i+1));
		o.appendChild(d);
	}
	d=document.createElement('div');
	d.style.backgroundImage='url(/img/'+b+'.png)';
	d.style.position='absolute';
	d.style.width=x+'px';
	d.style.height=y+'px';
	d.style.top=d.style.left='0px';
	d.innerHTML=a;o.appendChild(d);
}

function cCS(){
	var csh=getElementsByClassName('cshaddowed'),k,o;
	for(k=0;o=csh[k];k++)
		ccs(o);
}

function showMenu(e){
	document.getElementById('menu'+this.menuId).style.visibility = "visible";
}

function hideMenu(e){
	this.style.visibility="hidden";
}

function ciT(el){
	var se,im;
	se=el.getElementsByTagName('span');
	for(i=0;i<se.length;i++){
		im=document.createElement("img");
		im.src='/buttons.php?s=tab_s&t='+encodeURI(se[i].innerHTML);
		im.alt=se[i].innerHTML;
		im.title=se[i].innerHTML;
		while(se[i].childNodes.length){
			se[i].removeChild(se[i].firstChild);
		}
		se[i].appendChild(im);
	}
	se=el.getElementsByTagName('a');
	for(i=0;i<se.length;i++){
		im=document.createElement("img");
		im.src='/buttons.php?s=tab_u&t='+encodeURI(se[i].innerHTML);
		im.alt=se[i].innerHTML;
		im.title=se[i].innerHTML;
		while(se[i].childNodes.length){
			se[i].removeChild(se[i].firstChild);
		}
		se[i].appendChild(im);
	}
}

function mT(){
	var aT=getElementsByClassName('tabs'),tc;
	for(tc=0;tc<aT.length;tc++){
		ciT(aT[tc]);
	}
}

function initPage(){
	var sc;if(!document.getElementById)return false;
	cCS();
	createScrollers();
	createTextImages("TagName:h1,TagName:h2,TagName:h3,ClassName:w_g,ClassName:w_r");
	mT();
	replaceText(document.getElementById('logoanchor'),'/img/logo.png',200,47);
	for(var k=0;sc=aS[k];k++){
		sc.rs();
	}
	for(var i=0;i<3;i++){
		if(document.getElementById('divmenu'+i)){
			document.getElementById('divmenu'+i).menuId=i;
			document.getElementById('divmenu'+i).onmouseover=showMenu;
			document.getElementById('menu'+i).menuId=i;
			document.getElementById('menu'+i).onmouseover=showMenu;
			document.getElementById('menu'+i).onmouseout=hideMenu;
		}
	}
	checkAnchorURL();
}

addEL(window,'load',initPage);

function ShB(wi){
	document.getElementById(wi).style.visibility='visible';
	return(false);
}

function HhB(wi){
	document.getElementById(wi).style.visibility='hidden';
	return(false);
}

function menu3r(){
	var menu3red=new Image();
	menu3red.src='/img/menu3t.png';
	var targ3=document.getElementById('m3t');
	targ3.src=menu3red.src;
}

function menu3g(){
	var menu3gray=new Image();
	menu3gray.src='/img/menu3.png';
	var targ3=document.getElementById('m3t');
	targ3.src=menu3gray.src;
}
