// Browser detection variables
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_dom = 0;
var is_ie = 0;		// IE 4 and up
var is_ie5up = 0;	// IE 5 and up
var is_moz = 0;
var scrollxfix = 0;	// Fixups for viewable region
var scrollyfix = 0;
var bload_x = 0;	// Image preload location
var bload_y = 0;
var BrowserOK = 0;	// Browser unknown
var layerOK = 1;
var menuOK = 1;
var imageOK = 1;

// Needed for the search function
window.name = "toplevel";
searchwidth = 260;

// Drop-down menu information
tban_height = 84-2;	// Top banner height (less adjust)
tban_topr = 280;	// Top banner right image width
top_width = 61;		// Width of a menu button
top_space = 5;		// Width between menu buttons
top_height = 19+2;	// Height of menu buttons (plus adjust)
menu_width = 102;	// Width of a drop-down menu (10+82+10)
menu_off_x = 20;	// Menu offset to left of menu button
menu_top = 15;		// Height of top drop-down cell
menu_cell = 20;		// Height of one menu item unit
menu_end = 30;		// Height of the end of a drop-down menu

minwide = 620;		// Minimum width;
			// Minimum height (6 menu items + 20 slop)
minhigh = tban_height + top_height + menu_top +
	6*menu_cell + menu_end + 20;

// Set to 1 to add 'White Papers' to news menu
whitep_on = 1;

// Browser dependent strings for referencing documents
var doc_ref = "";
var style_ref = "";
var end_ref = "";
var hreftag = "";

// Used for image swapping in a layer
var target = "";
var preloadtgt = "";

// Arrays used to store information about drop-down menus
var dd_texts = new Array();
var dd_ys = new Array();
var dd_content = new Array();

// Variables used for menu sizing and placement
var page_width = 0;
var page_height = 0;
var view_width = -1;
var view_height = -1;
var old_vw = 0;
var old_vh = 0;
var menu_on = 0;
var loaded = 0;

// -------------- End of control variables --------------

// Check browser validity
// Gecko engine - Netscape 6, Mozilla
if (agt.indexOf('gecko') != -1) {
	is_dom = 1;
	doc_ref = "document.getElementById(";
	style_ref = ").style";
	end_ref = ")";
	scrollxfix = 16;
	scrollyfix = 16;
	searchwidth += 20;
	}

// Internet Explorer 4+ - forbids Opera
else if ((agt.indexOf("msie") != -1) &&
		(agt.indexOf("opera") == -1)) {
	if (is_major >= 4) {
		is_ie = 1;
		if ((is_major == 4) && (agt.indexOf("msie 4")==-1))
			is_ie5up = 1;
		else	imageOK = 0;
		doc_ref = "document.all(";
		style_ref = ").style";
		end_ref = ")";
		}
	}

// Netscape Navigator 4+ - forbids Opera,
// WebTV, HotJava and other spoofers
else if ((agt.indexOf('mozilla')!=-1)
		&& (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible') == -1)
		&& (agt.indexOf('opera')==-1)
		&& (agt.indexOf('webtv')==-1)
		&& (agt.indexOf('hotjava')==-1) ) {
	if (is_major >= 4) {
		is_moz = 1;
		hreftag = ' HREF="#"';
		doc_ref = "document.layers[";
		style_ref = "]";
		end_ref = "]";
		scrollxfix = 16;
		scrollyfix = 16;
		searchwidth += 20;
		}
	}

BrowserOK = is_dom | is_ie | is_moz;

if (BrowserOK) {
	window.onerror = null;
	window.status = "";
	}
else {
	menuOK = 0;
	layerOK = 0;
	imageOK = 0;
	}

// -------------- Start of content variables --------------

KD_menus = new Array('ddmenu1','ddmenu2','ddmenu3','ddmenu4','ddmenu5');
KD_mname = new Array('menu1','menu2','menu3','menu4','menu5');

// HTML strings for drop-down menu layer
ddmtbl = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR>';
ddmtdw = '<TD WIDTH=';
ddmh = ' HEIGHT=';
ddmimgw = '<IMG WIDTH=';
ddmimge = ' BORDER=0 SRC="images/kd_empty.gif"></A></TD>';
ddmrend = '</TD></TR>';
ddmtend = '</TR></TABLE>';
ddmoff = '><A' + hreftag + ' onMouseOver="return(ALL_off());">';
ddmA1 = '><A onMouseOver="return(KD_ws(\'';
ddmA2 = '\'));" onMouseOut="return(KD_ws(\'\'));">';

// HTML template for drop-down menu
dd_html = new Array();
dd_html[0] = '<TABLE WIDTH=102 BORDER=0 CELLSPACING=0 CELLPADDING=0>';
dd_html[0] += '<TR><TD WIDTH=10 HEIGHT=' + menu_top + '>';
dd_html[0] += '<IMG WIDTH=10 HEIGHT=' + menu_top;
dd_html[0] += ' BORDER=0 SRC="images/kd_d2tol.gif"></TD>';
dd_html[0] += '<TD WIDTH=82 HEIGHT=' + menu_top + '>';
dd_html[0] += '<IMG WIDTH=82 HEIGHT=' + menu_top;
dd_html[0] += ' BORDER=0 SRC="images/kd_d2top.gif"></TD>';
dd_html[0] += '<TD WIDTH=10 HEIGHT=' + menu_top + '>';
dd_html[0] += '<IMG WIDTH=10 HEIGHT=' + menu_top;
dd_html[0] += ' BORDER=0 SRC="images/kd_d2tor.gif"></TD></TR>';

dd_html[1] = '<TR><TD WIDTH=10 HEIGHT=' + menu_end + '>';
dd_html[1] += '<IMG WIDTH=10 HEIGHT=' + menu_end;
dd_html[1] += ' BORDER=0 SRC="images/kd_d2bol.gif"></TD>';
dd_html[1] += '<TD WIDTH=82 HEIGHT=' + menu_end + '>';
dd_html[1] += '<IMG WIDTH=82 HEIGHT=' + menu_end;
dd_html[1] += ' BORDER=0 SRC="images/kd_d2bom.gif"></TD>';
dd_html[1] += '<TD WIDTH=10 HEIGHT=' + menu_end + '>';
dd_html[1] += '<IMG WIDTH=10 HEIGHT=' + menu_end;
dd_html[1] += ' BORDER=0 SRC="images/kd_d2bor.gif"></TD></TR></TABLE>';

cell_left   = '<TR><TD WIDTH=10 HEIGHT=' + menu_cell +
	'><IMG WIDTH=10 HEIGHT=' + menu_cell +
	' BORDER=0 SRC="images/kd_d2cel.gif"></TD>';
cell_part1  = '<TD WIDTH=82 HEIGHT=' + menu_cell +
	'><A onMouseOver="return(KD_mswap(\'';
cell_middle = '\',\'';
cell_part2  = '\', \'\'));" HREF="';
cell_part3  = '\', \'';
cell_part4  = '\'));" onMouseOut="return(KD_mswap(\'';
cell_src    = '"><IMG WIDTH=82 HEIGHT=' + menu_cell + ' BORDER=0 SRC="';
cell_name   = '" NAME="';
cell_part5  = '"></A></TD>';
cell_right   = '<TD WIDTH=10 HEIGHT=' + menu_cell +
	'><IMG WIDTH=10 HEIGHT=' + menu_cell +
	' BORDER=0 SRC="images/kd_d2cer.gif"></TD></TR>';

// Menu titles shown in status window
KD_mtitle = new Array("Products", "Tech Info", "News",
	"Partners", "Corporate");

// ddmenux_pics[]	"off" images
// ddmenux_on[]		"on" images
// ddmenux_names[]	item names (All menu names must be unique)
// ddmenux_links[]	document link
// ddmenux_words[]	status window text

ddmenu1_pics = new Array("images/kd_drts.gif", "images/kd_dtcp.gif",
	"images/kd_dgfx.gif", "images/kd_dfs.gif",
	"images/kd_dlic.gif");
ddmenu1_on = new Array("images/kd_drts1.gif", "images/kd_dtcp1.gif",
	"images/kd_dgfx1.gif", "images/kd_dfs1.gif",
	"images/kd_dlic1.gif");
ddmenu1_names = new Array("rtos", "tcp", "graphics",
	"filesys", "license");
ddmenu1_links = new Array("rtos/rtos.htm", "tcp_ip/tcpip.htm",
	"html/kdkp1040.htm", "html/kdkp1018.htm",
	"html/kdkp1410.htm");
ddmenu1_words = new Array("RTOS", "TCP/IP", "Graphics",
	"File System", "Licensing");

ddmenu2_pics = new Array("images/kd_dman.gif", "images/kd_ddem.gif",
	"images/kd_dsup.gif");
ddmenu2_on = new Array("images/kd_dman1.gif", "images/kd_ddem1.gif",
	"images/kd_dsup1.gif");
ddmenu2_names = new Array("manuals", "demos", "support");
ddmenu2_links = new Array("html/kdkp1510.htm", "html/kdkp1610.htm",
	"html/kdkp1560.htm");
ddmenu2_words = new Array("Manuals", "Demos", "Support");

ddmenu3_pics = new Array("images/kd_dwha.gif", "images/kd_dpr.gif",
	"images/kd_dnlr.gif");
ddmenu3_on = new Array("images/kd_dwha1.gif", "images/kd_dpr1.gif",
	"images/kd_dnlr1.gif");
ddmenu3_names = new Array("whatsnew", "press", "newsletters");
ddmenu3_links = new Array("html/kdkp1300.htm", "html/kdkp1310.htm",
	"html/kdkp1320.htm");
ddmenu3_words = new Array("Whats New", "Press Releases", "Newsletters");

// Add white papers to News menu
if (whitep_on) {
	ddmenu3_pics.push("images/kd_dwpr.gif");
	ddmenu3_on.push("images/kd_dwpr1.gif");
	ddmenu3_names.push("whitep");
	ddmenu3_links.push("html/kdkp1330.htm");
	ddmenu3_words.push("White Papers");
	}

ddmenu4_pics = new Array("images/kd_dtoo.gif", "images/kd_dali.gif",
	"images/kd_ddea.gif", "images/kd_dcnt.gif");
ddmenu4_on = new Array("images/kd_dtoo1.gif", "images/kd_dali1.gif",
	"images/kd_ddea1.gif", "images/kd_dcnt1.gif");
ddmenu4_names = new Array("tools", "alliances", "dealers", "contractors");
ddmenu4_links = new Array("html/kdkp1621.htm", "html/kdkp1620.htm",
	"html/kdkp1132.htm", "html/kdkp1561.htm");
ddmenu4_words = new Array("Tools", "Alliances", "Dealers", "Contractors");

ddmenu5_pics = new Array("images/kd_dcom.gif", "images/kd_dsho.gif",
	"images/kd_dsup.gif");
ddmenu5_on = new Array("images/kd_dcom1.gif", "images/kd_dsho1.gif",
	"images/kd_dsup1.gif");
ddmenu5_names = new Array("company", "showcase", "support2");
ddmenu5_links = new Array("html/kdkp1130.htm", "html/kdkp1400.htm",
	"html/kdkp1560.htm");
ddmenu5_words = new Array("Company", "Showcase", "Support");

// Warning layer for impaired browsers
no_menu = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>';
no_menu += '<TR><TD WIDTH=620 HEIGHT=64><IMG WIDTH=620 HEIGHT=64';
no_menu += ' BORDER=0 SRC="images/kd_empty.gif"></TD></TR><TR>';
no_menu += '<TD WIDTH=250 HEIGHT=20><A HREF="http://www.kadak.com/index.htm">';
no_menu += '<IMG ALT="Home" WIDTH=150 HEIGHT=20 BORDER=0';
no_menu += ' SRC="images/kd_tmlnk.gif"></A></TD></TR>';
no_menu += '<TR><TD WIDTH=620 HEIGHT=64><IMG WIDTH=620 HEIGHT=64';
no_menu += ' BORDER=0 SRC="images/kd_empty.gif"></TD></TR></TABLE>';

// Repair preloaded image stripe
img_html = "";
img_load = new Array();
img_load[0] = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>';
img_load[0] += '<TR><TD WIDTH=1 HEIGHT=';
img_load[1] = '><IMG WIDTH=1 HEIGHT=1 BORDER=0';
img_load[1] += ' SRC="images/kd_empty.gif"></TD></TR>';
img_load[1] += '<TR><TD WIDTH=4 HEIGHT=19><IMG WIDTH=4 HEIGHT=19';
img_load[1] += ' BORDER=0 SRC="images/kd_sfill.gif"></TD></TR></TABLE>';

// -------------- End of content variables --------------

function KD_init() {
	window.status = "";
	if (!layerOK)
		return;

	if (is_ie || is_dom)
		DF_getsize();
	else	NS_getsize();

	KD_prepImage();
	if (KD_useLinks()) {
		loaded = 1;
		return;
		}

	// Make drop-down menu HTML content
	KD_makeMenu(0, ddmenu1_pics, ddmenu1_on, ddmenu1_names,
		ddmenu1_links, ddmenu1_words);
	KD_makeMenu(1, ddmenu2_pics, ddmenu2_on, ddmenu2_names,
		ddmenu2_links, ddmenu2_words);
	KD_makeMenu(2, ddmenu3_pics, ddmenu3_on, ddmenu3_names,
		ddmenu3_links, ddmenu3_words);
	KD_makeMenu(3, ddmenu4_pics, ddmenu4_on, ddmenu4_names,
		ddmenu4_links, ddmenu4_words);
	KD_makeMenu(4, ddmenu5_pics, ddmenu5_on, ddmenu5_names,
		ddmenu5_links, ddmenu5_words);

	KD_prepMenus();			// Make menu layers
	loaded = 1;

	// Detect mouse motion outside client window
	if (document.layers)
		document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove=mtrack;
	}


function KD_initx() {
	if (!layerOK)
		alert('We do not have menus for your browser!\n' +
			'Use the links at the bottom of the page.');
	KD_init();
	}

function KD_exit() {
	if (!loaded) return;

	loaded = 0;
	if (document.layers)
		document.releaseEvents(Event.MOUSEMOVE);
	document.onmousemove=null;
	}

function KD_menu(index) {
	ALL_off();
	if (!(loaded && menuOK))
		return true;

	window.status = KD_mtitle[index];
	menu_on = index + 1;
	target = eval(doc_ref + 'KD_menus[index]' + style_ref);
	target.visibility = 'visible';
	return true;
	}

// Get Netscape viewport size (Mozilla and Gecko)
function NS_getview() {
	view_width = parseInt(innerWidth) - scrollxfix;
	view_height = parseInt(innerHeight) - scrollyfix;

	if (view_width < 0)
		view_width = 0;
	if (view_height < 0)
		view_height = 0;
	}


// Default sizing info (not Mozilla)
function DF_getsize() {
	bload_x = getRealLeft(document.images["bload"]);
	bload_y = getRealTop(document.images["bload"]);
	page_width = getRealLeft(document.images["tbanr"]) + tban_topr;
	page_height = getRealTop(document.images["bcopyr"]);

	if (is_ie) {
		view_width = parseInt(document.body.clientWidth);
		view_height = parseInt(document.body.clientHeight);
		}

	else	NS_getview();	// Get Gecko view size
	}

// Netscape sizing info (Mozilla only)
function NS_getsize() {
	bload_x = parseInt(document.images["bload"].x);
	bload_y = parseInt(document.images["bload"].y);
	page_width = parseInt(document.images["tbanr"].x) + tban_topr;
	page_height = parseInt(document.images["bcopyr"].y);

	NS_getview();		// Get Mozilla view size
	}

// Viewport has been resized
// Important:	Netscape 4.0x can lose a layer's image on resize.
// Solution:	If the window size has changed, initiate a reload
//		to force the document page to be regenerated.
function KD_resize() {
	if (!loaded)
		return;

	if (is_ie || is_dom) {
		DF_getsize();
		}
	else {
		old_vw = view_width;
		old_vh = view_height;
		NS_getsize();

		if ((view_width != old_vw) || (view_height != old_vh)) {
			KD_exit();
			location.reload();
			while(!loaded) {loaded = 0;} // do NOT return!
			}
		}

	ALL_off();
	if (!KD_useLinks())
		KD_prepMenus();	// Recreate menu layers
	}

function KD_useLinks() {
	if (menuOK)
		return 0;

	KD_setLayer('NoMenu', no_menu);
	target = eval(doc_ref + '"NoMenu"' + style_ref);
	target.visibility = 'visible';
	return 1;
	}

function KD_prepImage() {
	if (!imageOK)
		return;

	// Fix region used to preload images; make layer visible
	img_html = img_load[0] + bload_y + img_load[1];
	KD_setLayer('PreLoad', img_html);

	preloadtgt = eval(doc_ref + '"PreLoad"' + style_ref);
	preloadtgt.visibility = 'visible';
	}

function KD_prepMenus() {
	if (page_width < minwide) page_width = minwide;
	if (page_height < minhigh) page_height = minhigh;

	for (var i=0; i<KD_menus.length; i++) {
		dd_content[i] = KD_createMLayer(i);
		KD_setLayer(KD_menus[i], dd_content[i]);
		}
	}

// Writing HTML into a layer
function KD_setLayer(name, content) {
	if (is_dom)
		document.getElementById(name).innerHTML = content;
	else if (is_ie)
		document.all[name].innerHTML = content;
	else {	// Must be Netscape
		document.layers[name].document.open();
		document.layers[name].document.write(content);
		document.layers[name].document.close();
		}
	}

// Creating drop-down menu HTML
function KD_makeMenu(index, image_array, on_array,
		names_array, links_array, words_array) {
	var i;
	var text = dd_html[0];

	for (i=0; i<image_array.length; i++) {
		text += cell_left + cell_part1 + KD_menus[index] +
			cell_middle + names_array[i];
		text += cell_middle + on_array[i] + cell_part3 +
			words_array[i];
		text += cell_part4 + KD_menus[index] + cell_middle +
			names_array[i];
		text += cell_middle + image_array[i] + cell_part2 +
			links_array[i];
		text += cell_src + image_array[i] + cell_name +
			names_array[i];
		text += cell_part5 + cell_right;
		}

	text += dd_html[1];
	dd_texts[index] = text;
	hspan = menu_cell * i;
	dd_ys[index] = hspan + menu_end + menu_top;
	}

// Creating a drop-down menu layer
function KD_createMLayer(index) {
	var mxloc, myloc;
	var mname = KD_mname[index];
	if (is_moz) {
		mxloc = parseInt(document.images[mname].x);
		myloc = parseInt(document.images[mname].y);
		}
	else {
		mxloc = getRealLeft(document.images[mname]);
		myloc = getRealTop(document.images[mname]);
		}

	myloc -= 2;			// Adjust menu position
	mxloc -= 2;
	if (mxloc & 1)
		mxloc -= 1;		// Adjust x to even pixel

	var xlfill = mxloc;
	var xrfill = page_width - mxloc - top_width;
	var yval = myloc;

	// Start layer table with banner row
	var text = ddmtbl;
	text += ddmtdw + page_width + ddmh + yval;
	text += ddmoff + ddmimgw + page_width + ddmh + yval;
	text += ddmimge + '</TR>';

	// Menu title row is a table
	yval = top_height;
	text += '<TR>' + ddmtdw + page_width + ddmh + yval;
	text += '>' + ddmtbl;
	text += ddmtdw + xlfill + ddmh + yval;
	text += ddmoff + ddmimgw + xlfill + ddmh + yval;
	text += ddmimge;
	text += ddmtdw + top_width + ddmh + yval;
	text += ddmA1 + KD_mtitle[index] + ddmA2;
	text += ddmimgw + top_width + ddmh + yval;
	text += ddmimge;
	text += ddmtdw + xrfill + ddmh + yval;
	text += ddmoff + ddmimgw + xrfill + ddmh + yval;
	text += ddmimge + ddmtend + ddmrend;

	// Pull down menu row is a table
	xlfill = mxloc - menu_off_x;
	xrfill = xrfill + top_width + menu_off_x - menu_width;
	yval = dd_ys[index];
	text += '<TR>' + ddmtdw + page_width + ddmh + yval;
	text += '>' + ddmtbl;
	text += ddmtdw + xlfill + ddmh + yval;
	text += ddmoff + ddmimgw + xlfill + ddmh + yval;
	text += ddmimge;
	text += ddmtdw + menu_width + ddmh + yval;
	text += '>' + dd_texts[index] + '</TD>';
	text += ddmtdw + xrfill + ddmh + yval;
	text += ddmoff + ddmimgw + xrfill + ddmh + yval;
	text += ddmimge + ddmtend + ddmrend;

	// Bottom fill row
	yval = page_height - myloc - top_height - dd_ys[index];
	text += '<TR>' + ddmtdw + page_width + ddmh + yval;
	text += ddmoff + ddmimgw + page_width + ddmh + yval;
	text += ddmimge + ddmtend;

	return text;
	}

// Swapping an image within a layer
function KD_mswap(a_layer, name, img, msg) {
	if (is_dom)
		return(KD_swap(name,img,msg));

	window.status = msg;
	target = eval(doc_ref + 'a_layer' + end_ref);
	target.document.images[name].src = img;
	return true;
	}	

// If the mouse leaves the viewable area, turn off the menus
// Although not really necessary, do so as a precaution
function mtrack(e) {
	if (!(loaded && menu_on)) return;

	var mouseX, mouseY, screenWidth, screenHeight;
	if (is_ie) {
		mouseX = event.x;
		mouseY = event.y;
		screenWidth = document.body.clientWidth;
		screenHeight = document.body.clientHeight;
		}
	else {	// Netscape (all versions)
		mouseX = e.pageX - pageXOffset;
		mouseY = e.pageY - pageYOffset;
		screenWidth = innerWidth;
		screenHeight = innerHeight;
		}

	screenWidth -= scrollxfix;
	screenHeight -= scrollyfix;

	if (screenWidth < 0) screenWidth = 0;
	if (screenHeight < 0) screenHeight = 0;

	if ((mouseX >= screenWidth) || (mouseY >= screenHeight) ||
			(mouseX <= 0) || (mouseY <= 0))
		ALL_off();
	}

function ALL_off() {
	window.status = "";
	menu_on = 0;
	if (!(loaded && menuOK))
		return true;

	// Only the kill layer needs to be turned off
	// but in Netscape if the mouse is moved fast enough
	// things can get confused, so all menu layers are turned off
	for (var i=0; i<KD_menus.length; i++) {
		target = eval(doc_ref + 'KD_menus[i]' + style_ref);
		target.visibility = 'hidden';
		}

	KD_prepImage();		// Fix preloaded image
	return true;
	}

function KD_ws(name) {
	window.status = name;
	return true;
	}

// Recurses through parent layers to get a layer's real position
// in the document (Netscape does not need to use this function,
// as it keeps track of where elements are in the document)
function getRealLeft(el) {
	var xPos = el.offsetLeft;
	var tempEl = el.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
		}
	return xPos;
}

function getRealTop(el) {
	var yPos = el.offsetTop;
	var tempEl = el.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
		}
	return yPos;
}

function searcher() {
	myPopup = window.open(searchfile, 'searchWin',
		'scrollbars=no,status=no,width=' +
		searchwidth + ',height=100');

	if (!myPopup.opener)
		myPopup.opener = self;
	}

// End of File
