
var leftMargin=25;

var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;

function switchid(id, gm){
	if ( !gm ) {
		gm=getGM( id );
		}

	hideallids();
	showdiv(id);

	if ( document.getElementById(gm) ) {
		var p=findPos( document.getElementById(gm) );
		var p0=findPos( document.getElementById( ids[0] ) );
		var ph=findPos( document.getElementById( "head" ) );

		var l1=getElementWidth( gm );
		var l2=getMenuWidth( id );
		var l3=getElementWidth( id );

//		var pos=(p[0]-leftMargin-1)+(l1/2)-(l2/2);
		pos=(p[0]-ph[0])+(l1/2)-(l2/2)-5;

		if ( pos+l2>l3 ) pos=l3-l2-leftMargin;
		if ( pos < 0 ) pos=0;
		document.getElementById( id ).style.paddingLeft=pos+"px";
		}
	}

function getGM( id ) {
	
	for (var i=0;i<ids.length;i++) {
		if ( ids[i]==id ) return "m"+i;
		}

	return 0;
	}

function getMenuWidth( id ) {
	var w=0;

	for ( var i=1; i<=25; i++ ) {
		if ( !document.getElementById( id+"_"+i ) ) return w;

		w+= getElementWidth( id+"_"+i );
		}

	return w;
	}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++) {
		hidediv(ids[i]);
		document.getElementById( ids[i] ).style.paddingLeft="0px";
		}
	}

function getElementHeight(Elem) {
	if (NS4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if ( elem.style.pixelHeight ) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (NS4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (elem.style.pixelWidth) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
	}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		if ( !document.getElementById(id) ) return;
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) { 
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		if ( !document.getElementById(id) ) return;
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


