/*
	_______________________________________________________
	
	SCRIPTS FOR PIPEX POP-UP NAVIGATION SYSTEM
	The script in this file control the popup navigation
	system, creating the DIVs and LAYERs on the fly, populating
	them, and manipulating their positioning and visibility
	Copyright PIPEX Internet Ltd, 2000-2002
	_______________________________________________________

*/


// ************************************************************** //

/* Error handler to supress errors. */

window.onerror = new Function("return true;");
window.onresize = new Function("location.reload()");
/* Comment out the line above to see full script errors for debugging
   etc */
   
// ************************************************************** //

var table_template_front_array = new Array();
var table_template_end_array = new Array();
var row_template_front_array = new Array();
var parent_layer_array = new Array();
var child_layer_array = new Array();
var last_button_name = "";
var last_parent_layer = "";
var last_child_layer = "";
var last_image_name = "";
var image_pointer = "";
var TimerID = "";
var table_width = 110; // width of main menu layer
var tw2 = 40; // width of second-level menus
var tab_name = ""; // name of tab which was moused over

// reload code for Netscape browsers
if (document.layers) {
	initial_width = innerWidth;
	initial_height = innerHeight;
}

function reload_window() {
	if ((innerWidth != initial_width) || (innerHeight != initial_height)) location.reload();
}

if (document.layers) onresize = reload_window;
// end reload code


function getWindowSize(whichd) {
/*
	This function returns the height or width
	of the document display area of the browser.
	call using getWindowSize('w') for width or 
	...('h') for height. :: PIPEX Internet Ltd
	2000
*/
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);  
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
   && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
   && (agt.indexOf('webtv')==-1));
var is_nav4up = (is_nav && (is_major >= 4));
var is_gecko = (agt.indexOf("gecko") != -1); 
 var is_ie   = (agt.indexOf("msie") != -1);
 var is_ie4up  = (is_ie  && (is_major >= 4)); 
 var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );  

if (is_nav) {
	var nw = window.innerWidth;
	var nh = window.innerHeight;
	var nh = nh + 4;
	var nw = nw - 5;	
		if (whichd=='w')  
			{ return nw; } 
		if (whichd=='h')
			{ return nh; }
}
if (is_ie) {
	var iw = document.body.clientWidth;
	var ih = document.body.clientHeight;
		if (whichd=='w')
			{ return iw; }
		if (whichd=='h')
			{ return ih; }
}

}

function getProdLeft() {
// work out position of products button

var winwidth = getWindowSize('w');
// page is 783 wide so -
var spaceleft = (winwidth - 783);
// halve the spaceleft to find the space
// to the left of the page
var leftspace = (spaceleft / 2);

// left edge of prods button is about 338 pixels
// from left edge of page, so add 338 to leftspace
// to find its position relative to edge of window
var pbleft = leftspace + 338;

// if the window size is less than the page size, there
// will be negative values in the space variables,
// so just return 338
if (winwidth < 783)
	{ pbleft = 338; }

return pbleft;
}



if (document.images) {
	var arrow = new Image();
	var blank = new Image();
	
	var productsbutton_on = new Image();
	var productsbutton_off = new Image();
	
	var websellbutton_on = new Image();
	var websellbutton_off = new Image();
	
	var dialbutton_on = new Image();
	var dialbutton_off = new Image();
	
	var aboutbutton_on = new Image();
	var aboutbutton_off = new Image();
	
	var networkbutton_on = new Image();
	var networkbutton_off = new Image();
	
	productsbutton_on.src = "http://www.gtnet.gov.uk/images/topbar/nav/solutions-on.gif";
	productsbutton_off.src = "http://www.gtnet.gov.uk/images/topbar/nav/solutions.gif";
	
	websellbutton_on.src = "http://www.gtnet.gov.uk/images/topbar/nav/websell-on.gif";
	websellbutton_off.src = "http://www.gtnet.gov.uk/images/topbar/nav/websell-on.gif";
	
	dialbutton_on.src = "http://www.gtnet.gov.uk/images/topbar/nav/dial-on.gif";
	dialbutton_off.src = "http://www.gtnet.gov.uk/images/topbar/nav/dial-on.gif";	
	
	aboutbutton_on.src = "http://www.gtnet.gov.uk/images/topbar/nav/about-on.gif";
	aboutbutton_off.src = "http://www.gtnet.gov.uk/images/topbar/nav/about.gif";
	
	networkbutton_on.src = "http://www.gtnet.gov.uk/images/topbar/nav/network-on.gif";
	networkbutton_off.src = "http://www.gtnet.gov.uk/images/topbar/nav/network.gif";	
	
	arrow.src = "arrow.gif";
	blank.src = "blank.gif";
	
	
}

function Layer(name, visibility, zindex, table_template, left, top) {
	this.name = name;
	this.left = left;
	this.top = top;
	this.width = table_width;
	this.visibility = visibility;
	this.zindex = zindex;
	this.table_template = table_template;
	
	this.ar = ar;
	this.fl = fl;

	if (this.table_template == 1) this.left = this.left + this.width - 7;
	if (table_template == 1) this.width = tw2;
	if (table_template == 3) this.width = ndwidth;
	if (document.all || document.getElementById) {
		if (navigator.appVersion.indexOf("Macintosh") == -1) {
			this.top += 7;
			this.left += 2;
		}
		
		this.layer_content = '<div id="' + this.name + '" style="position: absolute; left: ' + this.left + '; top: ' + this.top + '; width: ' + this.width + '; visibility: ' + (this.visibility ? 'visible' : 'hidden') + '; z-index: ' + this.zindex + ';">';
	}
	else if (document.layers) {
	    this.layer_content = '<layer name="' + this.name + '" left=' + this.left + ' top=' + this.top + ' width=' + this.width + ' visibility=' + (this.visibility ? '"show"' : '"hide"') + ' z-index=' + this.zindex + '>';
	}
	
	this.layer_content += table_template_front_array[this.table_template];
	if (this.table_template == 0) parent_layer_array[parent_layer_array.length] = this.name;
	else child_layer_array[child_layer_array.length] = this.name;
}






function ar(row_template, row_content) {  // add row
	this.layer_content += row_template_front_array[row_template] + row_content + row_end;
}

function fl() {  // finish layer
	this.layer_content += table_template_end_array[this.table_template];
	if (document.all || document.getElementById) this.layer_content += '</div>';
	else if (document.layers) this.layer_content += '</layer>';
	document.write(this.layer_content);
}

function cpv(layer_name, image_name) {  // change parent visibility
	tabname = image_name;
	if ((last_parent_layer) && (last_parent_layer != layer_name)) mi(last_parent_layer);
	if ((last_button_name) && (last_button_name != image_name)) mii(last_button_name);
	ha();
	last_parent_layer = layer_name;
	last_button_name = image_name;
	hc();
	tlv(layer_name);
	tiv(layer_name, image_name);
}

function ccv(name) {  // change child visibility
	if ((last_child_layer) && (last_child_layer != name)) mi(last_child_layer);
	last_child_layer = name;
	tlv(name);
}

function ccv2(lcl,name) {  // change child visibility
	last_child_layer = lcl;
	tlv(name);
}

function hc() {  // hide child
	if (last_child_layer) mi(last_child_layer);
}

function ha() {  // hide arrow
	// image_pointer.src = blank.src;
}

function sa(name) { // show arrow
	last_image_name = name + "link";

	if (document.layers) {
		if (last_image_name) document.layers[last_parent_layer].document.images[last_image_name].src = arrow.src;
		image_pointer = document.layers[last_parent_layer].document.images[last_image_name];
	}
	else if (document.all || document.getElementById) {
		document.images[last_image_name].src = arrow.src;
		image_pointer = document.images[last_image_name];
	}
}

function tav(name) {  // toggle arrow visibility
	ha();
	
	if (document.layers) {
		if (document.layers[name].visibility == "show") ha();
		else sa(name);
	}
	else if (document.all) {
		if (document.all[name]) {
			if (document.all[name].style.visibility == "visible") ha();
			else sa(name);
		}
	}
	else if (document.getElementById) {
		if (document.getElementById(name)) {
			if (document.getElementById(name).style.visibility == "visible") ha();
			else sa(name);
		}
	}
}

function tlv(name) {  // toggle layer visibility
	if (document.layers) {
		if (document.layers[name].visibility == "show") mi(name);
		else mv(name);
	}
	else if (document.all) {
		if (document.all[name]) {
			if (document.all[name].style.visibility == "visible") mi(name);
			else mv(name);
		}
	}
	else if (document.getElementById) {
		if (document.getElementById(name)) {
			if (document.getElementById(name).style.visibility == "visible") mi(name);
			else mv(name);
		}
	}
}

function mv(name) {  // make visible
	if (document.layers) document.layers[name].visibility = "show";
	else if (document.all) document.all[name].style.visibility = "visible";
	else if (document.getElementById) document.getElementById(name).style.visibility = "visible";
}

function mi(name) {  // make invisible
	if (document.layers) { if (document.layers[name]) { document.layers[name].visibility = "hide"; } }
	else if (document.all) {
		if (document.all[name])
		{ document.all[name].style.visibility = "hidden"; }
	}
	else if (document.getElementById) {
		if (document.getElementById(name))
		{ document.getElementById(name).style.visibility = "hidden"; }
	}
	
	
	/*
	if (document.layers) {
		if (document.layers['DL21B']) {
			document.layers['DL21B'].visibility = "hide"; 
			}
		}
	if (document.all) {
		if (document.all['DL21B']) {
			document.all['DL21B'].style.visibility = "hide";
			}
		}
	*/
	
	if (name == 'L21') {
	// fix for problem of a menu box which stayed on screen
	// no other solution seemed to work, so have to do this way

	if (document.layers) {document.layers['L21B'].visibility = "hide"; }
	else if (document.all) {
		if (document.all['L21B'])
		{ document.all['L21B'].style.visibility = "hidden"; }
	}
	else if (document.getElementById) {
		if (document.getElementById('L21B'))
		{ document.getElementById('L21B').style.visibility = "hidden"; }
	}
	
	}
	
	if (name == 'DL21') {
	// fix for problem of a menu box which stayed on screen
	// no other solution seemed to work, so have to do this way

	if (document.layers) {document.layers['DL21B'].visibility = "hide"; }
	else if (document.all) {
		if (document.all['DL21B'])
		{ document.all['DL21B'].style.visibility = "hidden"; }
	}
	else if (document.getElementById) {
		if (document.getElementById('DL21B'))
		{ document.getElementById('DL21B').style.visibility = "hidden"; }
	}
	
	}

}
function tiv(layer_name, image_name) {  // toggle image visibility
	if (document.layers) {
		if (document.layers[layer_name].visibility == "show") miv(image_name);
		else mii(image_name);
	}
	else if (document.all) {
		if (document.all[layer_name].style.visibility == "visible") miv(image_name);
		else mii(image_name);
	}
	else if (document.getElementById) {
		if (document.getElementById(layer_name).style.visibility == "visible") miv(image_name);
		else mii(image_name);
	}
}

function mii(name) {  // make image invisible
	document.images[name].src = eval(last_button_name + "_off.src");
}

function miv(name) {  // make image visible
document.images[last_button_name].src = eval(last_button_name + "_off.src");
document.images[name].src = eval(name + "_on.src");
}

function ci(image_tag_name, new_image_name) {  // change image
document.images[image_tag_name].src = eval(new_image_name + ".src");
}

function close_sec()
{
    clearTimeout(TimerID);
    TimerID = setTimeout('close_all()', 250);
	//changeImage('L1', 'puProducts', 'http://www.gtnet.gov.uk/images/newcorphp/menu/newset/pipexproducts.gif');
}


function close_all() {
/*
	switch (tab_name) {
	case ('productsbutton'):
		document.images['productsbutton'].src = productsbutton_off.src;
	break;
	case ('websellbutton'):
		document.images['websellbutton'].src = websellbutton_off.src;
	break;
	case ('networkbutton'):
		document.images['networkbutton'].src = networkbutton_off.src;
	break;
	case ('aboutbutton'):
		document.images['aboutbutton'].src = aboutbutton_off.src;
	break; }
*/
	
	
	mi(last_parent_layer);
	mii(last_button_name);
	ha();
	hc();
}

function changeImage(layer, image, newsrc) {
// Change the src of _image_  on _layer_ to _newsrc_

if (document.layers) { // netscape 4
	if (document.layers[layer].document.images[image]) {
	
		document.layers[layer].document.images[image].src = newsrc;
		} else { /*alert('Error: Image '+ image + ' not found!'); */ } }
		
if (document.all || document.getElementById) { // ie or netscape gecko
	if (document.images[image]) {
		document.images[image].src = newsrc;
		}
}
}




function define_table(tw) {
	table_template_front_array[0] = '<TABLE WIDTH="' + tw + '" CELLSPACING="0" CELLPADDING="0" BORDER="0" onmouseover="changeImage(\'puConnectivity\', \'http://www.gtnet.gov.uk/images/newcorphp/menu/connectivity-on.gif\'); clearTimeout(TimerID)" onmouseout="changeImage(\'puConnectivity\', \'http://www.gtnet.gov.uk/images/newcorphp/menu/connectivity.gif\'); close_sec()"><TR><TD COLSPAN="2" WIDTH="' + (tw-7) + '" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=' + (tw2-7) + ' HEIGHT=1 BORDER="0"></TD><TD COLSPAN="2" WIDTH="7" bgcolor="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD></TR><TR><TD WIDTH="7" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=7 HEIGHT=1 BORDER="0"></TD><TD WIDTH="' + (tw-7) + '" VALIGN="top" BGCOLOR="3F0C72"><TABLE WIDTH="' + (tw-14) + '" CELLSPACING="0" CELLPADDING="0" BORDER="0">';
	table_template_end_array[0] = '</TABLE></TD><TD WIDTH="6" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=6 HEIGHT=1 BORDER="0"></TD><TD WIDTH="1" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=1 HEIGHT=1 BORDER="0"></TD></TR><TR><TD COLSPAN="2" WIDTH="' + (tw-7) + '" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=' + (tw-7) + ' HEIGHT=1 BORDER="0"></TD><TD COLSPAN="2" WIDTH="7" bgcolor="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD></TR></TABLE>';
	
	table_template_front_array[1] = '<TABLE WIDTH="' + tw2 + '" CELLSPACING="0" CELLPADDING="0" BORDER="0" onmouseover="clearTimeout(TimerID)" onmouseout="close_sec()"><TR><TD COLSPAN="2" WIDTH="7" bgcolor="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD><TD WIDTH="' + (tw2-14) + '" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=' + (tw2-14) + ' HEIGHT=1 BORDER="0"></TD><TD COLSPAN="2" WIDTH="7" bgcolor="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD></TR><TR><TD WIDTH="1" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=1 HEIGHT=1 BORDER="0"></TD><TD WIDTH="6" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=6 HEIGHT=1 BORDER="0"></TD><TD WIDTH="' + (tw2-14) + '" VALIGN="top" BGCOLOR="3F0C72"><TABLE WIDTH="' + (tw2-14) + '" CELLSPACING="0" CELLPADDING="1" BORDER="0">';
	table_template_end_array[1] = '</TABLE></TD><TD WIDTH="6" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=6 HEIGHT=1 BORDER="0"></TD><TD WIDTH="1" bgcolor="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=1 HEIGHT=1 BORDER="0"></TD></TR><TR><TD COLSPAN="2" WIDTH="7" bgcolor="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD><TD WIDTH="' + (tw2-14) + '" BGCOLOR="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=' + (tw2-14) + ' HEIGHT=1 BORDER="0"></TD><TD COLSPAN="2" WIDTH="7" bgcolor="3F0C72"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD></TR></TABLE>';
	
	table_template_front_array[3] = '<TABLE WIDTH="' + tw + '" CELLSPACING="0" CELLPADDING="0" BORDER="0" onmouseover="clearTimeout(TimerID)" onmouseout="close_sec()"><TR><TD COLSPAN="2" WIDTH="7"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD><TD WIDTH="' + (tw-14) + '"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=' + (tw-14) + ' HEIGHT=1 BORDER="0"></TD><TD COLSPAN="2" WIDTH="7"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD></TR><TR><TD WIDTH="1"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=1 HEIGHT=1 BORDER="0"></TD><TD WIDTH="6"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=6 HEIGHT=1 BORDER="0"></TD><TD WIDTH="' + (tw-14) + '" VALIGN="top"><TABLE WIDTH="' + (tw-14) + '" CELLSPACING="0" CELLPADDING="0" BORDER="0">';
	table_template_end_array[3] = '</TABLE></TD><TD WIDTH="6"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=6 HEIGHT=1 BORDER="0"></TD><TD WIDTH="1"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=1 HEIGHT=1 BORDER="0"></TD></TR><TR><TD COLSPAN="2" WIDTH="7"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD><TD WIDTH="' + (tw-14) + '"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=' + (tw-14) + ' HEIGHT=1 BORDER="0"></TD><TD COLSPAN="2" WIDTH="7"><IMG SRC="/new-images-dir/spacer.gif" WIDTH=7 HEIGHT=8 BORDER="0"></TD></TR></TABLE>';
	
	row_template_front_array[0] = '<TR><TD WIDTH=5 VALIGN="top"><IMG SRC="http://www.gtnet.gov.uk/images/onepixel.gif" WIDTH=5 HEIGHT=13 BORDER="0"></TD><TD WIDTH=' + (tw-25) + '><FONT FACE="Arial, Helvetica" SIZE=2>';
	row_template_front_array[1] = '<TR><TD WIDTH=' + (tw2-14) + ' COLSPAN="2"><FONT FACE="Arial, Helvetica" SIZE=2>';
	row_template_front_array[3] = '<TR><TD WIDTH=' + (tw2-14) + ' COLSPAN="2"><FONT FACE="Arial, Helvetica" SIZE=2>';	
	row_template_front_array[2] = '<TR><TD WIDTH=' + (tw2-14) + ' ALIGN="right" COLSPAN="2"><FONT FACE="Arial, Helvetica" SIZE=1>';

	row_end = '</TR>';
}

define_table(table_width);



var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);  
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
   && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
   && (agt.indexOf('webtv')==-1));

if (is_nav) {
var productsLeft = getProdLeft();
var websellLeft = getProdLeft()-8;
var dialLeft = getProdLeft()-8;
var aboutLeft = getProdLeft()-135;
var networkLeft = getProdLeft()-70;

var productsTop = 95;
var websellTop = 95;
var dialTop = 95;
var aboutTop = 95;
var networkTop = 95;
} else {
var productsLeft = getProdLeft()-10;
var websellLeft = getProdLeft();
var dialLeft = getProdLeft()-6;
var aboutLeft = getProdLeft()-130;
var networkLeft = getProdLeft()-70;
var productsTop = 91;
var websellTop = 91;
var dialTop = 91;
var aboutTop = 90;
var networkTop = 90
}

