/*
	file: navig.js
	action: manages the dhtml navigation menu
	author: nicolas glinoer - n@walkingmen.com
	date: 03 11 05
*/

navig_Arrays = [
	[
		"navig_Company","navig_Company_child",242,130,
		[
			["What We Do","/company/what.shtml"],
			["Where We Are","/company/where.php"],
			["Our Leadership","/company/leadership.shtml"],
			["Our History","/company/history.shtml"],
			["The Nielsen Code","/company/nielsen.shtml"]
		]
	],
	[
		"navig_Capabilities","navig_Capabilities_child",350,140,
		[
			["By Business Issue","/issues/index.shtml"],
			["By Industry","/industry/index.shtml"],
			["By Product","/products/index.shtml"]
		]
	],
	[
		"navig_Press","navig_Press_child",346,98,[]
	],
	[
		"navig_Events","navig_Events_child",300,150,[]
	],
	[
		"navig_Careers","navig_Careers_child",300,150,[]
	],
	[
		"navig_Research","navig_Research_child",630,170,
		[
			["Publications","/pubs/index.shtml"],
			["Reports and Studies","/reports/index.shtml"]
		]
	]
];
/*  ****************   - DETECTION NAVIGATEUR - REFERENCE OBJET - ***************************** */
function thisbrowser(){ 
	this.NS4=document.layers;
	this.IE4=document.all;
	this.DOM=document.getElementById&&!document.all;
	this.bw=(this.NS4 || this.IE4 || this.DOM);
	return this;
}
var bw=new thisbrowser();
var px = bw.NS4?"":"px";  //"px" needed to position the layer



/* ********************* stylesheet elements for navig menu********************** */
document.writeln('<STYLE type="text/css">');

for(h=0; h<navig_Arrays.length; h++){
	if (document.layers) {
		var menuheighteach = 19; 
		var menufontsize = 13;
		var menufontheight = 14;
		var menuheighttotal = (navig_Arrays[h][4].length) * menuheighteach;
	}
	else {
		var menuheighteach = 17;
		var menufontsize = 11;
		var menufontheight = 12;
		var menuheighttotal = ((navig_Arrays[h][4].length) * menuheighteach) + 10;
	}
	
	document.writeln('#calque' + navig_Arrays[h][0] + ' {position:absolute; left:' + navig_Arrays[h][2] + 'px; ');
	document.write('top:58px; width:' + navig_Arrays[h][3] + 'px; height:' + menuheighttotal + 'px; ');
	document.write('clip:rect(0px,' + navig_Arrays[h][3] + 'px,'+ menuheighttotal + 'px,0px);}');
}

document.writeln('.styleEnfant {position:absolute; left:0px; top:0px; visibility:hidden; }');

document.writeln('.navigmenu-over-orange {font-size: ' + menufontsize + 'px; line-height: ' + menufontheight + 'px; text-decoration: none; ');
document.write('font-family: Arial,Helvetica,sans-serif; color: #ffffff; font-weight: bold; background-color: #e98743; cursor: hand;} ');

document.writeln('.navigmenu-over {font-size: ' + menufontsize + 'px; line-height: ' + menufontheight + 'px; text-decoration: none; ');
document.write('font-family: Arial,Helvetica,sans-serif; color: #ffffff; font-weight: bold; background-color: #3f7ebc; cursor: hand;} ');

document.writeln('.navigmenu-out {font-size: ' + menufontsize + 'px; line-height: ' + menufontheight + 'px; text-decoration: none; ');
document.write('font-family: Arial,Helvetica,sans-serif; color: #ffffff; font-weight: bold; background-color: #004575; cursor: hand;} ');
document.writeln('</STYLE>');



/*  *********************   - INITIALIZE - ******************** */
var calqueTime = bw.NS4?"1500":"500";
window.fullyLoaded = false;

function initialisation(){
	instanceEnfant = new Array();
	for(h=0; h<navig_Arrays.length; h++){
		instanceEnfant[h] = new init(navig_Arrays[h][1],navig_Arrays[h][0]);
		instanceEnfant[h].css.left = 0+px;
		instanceEnfant[h].css.top = 0+px;
		instanceEnfant[h].css.visibility = "hidden";
	}
}

function init(enfant,parent) {
	//alert(parent + "." + enfant)
	if (bw.NS4) {
		//alert("bw.NS4");//pc ns4
		this.css=!enfant ? document.layers[parent] : document.layers[parent].document.layers[enfant];
		this.ref=!enfant ? document.layers[parent].document : document.layers[parent].document.layers[enfant].document;
	  }
	else if (bw.IE4) {
		//alert("bw.IE4");//pc ie 6

		this.css=!enfant ? document.all[parent].style : document.all[enfant].style;
		this.ref=!enfant ? document.all[parent] : document.all[enfant]; 
	  }
	else if (bw.DOM) {
		//alert("bw.DOM");//pc ns6, ns7
		this.css=!enfant ? document.getElementById(parent).style : document.getElementById(enfant).style;
		this.ref=!enfant ? document.getElementById(parent) : document.getElementById(enfant); 
	  }
	 else{
		//alert("else");
	}
	  
	this.css.xpos = parseInt(this.css.left);  // Needed to position the layer
	this.css.ypos = parseInt(this.css.top);
	this.hauteur=bw.NS4?this.css.document.height:this.ref.offsetHeight;
	this.positionEnHaut=F_positionEnHaut;
	return this;
}

//Top position setup
function F_positionEnHaut(){
	var gleft=(bw.NS4 || bw.DOM)?parseInt(this.css.top):eval(this.css.pixelTop);
	return gleft;
}


/*  ********************  - display/hide the layer - ************************** */
var timerOk = true;
function start_timer(){
	if(window.fullyLoaded){
		stop_timer();
		timerOk = setTimeout("hide()",calqueTime);
	}
}
function stop_timer(){	clearTimeout(timerOk); }

function show(which){
	if(window.fullyLoaded){
		hide();
		stop_timer();
		instanceEnfant[which].css.visibility = "visible";
	}
}
function hide(){
	if(window.fullyLoaded){
		stop_timer();
		for(h=0; h<navig_Arrays.length; h++){
			instanceEnfant[h].css.visibility = "hidden";
		}
	}
}



/* ********************* generate the navig menu *********************** */
function generateMenu(){
	for(h=0; h<navig_Arrays.length; h++){
		cellContentNS = new Array();
		//open external elements
		//alert(navig_Arrays[h][1])
		document.write('<DIV ID="calque' + navig_Arrays[h][0] + '"><DIV ID="' + navig_Arrays[h][1] + '" CLASS="calque' + navig_Arrays[h][1] + '" onMouseOver="if(window.fullyLoaded){show(' + h + ');}" onMouseOut="if(window.fullyLoaded){start_timer();}">');
		document.write('<TABLE cellspacing="0" cellpadding="0" border="0" bgcolor="#004575"><tr bgcolor="#004575"><td bgcolor="#004575"><TABLE cellspacing="1" cellpadding="0" border="0">');
	
		//loop into the different menu elements
		for (var i=0; i<navig_Arrays[h][4].length; i++){
			var thisCell = navig_Arrays[h][1] + "_Cell_" + i;
	
		//fix the links in case it's a javascript call
			if(navig_Arrays[h][4][i][1].indexOf("javascript:") == -1) { onClickString = 'onClick="self.location=(\'' + navig_Arrays[h][4][i][1] + '\');"' }
			else if(navig_Arrays[h][4][i][1] == "#") { onClickString = 'onClick="self.location=self.location;"' }
			else { onClickString = 'onClick="' + navig_Arrays[h][4][i][1].replace("javascript:","") + '"'; }
		//add some space at the beginning of the text
			navig_Arrays[h][4][i][0] = '&nbsp;&nbsp;&nbsp;' + navig_Arrays[h][4][i][0];
	
		//prepare rollover content for NS
			cellContentNS["NS" + thisCell] = '<a href="' + navig_Arrays[h][4][i][1] + '" class=\'navigmenu\'>&nbsp;&nbsp;&nbsp;&nbsp;' + navig_Arrays[h][4][i][0] + '</a>';	
	
		//begin TD
			document.write('<TR height=' + menuheighteach + '><TD ');
			if (document.layers){ document.write(' nowrap valign="middle" id="' + thisCell); }
			else { document.write('height=' + menuheighteach + ' nowrap valign="middle" id="' + thisCell); }
			document.write('" class="navigmenu-out" width=' + eval(navig_Arrays[h][3] - 2));
			if (h!=5){ document.write(' onMouseOver="this.className=\'navigmenu-over\'; show(' + h + ');"'); }
			if (h==5){ document.write(' onMouseOver="this.className=\'navigmenu-over-orange\'; show(' + h + ');"'); }
			document.write(' onMouseOut="this.className=\'navigmenu-out\'; start_timer();" ');
			document.write(onClickString + '>');
	
			if (document.layers){
		//begin LAYER
				document.write('<ILAYER id="NS' + thisCell +'"><LAYER width="' + eval(navig_Arrays[h][3] - 2));
				if (h!=5) { document.write('" onMouseOver="this.bgColor=\'#3f7ebc\'; rolloverTableCell(\'' + i + '\',\'' + thisCell + '\',\'navigmenu-over\'); show(' + h + ');"');	}
				if (h==5) {	document.write('" onMouseOver="this.bgColor=\'#e98743\'; rolloverTableCell(\'' + i + '\',\'' + thisCell + '\',\'navigmenu-over-orange\'); show(' + h + ');"'); }
				document.write('  onMouseOut="this.bgColor=\'#ffffff\';  rolloverTableCell(\'' + i + '\',\'' + thisCell + '\',\'navigmenu-out\');  start_timer();" ');
				document.write(onClickString);
				document.write('>');
			}
	
		//begin LINK and TEXT
			document.write(navig_Arrays[h][4][i][0]);
	
			if (document.layers){
				document.write('</LAYER></ILAYER>');
			}
		//close TD
			document.write('</TD></TR>');
		}
		//close external elements
		document.write('</TABLE></td></tr></TABLE></DIV></DIV>');
	}
}

/* ********************* manipulate the navig menu *********************** */
function getCell(id) { 
	if (document.all) return document.all(id);
	if (document.getElementById) return document.getElementById(id);
	if (document.layers) {
		return document.layers['calqueParent_company'].document.layers['calqueEnfant'].document['NS' + id].document.layers[0];
	}
	null; 
} 

function rolloverTableCell(refid,id,classname) { 
	if (document.layers){
		var itemID = getCell(id); 
		if (!itemID){ return; }
		var itemWitdh = itemID.clip.width; 
		var itemHeight = itemID.clip.height; 
		if (classname) { var sSPAN = '<span class="' + classname + '">' }
		else { var sSPAN = '<span>';  }
		itemID.document.write(sSPAN + navig_Company_Array[refid][0] + '</span>'); 
	
		itemID.document.close(); 
		itemID.parentLayer.clip.width  = itemID.clip.width  = itemWitdh; 
		itemID.parentLayer.clip.height = itemID.clip.height = itemHeight; 
		itemID.captureEvents(Event.MOUSEUP);
		top.currentRef = refid;
		top.currentID = id;
		itemID.onmouseup = clic;
	}
} 

function clic(){
	//NS only: fix the links in case it's a javascript call
	if(navig_Company_Array[top.currentRef][1].indexOf("javascript:") == -1) {
		self.location = navig_Company_Array[top.currentRef][1]
	}
	else {
		eval(navig_Company_Array[top.currentRef][1].replace("javascript:",""));
	}
}

// This function is used everywhere to email friend an article
// example: <a href="javascript:e_friend();" class="path1res">Email a Friend</a>

function e_friend(){

    oWinRpt = open("/scripts/EmailArticle.php?article=" + document.location.href + "&title=" + escape(document.title)  ,"","directories=no,copyhistory=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0,height=400,width=400");

}

function e_requestInfo(){

    oWinRpt = open("/scripts/ReqInfo.php?article=" + document.location.href + "&title=" + escape(document.title)  ,"","directories=no,copyhistory=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0,height=540,width=740");

}
function e_subscribe(){

    oWinRpt = open("/scripts/subscribe.php?article=" + document.location.href + "&title=" + escape(document.title)  ,"","directories=no,copyhistory=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0,height=400,width=400");

}
function e_purchaseReport(){

    oWinRpt = open("/scripts/purchaseReport.php?article=" + document.location.href + "&title=" + escape(document.title)  ,"","directories=no,copyhistory=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0,height=400,width=400");

}
generateMenu();
window.fullyLoaded=true; 
initialisation();
