// Content   : JavaScript Functions
// Author    : Mark Zwienenberg
// Copyright : Zwienenberg Engineering

// **************************************
// *** Javascript: swapImage          ***
// **************************************
// *** Description:                   ***
// ***	 changes the button activated ***
// ***   in the onMouseOver version   ***
// **************************************
function swapImage() 
	{
	// local variables
	var i, x;
	var j=0;
	var a=swapImage.arguments;
	
	// find the activated button and swap
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
		if ((x=findObj(a[i]))!=null)
			{
			document.MM_sr[j++]=x; 
			if(!x.oSrc)
				x.oSrc=x.src; 
			x.src=a[i+2];
			}
	}
	

// **************************************
// *** Javascript: swapImgRestore     ***
// **************************************
// *** Description:                   ***
// ***	 changes the activated button ***
// ***   in the original version      ***
// **************************************
function swapImgRestore()
 	{
 	// local variables
	var i,x;
	
	// restore the original state
	var a=document.MM_sr; 
	for(i=0; a && i<a.length && (x=a[i]) && x.oSrc;i++) 
		x.src=x.oSrc;
	}

// **************************************
// *** Javascript: preloadImages     ***
// **************************************
// *** Description:                   ***
// ***	 load all images at the same  ***
// ***   time as the entire document, ***
// ***   so the swap function won't   ***
// ***   be delayed.                  ***
// **************************************
function preloadImages()
	{ 
	var d=document; 
	if(d.images)
		{ 
		if(!d.MM_p) 
		d.MM_p=new Array();
		var i, j=d.MM_p.length, a=preloadImages.arguments; 
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0)
				{ 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
				}
		}
	}


// **************************************
// *** Javascript: findObj            ***
// **************************************
// *** Description:                   ***
// ***	 find the activated button    ***
// **************************************
function findObj(n, d)
	{ 
	var p,i,x;  
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
		{
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
		}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
		for (i=0;!x&&i<d.forms.length;i++) 
			x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=findObj(n,d.layers[i].document); 
	return x;
	}



// Layermenu at mouse-over

	var level;
	var OldMenu;
	var OldMenu2;
	var NewMenu;
	var ns4;
	var ie4;
	var ns6;
	OldMenu = "nix";
	OldMenu2 = "nix";
	NewMenu = "nix";
	level = -1;
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false
	ns6 = (document.getElementById)? true:false

	window.onerror=null;
	browserName=navigator.appName;
	browserVer=parseInt(navigator.appVersion);
	dir="images/";

	if(browserName=="Netscape" && browserVer>=3 || browserName=="Microsoft Internet Explorer" && browserVer>=4) 				ver="yes";
	else 
	ver="no";

	function hide(id)
	{
	if (ns4) 
		document.layers[id].visibility = "hide";
	else if (ie4) 
		document.all[id].style.visibility = "hidden";
	else if (ns6)
		document.getElementById(id).style.visibility = "hidden";
 	}

	function show(id)
	{
	if (ns4) 
		document.layers[id].visibility = "show";
	else if (ie4) 
		document.all[id].style.visibility = "visible";
	else if (ns6)
		document.getElementById(id).style.visibility = "visible";
	}
	

	
	function toggle(id)
		{
		if (document.all[id].style.visibility == "hidden" || 
				document.getElementById(id).style.visibility == "hidden")
			{
			swapImgRestore();
			if (level == 1 && OldMenu2 != 'nix')
				hide(OldMenu2);
				
			level = 0;
			
			if (id == 'sub1')
				swapImage('home','','images/home_b.gif',1);
			if (id == 'sub2')
				swapImage('products','','images/products_b.gif',1);
			if (id == 'sub3')
				swapImage('support','','images/support_b.gif',1);
			if (id == 'sub4')
				swapImage('order','','images/order_b.gif',1);
			if (id == 'sub5')
				swapImage('info','','images/info_b.gif',1);

						
			if (OldMenu == 'nix')
				{
				show(id);
				OldMenu = id;
				}
			else
				{
				hide(OldMenu);
				if (id != OldMenu)
					{
					show(id);
					OldMenu = id;
					}
				else 	{
					OldMenu = "nix";
					}
				}
			}
		}
	

	function dispose()
		{
		if (OldMenu != 'nix')
			{
			hide(OldMenu);
			if (level == 1 && OldMenu2 != 'nix')
				{
				hide(OldMenu2);
				OldMenu2 = "nix";
				}
			
			swapImgRestore();
			}
		level = -1;
		}

	
	function remember()
		{
		if (OldMenu != 'nix')
			{
			hide(OldMenu);
			if (level == 1 && OldMenu2 != 'nix')
				hide(OldMenu2);
			level = -1;
			}
		}


