// Menu functions
function menuobj(objid,delay) {
	this.count=0;
	this.delay=delay;
	this.objid=objid;
	this.width=this.objid.offsetWidth;
	this.widthFrom=0;
	this.widthTo=0;
	this.timer=0;
}
function pE() {
	obj=this.id.charAt(this.id.length-1);
	startEase(obj);
}
function sE() {
	obj=this.id.charAt(this.id.length-1);
	stopEase(obj);
}
function startEase(o) {
		obj=mnbut[o];
		obj.count=0;
		obj.widthFrom = obj.objid.offsetWidth;
		obj.widthTo = 137-obj.widthFrom;
		easeIt(o);
}
function stopEase(o) {
		obj=mnbut[o]
		clearTimeout(obj.timer);
		obj.count=0;
		obj.widthFrom = obj.objid.offsetWidth;
		obj.widthTo = obj.width-(obj.objid.offsetWidth);
		easeIt(o);
}
function easeIt(o) {
		obj=mnbut[o];
		objmove=Math.round(easeOutBounce(obj.count++,obj.widthFrom,obj.widthTo,obj.delay));
		if(objmove>obj.width) obj.objid.style.width=objmove+"px";
		else obj.objid.style.width=obj.width+"px";
		if(obj.count<=obj.delay) { obj.timer = setTimeout('easeIt('+o+')', 50); }
}
// Tooltips functions
function tipsobj(objid,delay) {
this.count=0;
this.delay=delay;
this.objid=objid;
this.width=this.objid.offsetWidth;
this.height=this.objid.offsetHeight;
this.heightFrom=0;
this.heightTo=0;
this.widthFrom=0;
this.widthTo=0;
this.timer=0;
this.state=1;
this.text="";
}
function tipseaseOn(tid) {
	var ttips=document.getElementById('tooltips');
	ttips.style.display="block";
	if(ttips.filters) ttips.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=80)";
	else ttips.style.opacity=0.8;
	obj=tooltipsBox;
	clearTimeout(obj.timer);
	obj.text="<p>"+document.getElementById(tid).innerHTML+"</p>";
	obj.state=1;
	obj.count=0;
	obj.heightFrom = obj.objid.offsetHeight;
	obj.heightTo = obj.height-(obj.objid.offsetHeight);
	obj.widthFrom = obj.objid.offsetWidth;
	obj.widthTo = obj.width-(obj.objid.offsetWidth);
	tipseaseIt();
}
function tipseaseOff() {
	obj=tooltipsBox;
	clearTimeout(obj.timer);
	document.getElementById('tooltipsmid').innerHTML="";
	obj.state=0;
	obj.count=0;
	obj.heightFrom = obj.objid.offsetHeight;
	obj.heightTo = 1-(obj.objid.offsetHeight);
	obj.widthFrom = obj.objid.offsetWidth;
	obj.widthTo = 19-(obj.objid.offsetWidth);
	tipseaseIt();
}
function tipseaseIt() {
	obj=tooltipsBox;
	tt=document.getElementById('tooltipstop');
	tb=document.getElementById('tooltipsbot');
	resa=Math.round(easeInOutCirc(obj.count,obj.widthFrom,obj.widthTo,obj.delay));
	resb=Math.round(easeOutBounce(obj.count++,obj.heightFrom,obj.heightTo,obj.delay));
	tres=(resa-18)>0?(resa-18):1;
	tt.style.width=tres+"px";
	tb.style.width=tres+"px";
	obj.objid.style.width=resa+"px";
	obj.objid.style.height=(resb>0)?(resb+"px"):(1+"px");
	if(obj.count<=obj.delay) obj.timer = setTimeout('tipseaseIt()', 50);
	else if (obj.state) { document.getElementById('tooltipsmid').innerHTML=obj.text; }
	else {
		fade=80;
		document.getElementById('tooltips').alphaTimer = alphaEffect('tooltips',-20);
	}

}
function alphaEffect(mc,step) {
	mcTofade=document.getElementById(mc);
	if(mcTofade.offTimer) clearTimeout(mcTofade.offTimer);
	if(mcTofade.filters) mcTofade.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+fade+")";
	else mcTofade.style.opacity=fade/100;
	fade+=step;
	if(fade>0 && fade<100) mcTofade.alphaTimer = setTimeout('alphaEffect("'+mc+'",'+step+')', 15);
	else if(fade<=0) {
		mcTofade.style.display="none"; 
		if(mc=="cache") {
			if(window.infoMail) { menushow(); infoMail(); }
			else { menushow(); }
		}
	} else {
  	if(mcTofade.filters) mcTofade.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
  	else mcTofade.style.opacity=1.0; 
    if(mc=="combo_items") {
      mcTofade.offTimer = setTimeout(function(){ alphaEffect('combo_items',-10); },2000);
      mcTofade.onmouseover = function() { clearTimeout(this.offTimer); }
      mcTofade.onmouseout = function() { mcTofade.offTimer = setTimeout(function(){ alphaEffect('combo_items',-10); },2000); }
    } 
  }
}
function infoMail() {
	if(document.getElementById('tipsMail').innerHTML!="") {
		tipseaseOn('tipsMail'); setTimeout('tipseaseOff()', 10000);
	}
}
function inputFocus() {
	if (this.value==this.old) { this.value =''; }
	else if(this.value=='') this.value=this.old;
}
function tipsinit() {
	d=document.getElementById('tooltipsmid');
	tooltipsBox = new tipsobj(d,12);
	d.style.width=19+"px";
	d.style.height=1+"px";
	document.getElementById('tooltipstop').style.width=1+"px";
	document.getElementById('tooltipsbot').style.width=1+"px";
	document.getElementById('tooltips').style.display="none";
	// Newsletter input
	Inpnews=document.getElementById("inews");
	Inpnews.onfocus=Inpnews.onblur=inputFocus;
	Inpnews.old=Inpnews.value;
}
function menusetup() {
	for(i=0;i<7;i++) {
		m[i]=document.getElementById('mn'+i);
		mcontent[i]=m[i].innerHTML;
		mcount[i]=(-i*3);
		mnbut[i]=new menuobj(m[i],16);
		m[i].onmouseover=pE;
		m[i].onmouseout=sE;
		m[i].innerHTML="";
	}
}
function menushow() {
	var still=false;
	for(i=0;i<7;i++) {
		if(mcount[i]>=0) {
			if(mcount[i]<mcontent[i].length) {
				if(mcontent[i].charCodeAt(mcount[i])==32) {
				m[i].innerHTML+=".";
				mcount[i]++;
				} else  m[i].innerHTML+=mcontent[i].charAt(mcount[i]++);
				still=true;
			}
		} else { mcount[i]++; still=true; }
	}
	if(still) { setTimeout('menushow()',10); }
	else {
		rExp = /\./gi;
		for(i=0;i<7;i++) m[i].innerHTML=m[i].innerHTML.replace(rExp," ");
		if(window.plotPoint) { plotPoint(); }
	}
}
function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = document.getElementById(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight)
	{
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop+'px '+clipWidth+'px '+clipBottom+'px 0px)'
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper+"px";
	}
	time = setTimeout('realscroll()',theTime);
}
function getScreenSize() {
	var bbx,bby;
	if (self.innerHeight)
	{
		bbx = self.innerWidth;
		bby = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		bbx = document.documentElement.clientWidth;
		bby = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		bbx = document.body.clientWidth;
		bby = document.body.clientHeight;
	}
	return Array(bbx,bby);
}
function bbAdjust() {
	reInit();
	gss = getScreenSize();
	bbLeft=document.getElementById("bluebarleft");
	bbLeft.style.width=(gss[0]-237)+"px";
	Bbox=document.getElementById("box");
	BarPosY=findPosY(document.getElementById("bluebarleft"));
	Bmenu=document.getElementById("menu");
	Bmenu.style.left=(findPosX(Bbox)-356)+"px";
	var tmp = (((BarPosY-288)/2)-Bmenu.offsetHeight/2)+292;
	Bmenu.style.top=tmp+"px";
	NewsBox=document.getElementById("newsLetterBox");
	Bleft=(findPosX(Bbox)+384)+"px";
	//Bleft=(findPosX(Bbox)-142)+"px";
	//NewsBox.style.top="226px";
	NewsBox.style.top="127px";
	NewsBox.style.left=Bleft;
}
function findPosX(obj) {
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x) curleft += obj.x;
		return curleft;
}
	
function findPosY(obj) {
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y) curtop += obj.y;
		return curtop;
}
function playSnd(snd) {
	var s=document.getElementById(snd);
	 if(s.autostart) {
	  s.Play();
	 }
}
function combo_menu() {
  d = document.getElementById('combo_items');
  if(d.style.display!="block") { 
    d.style.display="block";
    alphaEffect('combo_items',10);
  } else { 
    alphaEffect('combo_items',-10);
  }
}
function easeOutBounce(t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
};
function easeInOutCirc(t, b, c, d) {
	if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
	return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
};
