//**************************************
// Title: Hex Man Menu
// Date: 11-Apr-2003 
//**************************************
function menuFormat( menu )
{
	this.init = function( menu )
	{
		this.menuItems = 
		[
			['HOME PAGE', 'jobeq_home_nl.html', "mainFrame"
			],
			['Filosofie', 'filo_nl.htm', "mainFrame",
				['Excellentie', 'excel_nl.htm', "mainFrame"],
			],
			['Oplossingen', 'opl_nl.htm', "mainFrame",
				['Rekrutering', 'recr_nl.htm', "mainFrame"],
				['Cases', 'case_nl.htm', "mainFrame"],				
			],
			['Producten', 'prod_nl.htm', "mainFrame",
				['COMET', 'comet_nl.htm', "mainFrame",
					['COMET/EQ', 'cometeq_nl.htm', "mainFrame"],
				],	
				['iWAM', 'iwam_nl.htm', "mainFrame"],
				['VSQ', 'vsq_nl.htm', "mainFrame"],
			],
			['Verkoop','sales_nl.htm',"mainFrame"],
			['Over JobEQ','about_nl.htm',"mainFrame"],
			['Contactinfo', 'contact_nl.htm', "mainFrame"],				
			['Demo', 'http://www.jobexec.com/PPElogin.php?LANver=NL', "_blank"],
			['HR Login', 'http://www.jobexec.com/HRElogin.php?LANver=NL&LOOK=2005', "_blank"],
		];
// Research
// Voorbeelden
	//-----------------------------------------------------------------------------
		this.left = 4;				// left position 
		this.top = 4;				// top position
		var TRANS = "";				// background color
		this.back = new menuBase( TRANS, 'cls'+menu.name+'_back');
		this.arrowShut  = "images/arrow_across.gif";	// arrow (collapsed)
		this.arrowOpen  = "images/arrow_down.gif";	// arrow (expanded)
		this.iE  = "images/blank.gif";		//(blank)
		this.Bw  = 14;					// size arrow (width)
		this.Bh  = 14;					// size arrow (height)		
		this.bulletA  = "images/silver_bullet.gif"; 	// bullet (web page link)
		this.bulletB  = "images/blank.gif";   		// bullet (Sellected Item)
		this.Fw  = 10;					// size bullet (width)
		this.Fh  = 10;					// size bullet (height)		
		this.ident = [0,12,24];	// indent for levels[0/*1st*/,16/*2nd*/,32/*3rd*/,...]
		this.Ew  = 0;					// (id nodes w/o children)
		this.nst = "menuNode";				// default style for all nodes		
		this.nstl = ["menuNode01","menuNode02","menuNode03"];
			//styles for each level of menu(default used for undefined levels)
		this.pg = 0;					// item pagging
		this.sp = 2;					// item spacing	
	}
	//------------------------------------------------------------------------------
	this.nstyle = function ( lvl )
	{
		return ( und(this.nstl[lvl]) ) ? this.nst : this.nstl[lvl];
	}
	this.idn = function( lvl )
	{
		var id = ( und(this.ident[lvl]) ) ? this.ident[0]*lvl : this.ident[lvl];
		return id;
	}
	this.init( menu );
}
//**********************************************************************************************
function hexmanMENU( )
{
	//--------------------------------------------------------------------------------------
	this.name = "jobEQ menu"; //name;
	this.fmt = new menuFormat( this );//format,
	newMenu = new Array();
	newMenu[this.name] = this;
	this.Nodes = new Array();
	this.rootNode = new menuNode(null, "", "", "", null);
	this.rootNode.treeView = this;
	this.selectedNode = null;
	this.maxWidth = 0;
	this.maxHeight = 0;
	this.ondraw = null;
	//--------------------------------------------------------------------------------------
	if(document.layers)
	{
		var nsPositive = true;
	}
	else
	{
		var nsPositive = false;
	}
	//--------------------------------------------------------------------------------------
	this.addNode = function (node)
	{
		var parentNode = node.parentNode;
		this.Nodes = this.Nodes.concat([node]);
		node.index = this.Nodes.length - 1;
		if (parentNode == null)
		{
			this.rootNode.children = this.rootNode.children.concat([node]);
		}
		else
		{
			parentNode.children = parentNode.children.concat([node]);
		}
		return node;
	}
	//--------------------------------------------------------------------------------------
	this.rebuildMenu = function()
	{
	      var s = "";
	      for (var count = 0; count < this.Nodes.length; count++)
	      {
		s += this.Nodes[count].init();
	      }
	      document.write(s);
	      for (var k = 0; k < this.Nodes.length; k++)
	      {
		if (nsPositive)
		{
		  this.Nodes[k].el = document.layers[this.Nodes[k].id()+"d"];
		  this.Nodes[k].nb = this.Nodes[k].el.document.images[this.Nodes[k].id()+"nb"];
		  this.Nodes[k].nf = this.Nodes[k].el.document.images[this.Nodes[k].id()+"nf"];
		} 
		else
		{
		   this.Nodes[k].el = document.all? document.all[this.Nodes[k].id()+"d"] : document.getElementById(this.Nodes[k].id()+"d");
		   this.Nodes[k].nb = document.all? document.all[this.Nodes[k].id()+"nb"] : document.getElementById(this.Nodes[k].id()+"nb");
		   this.Nodes[k].nf = document.all? document.all[this.Nodes[k].id()+"nf"] : document.getElementById(this.Nodes[k].id()+"nf");				
		}
	      }
	}
	//--------------------------------------------------------------------------------------
	this.draw = function()
	{
		this.currTop = this.fmt.top;
		this.maxHeight =0; 
		this.maxWidth=0;
		for( var count = 0; count < this.rootNode.children.length; count++ )
		{
			this.rootNode.children[count].draw(true);
		}
		this.fmt.back.resize(this.maxWidth-this.fmt.left, this.maxHeight-this.fmt.top);
		if( this.ondraw != null )
		{
			this.ondraw();
		}
	}
	//--------------------------------------------------------------------------------------
	this.updateImages = function ( node )
	{
		var srcArrow = node.expanded? this.fmt.arrowOpen : this.fmt.arrowShut;
		if( node.nb && node.nb.src != srcArrow )
		{
			node.nb.src = srcArrow;
		}
		var srcBullet = this.fmt.bulletB;
		if( node.nf && node.nf.src != srcBullet )
		{
			node.nf.src = node.hasChildren() ? srcBullet : this.fmt.bulletA;
		}
	}
	//--------------------------------------------------------------------------------------
	this.expandNode = function( index )
	{
		var node = this.Nodes[index];
		var pNode = node.parentNode ? node.parentNode : null;
		if( !und(node) && node.hasChildren() )
		{
		   node.expanded = !node.expanded;
		   this.updateImages(node);
		   if (!node.expanded)
		   {
		      node.hideChildren();
		   }
//If this section of code is commented out then sections will not colasps when others expand
//############################################################################################### 
		   //else 
		   //{
		      //for (var count = 0; count < this.Nodes.length; count++)
		      //{
			 //this.Nodes[count].show(false);
			 //if( this.Nodes[count] != node && this.Nodes[count].parentNode == pNode)
			 //{
				//this.Nodes[count].expanded = false;
				//this.updateImages(this.Nodes[count]);
			 //}
		      //}
		   //}
//############################################################################################### 
		this.draw();
		}
	}
	//--------------------------------------------------------------------------------------
	this.selectNode = function( index )
	{
		var node = this.Nodes[index];
		if( !und(node) )
		{
			this.selectedNode = node;
		}
		node.draw();
	}
	//--------------------------------------------------------------------------------------
	this.readNodes = function (nodes)
	{
		var ind = 0;
		var par = null;
		function readOne( nArray , tree)
		{
			if (und(nArray)) return;
			var text = nArray[0];
			var url = nArray[1] == null? "": nArray[1];
			var targ = nArray[2] == null? "": nArray[2];
			var node = tree.addNode(new menuNode(tree, par, text, url, targ))
			var count = 3;
			while( !und( nArray[count] ) )
			{
				par = node;
				readOne(nArray[count], tree);
				count++;
			}
		}
		if( und(nodes) || und(nodes[0]) || und(nodes[0][0]) )
		{
			return;
		}
		for( var count = 0; count < nodes.length; count++ )
		{
			par = null;
			readOne( nodes[count], this );
		}
	}
	//--------------------------------------------------------------------------------------
	this.init = function( )
	{
		this.readNodes( this.fmt.menuItems );
		this.rebuildMenu();
		this.draw();
	}
	this.init( );
}
//**********************************************************************************************
function menuNode( treeView, parentNode , text, url, target )
{
	//--------------------------------------------------------------------------------------
	this.index = -1;
	this.treeView = treeView;
	this.parentNode = parentNode;
	this.text = text;
	this.url = url;
	this.target = target;
	this.expanded = false;
	this.children = new Array();
	if( document.layers )
	{
		var nsPositive = true;
	}
	else
	{
		var nsPositive = false;
	}
	//--------------------------------------------------------------------------------------
	this.level = function( )
	{
		var node = this;
		var count = 0;
		while( node.parentNode != null )
		{
			count++;
			node = node.parentNode;
		}
		return count;
	}
	//--------------------------------------------------------------------------------------
	this.hasChildren = function()
	{
		return this.children.length > 0;
	}
	//--------------------------------------------------------------------------------------
	this.init = function()
	{
		var iString = "";
		if ( nsPositive ) 
		{
			iString = '<layer id="'+this.id()+'d" z-index = "'+this.index+10+'" visibility="hidden">'+this.getContent()+'</layer>';
		} 
		else 
		{
			iString = '<div id="'+this.id()+'d" style="position:absolute;visibility:hidden;z-index:'+this.index+10+';">'+this.getContent()+'</div>';
		}
		return iString;
	}
	//--------------------------------------------------------------------------------------
	this.getH = function()
	{
		return nsPositive ? this.el.clip.height : this.el.offsetHeight;
	}
    	//--------------------------------------------------------------------------------------
	this.getW = function()
	{
		return nsPositive ? this.el.clip.width : this.el.offsetWidth;
	}
	//--------------------------------------------------------------------------------------
	this.id = function()
	{
		return 'nt'+this.treeView.name+this.index;
	}
	//--------------------------------------------------------------------------------------
	this.getContent = function()
	{
		function bullet(node)
		{
			var img = node.treeView.fmt.bulletB
			var img = node.hasChildren() ? node.treeView.fmt.bulletB : node.treeView.fmt.bulletA; 

			var w = node.hasChildren() ? 0 : node.treeView.fmt.Fw;
			var h = node.hasChildren() ? 0 : node.treeView.fmt.Fh;

			return "<td valign=\"middle\" width=\""+w+"\"><img id=\""+node.id()+"nf\" name=\""+node.id()+"nf\" src=\"" + img + "\" width="+w+" height="+h+" border=0></td>\n";
		}
		function arrow(node)
		{
			
			var img = node.expanded ? node.treeView.fmt.arrowOpen : node.treeView.fmt.arrowShut;
			var w = node.treeView.fmt.Bw; 
			var h = node.treeView.fmt.Bh;
			return '<td valign=\"middle\" width="'+w+'"><a href="javascript:newMenu[\''+node.treeView.name+'\'].expandNode('+node.index+')"><img name=\''+node.id()+'nb\' id=\''+node.id()+'nb\' src="' + img + '" width="'+w+'" height="'+h+'" border=0></a></td>\n';
		}
		function blank(node, ww)
		{
			var img = node.treeView.fmt.iE;
			return "<td width=\""+ww+"\"><img src=\"" + img + "\" width="+ww+" height=1 border=0></td>\n"
		}
	
		var buildString = '';
		var ll = this.level();
		buildString += '<table cellpadding='+this.treeView.fmt.pg+' cellspacing='+this.treeView.fmt.sp+' border=0 class="cls'+this.treeView.name+'_back'+ll+'"><tr>';	
		var idn = this.treeView.fmt.idn(ll);		//indent
		if( idn > 0 )
		{
			buildString += blank( this, idn );
		}
		buildString += this.hasChildren()? arrow(this): blank(this, this.treeView.fmt.Ew);
		buildString += bullet( this );

		if ( this.url == "")
		{	
		   buildString += this.hasChildren()? '<td nowrap=\"1\"><a class="'+this.treeView.fmt.nstyle(ll)+'" href="javascript:newMenu[\''+this.treeView.name+'\'].expandNode('+this.index+')">'+this.text+'</a></td></tr></table>' : '<td nowrap=\"1\"><a class="'+this.treeView.fmt.nstyle(ll)+'" href="#">'+this.text+'</a></td></tr></table>';
		} 
		else 
		{
		   buildString += '<td nowrap=\"1\"><a class="'+this.treeView.fmt.nstyle(ll)+'" href="'+this.url+'" target="'+this.target+'" onclick="javascript:newMenu[\''+this.treeView.name+'\'].expandNode('+this.index+')">'+this.text+'</a></td></tr></table>';
		}
		return buildString;
	}
	//--------------------------------------------------------------------------------------
	this.moveTo = function( x, y )
	{
		if( nsPositive )
		{
			this.el.moveTo(x,y);
		}
		else
		{
			this.el.style.left = x;
			this.el.style.top = y;
		}
	}
	//--------------------------------------------------------------------------------------
	this.show = function( showing )
	{
		if( this.visible == showing )
		{
			return;
		}
		this.visible = showing;
		var vis = "";
		if( nsPositive )
		{
			var vis = (showing ? 'show' : 'hide');
		}
		else
		{ 
			var vis = (showing ? 'visible': 'hidden');
		}
		if( nsPositive )
		{
			this.el.visibility = vis;
		}
		else
		{
			this.el.style.visibility = vis;
		}
	}
	//--------------------------------------------------------------------------------------
	this.hideChildren = function()
	{
		this.show(false);
		for( var count = 0; count < this.children.length; count++ )
		{
			this.children[count].hideChildren();
		}
	}
	//--------------------------------------------------------------------------------------
	this.draw = function()
	{
		var pos = this.treeView.fmt.left;
		this.moveTo( this.treeView.fmt.left, this.treeView.currTop );
		if( pos+this.getW() > this.treeView.maxWidth )
		{
			this.treeView.maxWidth = pos+this.getW();
		}
		this.show(true);
		this.treeView.currTop += this.getH();
		if( this.treeView.currTop > this.treeView.maxHeight )
		{
			this.treeView.maxHeight = this.treeView.currTop;
		}
		if( this.expanded && this.hasChildren() )
		{
			for (var count = 0; count < this.children.length; count++)
			{
				this.children[count].draw();
			}
		}
	}
}
//**********************************************************************************************
function menuBase( color, name ) 
{
	//--------------------------------------------------------------------------------------
	this.name = name;
	this.color = color;
	if( document.layers )
	{
		var nsPositive = true;
	}
	else
	{
		var nsPositive = false;
	}
	//--------------------------------------------------------------------------------------
	this.resize = function(w,h)
	{
		if(nsPositive)
		{
			this.el.resizeTo(w,h);
		}
		else
		{
			this.el.style.width = w;
			this.el.style.height = h;
		}
	}
	//--------------------------------------------------------------------------------------
	this.init = function()
	{
		if(nsPositive)
		{
			var bgc = this.color == ""? "" : ' bgcolor="'+this.color+'" ';
			document.write('<layer '+bgc+' top="'+this.top+'" left="'+this.left+'" id="'+this.name+'" z-index="0">'+ '</layer>');this.el = document.layers[this.name];
		} 
		else 
		{
			var bgc = this.color == ""? "" : " background-color:"+this.color+";";
			document.write('<div id="'+this.name+'" style="'+bgc+'position:absolute;z-index:0;top:'+this.top+'px;left:'+this.left+'px">'+ '</div>');this.el = document.all? document.all[this.name] : document.getElementById(this.name);
		}
	}	
	this.init();
}
//**********************************************************************************************
function und( val ){ return typeof(val) == 'undefined'; }
window.oldCTOnLoad = window.onload;
//**********************************************************************************************
window.onload = function ()
{
	if(document.layers)
	{
		var nsPositive = true;
	}
	else
	{
		var nsPositive = false;
	}
	var agent = navigator.userAgent;
	var opera = agent.indexOf("Opera") > -1;
	if ( nsPositive || opera )
	{
		window.origWidth  = this.innerWidth;
		window.origHeight = this.innerHeight;
		if (opera && und(window.operaRH))
		{
			window.operaRH = 1;
			resizeHandler();
		}
	}
	if( window.oldCTOnLoad )
	{
		window.oldCTOnLoad();
	}
}
//**********************************************************************************************
function resizeHandler() 
{
	var agent = navigator.userAgent;
	var opera = agent.indexOf("Opera") > -1;
	if (this.innerWidth != window.origWidth || this.innerHeight != window.origHeight)
	{ 
		location.reload();
	}
	if ( opera )
	{
		setTimeout('resizeHandler()',500);
	}
}
if(document.layers)
{
	window.onresize = resizeHandler;
}

