function prepareLabel (str, maxLength, boldText) {

	//handle the optional value: boldText
	
	if (!boldText) {
		var boldText = false;
	}

	var checkStr = new String(str);
	var subStrArray = checkStr.match(/\s*\S*/g);

	var output ="";
	var lineLength = 0;
	var lineCount = 1;
	
	//Build the final string according to the rules
	
	for ( var i = 0 ; i < subStrArray.length ; i++ ) {

		//get length of this string
		result = checkStrLength ( subStrArray[i], boldText );
		
		//would the string be too long if we added that part?
		
		if ( ( result.length + lineLength) > maxLength ) {
			//error: word is too long for a line !
			if (lineLength == 0) {
				alert ('ERROR!');
				return null;
			}
			//add a line break
			output += '<br>&nbsp;<img src="images/blind.gif" width="11" height="3" border="0">&nbsp;';
			//strip the leading space from the new word before it is added
			output += result.str.replace(/^\s*/, '');
			//set lineLength to 0
			lineLength = 0;
			//we started a new line
			lineCount ++;
		}
		else {
			//add the word to the line
			output += result.str;
			lineLength += result.length;
		}
	}
	var returnValue = new Object();
	returnValue.str = output;
	returnValue.lines = lineCount;
	return returnValue;
}

//var val = prepareLabel ("This is a test of the capabilities of the system get lost you unbelievers", 150);
//alert (":"+val.str+":"+val.lines)

function checkStrLength (str, boldText) {
	var returnValue = new Object;
	var checkStr = new String (str);

//Arial 22 1280x1024; pixels width measured with screen ruler:

	var strLns = 0;
	var lenArray;
		
	lenArray = checkStr.match(/[I]/g) //7
	if (lenArray) strLns += lenArray.length * 7;
	lenArray = checkStr.match(/[J]/g) //14
	if (lenArray) strLns +=lenArray.length * 14;
	lenArray = checkStr.match(/[A-FHKLNPR-TUVX-Z]/g) //21
	if (lenArray) strLns +=lenArray.length * 21;
	lenArray = checkStr.match(/[GMQ]/g) //23
	if (lenArray) strLns +=lenArray.length * 23;
	lenArray = checkStr.match(/[W]/g) //30
	if (lenArray) strLns +=lenArray.length * 30;
	lenArray = checkStr.match(/[ijl]/g) //7
	if (lenArray) strLns +=lenArray.length * 7;
	lenArray = checkStr.match(/[ft]/g) //11
	if (lenArray) strLns +=lenArray.length * 11;
	lenArray = checkStr.match(/[a-eghkn-qsuvx-z]/g) //16
	if (lenArray) strLns +=lenArray.length * 16;
	lenArray = checkStr.match(/[w]/g) //23
	if (lenArray) strLns +=lenArray.length * 23;
	lenArray = checkStr.match(/[m]/g) //25
	if (lenArray) strLns +=lenArray.length * 25;
	lenArray = checkStr.match(/[0-9]/g) //15
	if (lenArray) strLns +=lenArray.length * 15;
	lenArray = checkStr.match(/[\!]/g) //6
	if (lenArray) strLns +=lenArray.length * 6;
	lenArray = checkStr.match(/[\&]/g) //17
	if (lenArray) strLns +=lenArray.length * 17;
	lenArray = checkStr.match(/[\s]/g) //10
	if (lenArray) strLns +=lenArray.length * 17;

	// adapt for screen output
	
//Arial 10

	var realLns = strLns * testStringLength / 241 //Investor Relations

//bold?

	if (boldText) {
		realLns *= (355 / 332) //<b>Investor Relations</b>/Investor Relations
	}
	
	returnValue.length = realLns;
	returnValue.lines = 1;
	returnValue.str = checkStr;
	return returnValue;
}

var itemHeight = new Array (0,15, 30, 42);
var subItemHeight = new Array (0,14, 30, 42);

function getSubMenuWidth (subMenuStrings) {
	var maxLength	= 0;
	var result;
	var checkStr = new String (subMenuStrings)
	var itemsArray = checkStr.split(';');
	for ( var i = 0; i < itemsArray.length; i++ ) {
		result = checkStrLength(itemsArray[i]);
		if (result.length > maxLength) {
			maxLength=Math.floor(result.length);
		}
	}
//	return (maxLength*1.2 + 15);
	//11 px spacer on each side
	return (maxLength+22);
}

/******************************************
Menu item creation:
myCoolMenu.makeMenu(name, parent_name, text, link, target, width, height, regImage, overImage, regClass, overClass , align, rows, nolink, onclick, onmouseover, onmouseout) 
*************************************/

var menuHeight=0;
var arrow_main_adapt = '<img src="http://www.holcim.com/common/images/arrow_grey.gif" border="0" align="top">';
var src_arrow = '';
var src_arrowB = '';
var arrow_main_white = '<img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="top">';

function adaptGnmToColor(gnCol){
switch (gnCol) {
	case 20: arrow_main_adapt='<div style="position:absolute; LEFT: 4px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 2px; HEIGHT: 12px"><div id="imgMenuA20" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; visibility: visible"><img src="http://www.holcim.com/common/images/arrow_green_trans.gif" border="0" align="middle"></div><div id="imgMenuB20" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; VISIBILITY: hidden"><img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="middle"></div></div>';break;
	case 30: arrow_main_adapt='<div style="position:absolute; LEFT: 4px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 2px; HEIGHT: 12px"><div id="imgMenuA30" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; visibility: visible"><img  src="http://www.holcim.com/common/images/arrow_azul_trans.gif" border="0" align="middle"></div><div id="imgMenuB30" style="position: absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; VISIBILITY: hidden"><img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="middle"></div></div>';break;
	case 40 : arrow_main_adapt='<div style="position:absolute; LEFT: 4px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 2px; HEIGHT: 12px"><div id="imgMenuA40" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; visibility: visible"><img  src="http://www.holcim.com/common/images/arrow_blue_trans.gif" border="0" align="middle"></div><div id="imgMenuB40" style="position: absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; VISIBILITY: hidden"><img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="middle"></div></div>';break;
	case 10: arrow_main_adapt='<div style="position:absolute; LEFT: 4px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 2px; HEIGHT: 12px"><div id="imgMenuA10" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; visibility: visible"><img  src="http://www.holcim.com/common/images/arrow_olive_trans.gif" border="0" align="middle"></div><div id="imgMenuB10" style="position: absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; VISIBILITY: hidden"><img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="middle"></div></div>';break;
	case 0: arrow_main_adapt='<div style="position:absolute; LEFT: 4px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 2px; HEIGHT: 12px"><div id="imgMenuA0" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; visibility: visible"><img  src="http://www.holcim.com/common/images/arrow_orange_trans.gif" border="0" align="middle"></div><div id="imgMenuB0" style="position: absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; VISIBILITY: hidden"><img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="middle"></div></div>';break;
	case 50: arrow_main_adapt='<div style="position:absolute; LEFT: 4px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 2px; HEIGHT: 12px"><div id="imgMenuA50" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; visibility: visible"><img  src="http://www.holcim.com/common/images/arrow_violet_trans.gif" border="0" align="middle"></div><div id="imgMenuB50" style="position: absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; VISIBILITY: hidden"><img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="middle"></div></div>';break;
	default: '<div style="position:absolute; LEFT: 4px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 2px; HEIGHT: 12px"><div id="imgMenuA0" style="position:absolute; LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; visibility: visible"><img src="http://www.holcim.com/common/images/arrow_grey.gif" border="0" align="top"></div><div id="imgMenuB0" style="position: absolute;LEFT: 0px; WIDTH: 11px; CLIP: rect(0px 11px 12px 0px); TOP: 0px; HEIGHT: 12px; VISIBILITY: hidden"><img src="http://www.holcim.com/common/images/arrow_white_trans.gif" border="0" align="middle"></div></div>';
}
}

/*function adaptArrowB(ni){
switch (ni) {
	case 20: src_arrowB = "http://www.holcim.com/common/images/arrow_green_trans.gif";break;
	case 30: src_arrowB = "http://www.holcim.com/common/images/arrow_azul_trans.gif";break;
	case 40 :src_arrowB = "http://www.holcim.com/common/images/arrow_blue_trans.gif";break;
	case 10: src_arrowB = "http://www.holcim.com/common/images/arrow_olive_trans.gif";break;
	case 0: src_arrowB = "http://www.holcim.com/common/images/arrow_orange_trans.gif";break;
	case 50: src_arrowB = "http://www.holcim.com/common/images/arrow_violet_trans.gif";break;
	default: "http://www.holcim.com/common/images/arrow_grey.gif";
}
}

function adaptArrow(ni){
switch (ni) {
	case 20: src_arrow = "http://www.holcim.com/common/images/arrow_white_trans.gif";break;
	case 30: src_arrow = "http://www.holcim.com/common/images/arrow_white_trans.gif";break;
	case 40 :src_arrow = "http://www.holcim.com/common/images/arrow_white_trans.gif";break;
	case 10: src_arrow = "http://www.holcim.com/common/images/arrow_white_trans.gif";break;
	case 0: src_arrow = "http://www.holcim.com/common/images/arrow_white_trans.gif";break;
	case 50: src_arrow = "http://www.holcim.com/common/images/arrow_white_trans.gif";break;
	default: "http://www.holcim.com/common/images/arrow_trans_white.gif";
}
}*/

function change_picA(i){
	//adaptArrowB(i);
	//document.images['imgMenu'+i].src = src_arrowB;	
	document.getElementById('imgMenuA'+i).style.visibility = "visible";
	document.getElementById('imgMenuB'+i).style.visibility = "hidden";
}

function change_picB(i){
	//adaptArrow(i)
	//alert(i + " ; " + src_arrow);
	//document.images['imgMenu'+i].src = "http://www.holcim.com/common/images/arrow_white_trans.gif";
	document.getElementById('imgMenuA'+i).style.visibility = "hidden";
	document.getElementById('imgMenuB'+i).style.visibility = "visible";
}


function wrapper_menuTopItem (name, label, url, menuactive, gnCol) {
	var bld;
	var ebld;
	var cl1;
	var cl2;
	if (menuactive) {
		//cl1 = 'clLevelselected';
		//cl2 = 'clLevelselected';
		cl1 = 'clLevel';
		//cl2 = 'clLevel'; //uncomment to have no mouseover on the expanded title
		cl2 = 'clLevelover';
		bld = "<b>";
		ebld = "</b>";
	}
	else {
		cl1 = 'clLevel';
		cl2 = 'clLevelover';
		bld = "";
		ebld = "";
	}
	adaptGnmToColor(gnCol);
	var lab = prepareLabel (label, 150, menuactive);
	var imgTest = "imgMenu";
	
	//if (menuactive) {
	//	oCMenu.makeMenu(name,'',bld+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+arrow_main_adapt+'&nbsp;'+lab.str+ebld,url,'','',itemHeight[lab.lines], '', '', cl1+gnCol, cl2+gnCol)
	//}else{
		oCMenu.makeMenu(name,'',bld+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+arrow_main_adapt+'&nbsp;'+lab.str+ebld,url,'','',itemHeight[lab.lines], '', '', cl1+gnCol, cl2+gnCol,'','','','',"change_picB("+ gnCol +")","change_picA("+ gnCol +")")
	//}
	menuHeight += itemHeight[lab.lines];
}

function wrapper_menuSubItem (name, father, label, url, menuactive, width, gnCol, currentP) {
	if (menuactive) {
		var lab = prepareLabel (label , 150);
		if (currentP){
			oCMenu.makeMenu(name,'','&nbsp;'+spacer_main+'&nbsp;'+lab.str,url,'','',subItemHeight[lab.lines], '', '', 'clLevel05over'+gnCol, 'clLevel05over'+gnCol)
		}else{
			oCMenu.makeMenu(name,'','&nbsp;'+spacer_main+'&nbsp;'+lab.str,url,'','',subItemHeight[lab.lines], '', '', 'clLevel05'+gnCol, 'clLevel05over'+gnCol)
		}
		menuHeight += subItemHeight[lab.lines];
	}
	else {
		oCMenu.makeMenu(name,father,spacer_sub+label,url,'',width,'','','','clLevelb'+gnCol, 'clLevelbover'+gnCol)
	}
}

function wrapper_menuDummyItem (name, father, menuactive, width,gnCol) {
	if (menuactive) {
		oCMenu.makeMenu(name,'','','', '','', dummyHeight, '', '', '', '', '', '', true)
		menuHeight += dummyHeight;
	}
	else {
		oCMenu.makeMenu(name,father,'','', '',width, dummyHeight, '', '', 'clLevelb'+gnCol, 'clLevelbover'+gnCol, '', '', true)
	}
}

function wrapper_menuTopDummyItem (name) {
	oCMenu.makeMenu(name,'','','', '','', dummyHeight, '', '', '', '', '', '', true)
	menuHeight += dummyHeight;
}