/* left position */
function getAbs(cObj){
	position = new Object;
	position.left=0;
	while(cObj.offsetParent){
		position.left+= cObj.offsetLeft;
		cObj = cObj.offsetParent;
	}
	return position.left;
}

/* show/hide submenu */
function ShowMenu(srcObj, ids){
	if(document.getElementById(ids) == null){return;}
	if(srcObj.nodeName.toLowerCase() == 'a'){
		document.getElementById(ids).style.left = (getAbs(srcObj) - 10) + 'px';
	}
	document.getElementById(ids).style.display = '';
}

function HideMenu(srcObj, ids){
	if(document.getElementById(ids) == null){return;}
	document.getElementById(ids).style.display = 'none';
}


function NavMenu(ids ,active)// ids - tag-container
                             // active - string -> menuData[][][THIS]
{

	this.target = document.getElementById(ids);    // finding target tag for main menu
	this.sub_target = document.getElementById('sub_menu_container'); // finding target tag for sub menu
	this.data   = menuData;                        // localizing menu data array
	this.out    = '';                              // menu data for output stream
	this.sout   = '';                              // sub menu data for output stream
	
	/*
	main menu
	*/
	this.out   += '<table border="0" cellpadding="0" cellspacing="0">';
	this.out   += '<tr align="center" valign="middle">';
	for(y = 0; y < this.data.length; y++){

		var linkURL  = this.data[y][1];
		var linkTEXT = this.data[y][0];
		var linkID   = this.data[y][2];
		var activeClass = '';
		if(active != null && active == this.data[y][2]){
			activeClass = ' class="active"';
		}
		
		// gen main menu
		if(y == 0){                                             // if start
			this.out += '<td height="43" id="' + linkID + '"><a href="' + linkURL + '" ' + activeClass + ' onmouseover="ShowMenu(this, ' + "'s" + y + "'" + ')" onmouseout="HideMenu(this, ' + "'s" + y + "'" + ')">' + linkTEXT + '</a></td>';
			this.out += '<td width="2" valign="bottom"><img src="img/menu_separator.jpg" alt="" /></td>';
		} else if( y == this.data.length - 1){                  // if end
			this.out += '<td id="' + linkID + '"><a href="' + linkURL + '" ' + activeClass + ' onmouseover="ShowMenu(this, ' + "'s" + y + "'" + ')" onmouseout="HideMenu(this, ' + "'s" + y + "'" + ')">' + linkTEXT + '</a></td>';
		} else {                                                // in proccess
			this.out += '<td id="' + linkID + '"><a href="' + linkURL + '" ' + activeClass + ' onmouseover="ShowMenu(this, ' + "'s" + y + "'" + ')" onmouseout="HideMenu(this, ' + "'s" + y + "'" + ')">' + linkTEXT + '</a></td>';
			this.out += '<td width="2" valign="bottom"><img src="img/menu_separator.jpg" alt="" /></td>';
		}
		
		var len = this.data[y][3].length;
		if(len > 0){
			this.sout += '<table border="0" width="146" cellpadding="0" cellspacing="0" class="subMenu" id="s' + y + '" onmouseover="ShowMenu(this, ' + "'s" + y + "'" + ')" onmouseout="HideMenu(this, ' + "'s" + y + "'" + ')" style="display:none">';
			this.sout += '<tr><td height="5"></td></tr>';
			
			for(x = 0; x < len; x++){
				this.sout += '<tr align="left">';
				this.sout += '	<td><a href="'+ this.data[y][3][x][1] +'">'+ this.data[y][3][x][0] +'</a></td>';
				this.sout += '</tr>';
			}
			
			this.sout += '</table>';
		}

	}
	
	this.out += '</tr>';
	this.out += '</table>';

	this.sub_target.innerHTML = this.sout;
	this.target.innerHTML     = this.out;
	
}

/* tpl

<table border="0" cellpadding="0" cellspacing="0">
<tr align="center" valign="middle">
	<td height="43"><a href="#">home</a></td>
	<td width="2" valign="bottom"><img src="img/menu_separator.jpg" alt="" /></td>
	<td><a href="#">find a provider</a></td>
	<td width="2" valign="bottom"><img src="img/menu_separator.jpg" alt="" /></td>
	<td><a href="#">products &amp; services</a></td>
	<td width="2" valign="bottom"><img src="img/menu_separator.jpg" alt="" /></td>
	<td><a href="#">company</a></td>
	<td width="2" valign="bottom"><img src="img/menu_separator.jpg" alt="" /></td>
	<td><a href="#">contact us</a></td>
</tr>
</table>

*/