// JavaScript menus
// copyright 2004 Bernhard Barkow - bb@creativeeyes.at
// except for the MM_* functions supplied by Macromedia Dreamweaver
function getElem(s) { return document.getElementById(s); }
function docBody() {	// Safari fix (3.0.4)
	var d=document, b;
	if (d.body) b=d.body;
	else {
		b=d.firstChild.children[1];
		if (b.tagName.toLowerCase()!="body") b = d.documentElement;
	}
	return b;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function BB_swapImgRestoreM(s) { //mod. from MM_swapImgRestore v3.0
  var i,x,a=document.BB_sr[s]; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function BB_swapImageM() { //v3.0
  var i,j=0,x,a=BB_swapImageM.arguments,s=a[0];
	if(a[1]) {
		var d=document; d.BB_sr[s]=new Array(); for(i=1;i<(a.length);i+=2)
			if ((x=getElem(a[i]))!=null) { d.BB_sr[s][j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+1]; }
	}
}

function BB_findXY(o) {
	var x=0, y=0; if(o.offsetParent) {
		do { x+=o.offsetLeft; y+=o.offsetTop; } while (o=o.offsetParent);
  }
	return [x,y];
}
function BB_findWDim() {
	var a,d=document,wd=Array(); if(self.innerWidth) {wd[0]=self.innerWidth; wd[1]=self.innerHeight; }
	else {
		if (d.documentElement && d.documentElement.clientHeight) a=d.documentElement; else a=d.body;
		wd[0]=a.clientWidth+a.scrollLeft;
		wd[1]=a.clientHeight+a.scrollTop;
	}
	return wd;
}

function BB_initM() { //main initialization
	var d=document; d.bbiMTID=new Array(); d.bbMArr=new Array(); d.bbMIArr=new Array(); d.bbMOpen=0;
	d.BB_sr=new Array();window.onunload=BB_hideMenus;
}

function BB_showMenu(m,r,l,h,v) { //menu layer, reference object, level,
	//h: 0=right edge of menu aligned with left edge of ref. / 1=ll / 2=rr / 3=lr,
	//v: 0=top edge of menu at bottom edge of ref. / 1=bb / 2=tt / 3=bt
	var obj=getElem(m),ref=getElem(r),d=document,i,x,y;
	var ow=obj.offsetWidth,oh=obj.offsetHeight,rw=ref.offsetWidth,rh=ref.offsetHeight,bF=false;
	var wd=BB_findWDim();
	for (i=0; i<d.bbMOpen && !bF; i++){ if(d.bbMArr[i]==m){ BB_cHide(i); bF=true; } }
	if(!bF) {
		if(l==0) BB_hideAllMenus(); else d.bbMIArr[i]=r;
		i=d.bbMOpen;
		if (obj.style) obj=obj.style;
		var xy=BB_findXY(ref);
		x = xy[0] + (h<=1 ? 0 : rw);
		if (h==1 || h==3) obj.left=Math.min(x,wd[0]-ow)+'px'; else obj.right=x+'px';
		y = xy[1] + (v>1 ? 0 : rh);
		if (v==1 || v==3) { y = wd[1]-y; if (y<.05*wd[1]+rh) y+=docBody().scrollTop; obj.bottom=(y)+'px'; }
		else obj.top=Math.min(y,wd[1]-oh)+'px';
		d.bbMArr[i]=m;d.bbiMTID[i]=-1;d.bbMOpen++;//BB_setMVis(obj,(l>0 ? ref : null),true);
		fadeIn(m);
	}
}

function BB_setMVis() {//obj,ref,show(t)/hide(f)
	var a=BB_setMVis.arguments, o=a[1];
	BB_setVis(a[0],a[2]);
	if(o!=null) {
		if(!RegExp(/\bmactive\b/).test(o.className) && a[2]) o.className+=" mactive"; 
		else o.className=o.className.replace(/[\s]?mactive\b/,"");
	}
}
function BB_setVis() { // args: object,vis=t(show)/f(hide)
	var a=BB_setVis.arguments,p=a[0],v='visible'; if(p!=null) { if(p.style != null) p=p.style;
		if ((p.visibility==v) != a[1]) { if(!a[1]) v='hidden'; p.visibility=v } }
}

function BB_hideMenu(i) {
	var d=document;
	//BB_setMVis(getElem(d.bbMArr[i]), (i>0 ? getElem(d.bbMIArr[i]) : null), false);
	fadeOut(d.bbMArr[i]);
}
function BB_hideMenus() {
	var d=document,i=d.bbMOpen-1; if(i>-1 && d.bbiMTID[i]!=-1) { d.bbiMTID[i]=-1; BB_hideMenu(i); d.bbMOpen--; }
	if(d.bbMOpen==0) BB_swapImgRestoreM(1);
}
function BB_hideAllMenus() {
	var d=document,i; for(i=0; i<d.bbMOpen; i++) { d.bbiMTID[i]=-1; BB_hideMenu(i); } d.bbMOpen=0;
}

function BB_dHideM() { //hide menus
	var d=document,i;
	for(i=0; i<d.bbMOpen; i++){ if(d.bbiMTID[i]==-1) d.bbiMTID[i]=window.setTimeout("BB_hideMenus()",(i>0 ? 250 : 700)); }
}

function BB_cHide(l) { //menu level
	var d=document;
	for (i=0; i<=l && i<d.bbMOpen; i++){ if(d.bbiMTID[i]!=-1) { window.clearTimeout(d.bbiMTID[i]); d.bbiMTID[i]=-1; } }
}

function BB_getMenuTopPos() {
	var d=document.documentElement; if (!d.clientHeight) d=document.body;
	return d.clientHeight - 44 + d.scrollTop;
}

function BB_writeMenuStyles() {	//some CSS tweaks to get the menus to work in IE
	var d=document;
	//IE5.5+/Win - this is more specific than the NS4 version:
	d.writeln('<!--[if gte IE 5.5]>');
	d.writeln('<!--[if lt IE 7]>');
	d.writeln('<style type="text/css">');
	d.writeln("div.navM { top: expression( BB_getMenuTopPos()+'px' ); }");
	d.writeln(".menus div { padding-bottom: 0px}");
	d.writeln(".menus div.menua { margin-left: 1px}");
	d.writeln(".menus a { margin: 0px 1px; border-top: 1px solid #000033; border-left: none; border-right: none}");
	d.writeln("a.sub { background-image:  url(/mimg/mra_ie.gif);}");
	d.writeln(".menus .menua a { border-top-color: #222255}");
	d.writeln(".menus .menub a { border-top-color: #444477}");
	d.writeln(".menus a:hover, .menus a.mactive { margin: 0px; }");
	d.writeln('</style>');
	d.writeln('<![endif]--><![endif]-->');
}

function toggle2() {	// toggle pairs of elements
	var a=toggle2.arguments,d=document,o,p,i; for(i=0;i<a.length;i+=2) {
		o=getElem(a[i]); p=getElem(a[i+1]); if (o!=null && p!=null) {
			if(RegExp(/\btoggleOn\b/).test(o.className)) toggleOffOn(o,p);
			else toggleOffOn(p,o);
		}
	}
}
function toggleOffOn(o,p) {
	o.className=o.className.replace(/toggleOn\b/,"toggleOff");
	p.className=p.className.replace(/toggleOff\b/,"toggleOn");
}

function BB_swapIcon(i) { BB_swapImageM(0,'icon'+i,'/mimg/cebg_icons_'+i+'_1.gif');showIconTxt(i);fadeIn('iconTxt'); }
function BB_iconRst() { BB_swapImgRestoreM(0); dHide('iconTxt'); }
function showIconTxt(i) { var o=getElem('iconTxt');o.firstChild.nodeValue=iconTxts[i]; }

function chkOp(o, br) {	// br=browser type 1...4
  if (br==1) return (o.style.opacity != null);
	else if (br==2) return (o.style.MozOpacity != null);
	else if (br==3) return (o.filters != null);
	else if (br==4) return (o.style.KhtmlOpacity != null)
}

function setOp(o, op) {	// returns true on error
	if (chkOp(o,2)) o.style.MozOpacity = Math.min(op,.999);	// Mozilla bug
  else if (chkOp(o,1)) o.style.opacity = op;
	else if (chkOp(o,4)) o.style.KhtmlOpacity = op;
	else if (chkOp(o,3)) { if(o.filters.alpha != null) o.filters.alpha.opacity = op*100; }
	else { return true }
	o.iOp = op; return false;
}

function changeOp(s, dOp) {
	var o=getElem(s), b=false, c=true, tmpOp; if(typeof(o.iOp)=='undefined') o.iOp=.1;
	tmpOp = o.iOp+dOp;
	if (tmpOp>=1. && dOp>0) {tmpOp=1.; b=true; }
	if (tmpOp<.1 && dOp<0) {tmpOp=.1; b=true; } 
	c=setOp(o, tmpOp); if (b || c) { BB_clearInt(o); if(dOp<0) BB_setVis(o,false); }
}

function BB_clearInt(o) { if (o.fadeID) { window.clearInterval(o.fadeID); o.fadeID=0; } }
function getElem(s) { return document.getElementById(s); }
function fadeIn(s) { var o=getElem(s); BB_setVis(o,true); startFade(s,dOp); }
function fadeOut(s) { startFade(s,-dOp); }
function startFade(s,d) { var o=getElem(s); if(o!=null) { BB_clearInt(o);
	o.fadeID=window.setInterval("changeOp('"+s+"',"+d+")",dtOp); } }
function dHide(s) { var o=getElem(s); if(o!=null) { BB_clearInt(o); o.fadeID=window.setInterval("fadeOut('"+s+"')",4*dtOp); } }

