var shiftX = 0;

var droppeditem = "";

var ROOT = "";

var PAGEWIDTH = 800;

//array items: no., width, page name-stub, menu items

var dropdowns = new Array( 

	"1",163, "services", new Array(

		"Overview","/pages/serv-overview.html",

		"Rural Communications","/pages/serv-rural.html",

		"Emerging Markets", "/pages/serv-emerging.html",

		"National ICT Strategy","/pages/serv-ict-strategy.html",

		"Satellite and Wireless", "/pages/serv-satellite.html",

		"Market Demand", "/pages/serv-market.html",

		"Universal Service/Access", "/pages/serv-universal.html",

		"Privatisation", "/pages/serv-privatise.html",

		"Due Diligence and Ventures","/pages/serv-diligence.html"

		),

	"2",85, "projects", new Array(

		"Projects by Category","/pages/projpcat.html",

		"Projects by Client-type", "/pages/projcli.html",

		"Projects by Continent","/pages/projcont.html"

		),

	"3",182, "reports", new Array(

		"Reports","/pages/reports.html",

		"Presentations","/pages/presentations.html"

		)/*, 

	"4",182, "news", new Array(

		"Industry News","#industry",

		"Regulatory News","#regulatory"

		) */

	);

	

CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);

function IsIE() { return CSAg.indexOf("MSIE") > 0;}

CSIsW3CDOM = ((document.getElementById) && !(IsIE()&&CSBVers<6)) ? true : false;



function CSIEStyl(s) { return document.all.tags("div")[s].style; }

function CSNSStyl(s) { if (CSIsW3CDOM) return document.getElementById(s).style; else return CSFindElement(s,0);  }

CSIImg=false;

function CSInitImgID() {if (!CSIImg && document.images) { for (var i=0; i<document.images.length; i++) { if (!document.images[i].id) document.images[i].id=document.images[i].name; } CSIImg = true;}}

function CSFindElement(n,ly) { if (CSBVers<4) return document[n];

	if (CSIsW3CDOM) {CSInitImgID();return(document.getElementById(n));}

	var curDoc = ly?ly.document:document; var elem = curDoc[n];

	if (!elem) {for (var i=0;i<curDoc.layers.length;i++) {elem=CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}

	return elem;

}

function CSGetImage(n) {if(document.images) {return ((!IsIE()&&CSBVers<5)?CSFindElement(n,0):document.images[n]);} else {return null;}}

CSDInit=false;

function CSIDOM() { if (CSDInit)return; CSDInit=true; if(document.getElementsByTagName) {var n = document.getElementsByTagName('DIV'); for (var i=0;i<n.length;i++) {CSICSS2Prop(n[i].id);}}}

function CSICSS2Prop(id) { var n = document.getElementsByTagName('STYLE');for (var i=0;i<n.length;i++) { var cn = n[i].childNodes; for (var j=0;j<cn.length;j++) { CSSetCSS2Props(CSFetchStyle(cn[j].data, id),id); }}}

function CSFetchStyle(sc, id) {

	var s=sc; while(s.indexOf("#")!=-1) { s=s.substring(s.indexOf("#")+1,sc.length); if (s.substring(0,s.indexOf("{")).toUpperCase().indexOf(id.toUpperCase())!=-1) return(s.substring(s.indexOf("{")+1,s.indexOf("}")));}

	return "";

}

function CSGetStyleAttrValue (si, id) {

	var s=si.toUpperCase();

	var myID=id.toUpperCase()+":";

	var id1=s.indexOf(myID);

	if (id1==-1) return "";

	s=s.substring(id1+myID.length+1,si.length);

	var id2=s.indexOf(";");

	return ((id2==-1)?s:s.substring(0,id2));

}

function CSSetCSS2Props(si, id) {

	var el=document.getElementById(id);

	if (el==null) return;

	var style=document.getElementById(id).style;

	if (style) {

		if (style.left=="") style.left=CSGetStyleAttrValue(si,"left");

		if (style.top=="") style.top=CSGetStyleAttrValue(si,"top");

		if (style.width=="") style.width=CSGetStyleAttrValue(si,"width");

		if (style.height=="") style.height=CSGetStyleAttrValue(si,"height");

		if (style.visibility=="") style.visibility=CSGetStyleAttrValue(si,"visibility");

		if (style.zIndex=="") style.zIndex=CSGetStyleAttrValue(si,"z-index");

	}

}



function CSRect (left,top,width,height) {

	this.left=left; this.top=top; this.width=width; this.height=height;

}

function CSSetLayerClip (el,clipRect) {

    var l,t,r,b;

    l=clipRect.left; t=clipRect.top; r=l+clipRect.width; b=t+clipRect.height;

    if(el.isIE) { el.style.clip = "rect("+ t + " " + r + " " + b + " " + l + ")"; }

    else if (CSBVers>=5) el.style.clip = "rect("+ t + "px, " + r + "px, " + b + "px, " + l + "px)";

    else { el.clip.left=l; el.clip.top=t; el.clip.width=clipRect.width; el.clip.height=clipRect.height; }

	CSSetStyleVis(el.layer);

}

function CSSetStyleVis(s,v) {

/*	if(!document.getElementById(s)) {
		alert(s + " doesn't exist");
		return;
	}
*/
	if (CSIsW3CDOM){CSIDOM();document.getElementById(s).style.visibility=(v==0)?"hidden":"visible";}

	else if(IsIE())CSIEStyl(s).visibility=(v==0)?"hidden":"visible";

	else CSNSStyl(s).visibility=(v==0)?'hide':'show';

}

function CSShowHide(action) {

	if (action[1] == '') return;

	var type=action[2];

	if(type==0) CSSetStyleVis(action[1],0);

	else if(type==1) CSSetStyleVis(action[1],1);

	else if(type==2) { 

		if (CSGetStyleVis(action[1]) == 0) CSSetStyleVis(action[1],1);

		else CSSetStyleVis(action[1],0);

	}

}

function CSGetStyleVis(s) {

	if (CSIsW3CDOM) {CSIDOM();return(document.getElementById(s).style.visibility=="hidden")?0:1;}

	else if(IsIE())return(CSIEStyl(s).visibility=="hidden")?0:1;

	else return(CSNSStyl(s).visibility=='hide')?0:1;

}

function CSSetStylePos(s,d,p) {

	if (CSIsW3CDOM)d==0?document.getElementById(s).style.left=p+"px":document.getElementById(s).style.top=p+"px";

	else if(IsIE())(d==0)?CSIEStyl(s).posLeft=p:CSIEStyl(s).posTop=p;

	else (d==0)?CSNSStyl(s).left=p:CSNSStyl(s).top=p;

}

userAgent = window.navigator.userAgent;

browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);

mustInitImg = true;

function initImgID() {di = document.images; if (mustInitImg && di) { for (var i=0; i<di.length; i++) { if (!di[i].id) di[i].id=di[i].name; } mustInitImg = false;}}

function findElement(n,ly) {

	d = document;

	if (browserVers < 4)		return d[n];

	if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 

	var cd = ly ? ly.document : d;

	var elem = cd[n];

	if (!elem) {

		for (var i=0;i<cd.layers.length;i++) {

			elem = findElement(n,cd.layers[i]);

			if (elem) return elem;

		}

	}

	return elem;

}

function changeImages() {

	d = document;

	if (d.images) {

		var img;

		for (var i=0; i<changeImages.arguments.length; i+=2) {

			img = null;

			if (d.layers) {img = findElement(changeImages.arguments[i],0);}

			else {img = d.images[changeImages.arguments[i]];}

			if (img) {img.src = changeImages.arguments[i+1];}

		}

	}

}

function windowWidth() {

	return (document.all ? document.body.clientWidth : parseInt(window.innerWidth) );

}

function myMakeLayerEl(layer) {

	var el;

	if (IsIE()) el=document.all.tags("div")[layer];

	else if (CSBVers>=5) el=document.getElementById(layer);

	else el=CSNSStyl(layer);

	el.isIE = IsIE();

	el.layer = layer;

	return el;

}

function objWidth(obj) {

	var w;

	//alert(obj);

	if (CSIsW3CDOM) {

		//alert("CSIsW3CDOM");

		w = document.getElementById(obj).offsetWidth;

	} else if (IsIE()) {

		//alert("IsIE");

		w = document.all[obj].offsetWidth;

	} else {

		//alert("NS4");

		w = document.layers[obj].clip.width; 

	}

	//alert("objWidth = " + w);

	return (parseInt(w));

}



//MAKE POPUP MENU LAYER for layer/div called thismenu

function makemenu(thismenu,thishtml) {

	if (document.all) {

		if(CSAg.indexOf("MSIE 5.0") > 0 && CSAg.indexOf("Mac") > 0) {	

			//bug in IE5.0 for Mac requires the extra space

			document.all(thismenu).innerHTML = thishtml + " ";

		} else {

			document.all(thismenu).innerHTML = thishtml;

		}

	} else if (CSIsW3CDOM) {

		document.getElementById(thismenu).innerHTML = thishtml;

	} else {

		document.layers[thismenu].document.write( thishtml );

		document.layers[thismenu].document.close();

	}

}



var HIDE = 0;

var SHOW = 1;



function doinit() {

	var aDropCount = dropdowns.length;
	
	//if (arguments.length = 0) aDropCount -= 4;	//Only home page has an argument, and it has 4 dropdowns instead of 3
	
	for (var i=0; i<aDropCount;i+=4) {

		CSShowHide(new Array('','menubase' + dropdowns[i],HIDE) ) ;

		CSShowHide(new Array('','menuhi' + dropdowns[i],HIDE) ) ;

		makedropdown(i);

	}

	setTimeout("placedropdowns();",100);	//delay to ensure that shiftX calculated 

}



//construct dropdown menu

function makedropdown(i) {

	var ncols = (document.all || CSIsW3CDOM) ? 2 : 3;	//need bullets column for rollovers if NS4

	var html = "";

	html += "<table border='0' cellspacing='0' cellpadding='0'>" ;

	html += "<tr><td colspan='" + (ncols-1) + "' bgcolor='#336699' align='left'><img src='" 

		+ ROOT + "/art/blue.gif' alt='' width='" + dropdowns[i+1] + "' height='3' border='0'></td></tr>" ; //defines min dropdown width = headwidth

	for (var j=0; j<dropdowns[i+3].length; j= j+2) {

		if (document.all || CSIsW3CDOM) {

			//if possible, change color of table row on rollover

			html += "<tr>" ;

			html += "<td bgcolor='#ffffff'><img src='" + ROOT + "/art/void.gif' alt='' height='1' width='100%' border='0'></td>" ;

			html += "</tr>" ;

			html += "<tr><td bgcolor='#cccc99' onmouseover='this.style.backgroundColor=\"#3399cc\";' " ;

			html += "onmouseout='this.style.backgroundColor=\"#cccc99\";' " ;

			html += "onclick='window.location=\"" + ROOT + dropdowns[i+3][j+1] + "\"; return true;'>" ;

			html += "<a class='popuptype' href='" + ROOT + dropdowns[i+3][j+1] + "'>" + dropdowns[i+3][j] + "</a></td>" ;

			html += "</tr>" ;

		} else {

			//otherwise (NS4) use a bullet

			html += "<tr>" ;

			html += "<td colspan='2' bgcolor='#ffffff'><img src='art/void.gif' alt='' height='1' width='100%' border='0'></td>" ;

			html += "</tr>" ;

			html += "<tr><td bgcolor='#cccc99'><img name='bull" + i + "-" + j + "' src='http://www.ktc-canada.com/nav/bullet-off.gif' width='12' height='10' border='0'></td>" ;

			html += "<td bgcolor='#cccc99'><a class='popuptype' style='margin-left:0px' href='" + ROOT + dropdowns[i+3][j+1] + "' " ;

			html += "onmouseover='changeImages(\"bull" + i + "-" + j + "\",\"http://www.ktc-canada.com/nav/bullet-on.gif\");return true;' " ;

			html += "onmouseout='changeImages(\"bull" + i + "-" + j + "\",\"http://www.ktc-canada.com/nav/bullet-off.gif\");return true;'>" ;

			html += dropdowns[i+3][j] + "</a></td>" ;

			html += "</tr>" ;

		}

	}

	html += "<tr><td colspan='" + ncols + "'><img src='" + ROOT + "/art/popupmenu-foot.gif' alt='' height='3' width='100%' border='0'></td></tr>" ;

	html += "</table>" ;

	makemenu("menupopup" + dropdowns[i],html);

}







//Move dropdown menus so they are left aligned with items in nav bar and make menuhi and appropriate menubase items visible

function placedropdowns() {

	var leftpos = 308 + shiftX;

	var SETLEFT = 0;

	var w;

	for (var i=0; i<dropdowns.length;i+=4) { 

		//Code for right-aligend:

		//w = objWidth('menupopup' + dropdowns[i]);

		//DLSetStyleWidth('menupopup' + dropdowns[i],w);

		//CSSetStylePos('menupopup' + dropdowns[i], SETLEFT, leftpos + dropdowns[i+1] - w);

		CSSetStylePos('menupopup' + dropdowns[i], SETLEFT, leftpos);

		CSSetStylePos('menubase' + dropdowns[i], SETLEFT, leftpos);

		CSSetStylePos('menuhi' + dropdowns[i], SETLEFT, leftpos);

		leftpos += dropdowns[i+1];

		CSShowHide(new Array('','menubase' + dropdowns[i],(dropdowns[i]==ownerdrop ? HIDE : SHOW ) ) ) ;

		CSShowHide(new Array('','menuhi' + dropdowns[i],SHOW) ) ;

	}

}

function DLSetStyleWidth(s,w) {

	if (CSIsW3CDOM)document.getElementById(s).style.width=w+"px";

	else if(IsIE())CSIEStyl(s).width=w;

	else CSNSStyl(s).clip.width=w;

}

function drop(item) {

	if (item == droppeditem) return;

	if (droppeditem != "") {

		CSShowHide(new Array('','menupopup' + droppeditem,HIDE));

		//Show the base item unless we're on a page within that dropdown

		if (droppeditem != ownerdrop) CSShowHide(new Array('','menubase' + droppeditem,SHOW));

	}

	//Hide the base item so the "over" item shows through

	CSShowHide(new Array('','menubase' + item,HIDE));

	CSShowHide(new Array('','menupopup' + item,SHOW));

	//alert("Dropping " + item);

	CSShowHide(new Array('','catcher',SHOW));

	droppeditem = item;

}

function undrop() {

	CSShowHide(new Array('','catcher',HIDE));

	for (var i=0; i<dropdowns.length;i+=4) {

		CSShowHide(new Array('','menupopup' + dropdowns[i],HIDE));

		//Show the base item unless we're on a page within that dropdown

		if (dropdowns[i] != ownerdrop) CSShowHide(new Array('','menubase' + dropdowns[i],SHOW));

	}

	droppeditem = "";

}





