































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































// JavaScript Document

// define classes in bottom up hirarchy

function NTZsubMenu(Text,The_Link) {
	//alert('in NTZsubMenu');
	this.text = Text;
	this.the_link = The_Link; 
	
	// for debugging: display the sub-menu data into the HTML
	this.DumpSubMenu = function() {
		var str =   '------ Text: ' + this.text + '<br>';
		str = str + '------ Link: ' + this.the_link + '<br>';
		document.write(str);
	}
	
	this.ShowSubMenu = function() {
		//alert('in NTZsubMenu.ShowSubMenu');
		var str    =   '<a href="' + this.the_link + '">'+ this.text + '</a><br>';
		//alert(str);
//		document.write('<a href="about_info.htm">מידע כללי</a><br>');
		document.write(str);
		
	}
}

function NTZmenuItem(Img_Up,Img_Down,The_Link,Alt,ID_number,Item_Width,Item_Height,Sub_Menu_Width) {
	//alert('in NTZmenuItem 0');
	this.img_up         = Img_Up;
	this.img_down       = Img_Down;
	this.the_link       = The_Link;
	this.alt            = Alt;
	this.id             = 'NTZmenuItem'+ID_number; // DOM id
	this.item_width     = Item_Width;
	this.item_height    = Item_Height;
	this.sub_menu_width = Sub_Menu_Width;
	this.sub_menu_id    = null;
	this.currentSubMenu = 0;
	this.sub_menu       = new Array();
	
	// when no link is inserted use the #, to link to the current page 
	if (this.the_link=='') {
		this.the_link='#'
	}
	
	this.AddSubMenuItem = function(Text,The_Link) {
		//alert('in NTZmenuItem.AddSubMenuItem2');
		// since we have a sub-menu, we erase the link
		//this.the_link = '';
		// set a DOM id for the submenu
		this.sub_menu_id    = 'NTZmenuItem'+ID_number+'NTZsubMenu';
		this.sub_menu[this.currentSubMenu] = new NTZsubMenu(Text,The_Link);
		this.currentSubMenu++;
	}
	
	this.get_menu_item_id = function() {
		return(this.id);
	}
	
	this.get_sub_menu_id = function() {
		//alert('in get_sub_menu_id with sub_menu_id =' + this.sub_menu_id);
		if (this.currentSubMenu > 0) { // do we have a sub menu for this menu item?
			return(this.sub_menu_id);
		} else {
			return(null);
		}
	}
	
	// for debugging: display the menu item data into the HTML
	this.DumpMenuItem = function() {
		//alert('in NTZmenuItem.DumpMenuItem');
		var str   = '--- DOM ID: ' + this.id + '<br>';
		str = str + '--- Up image: ' + this.img_up + '<br>';
		str = str + '--- Down image: ' + this.img_down + '<br>';
		str = str + '--- Link: ' + this.the_link + '<br>';
		str = str + '--- Alt: ' + this.alt + '<br>';
		
		document.write(str);
		//alert('in NTZmenuItem.DumpMenuItem' + this.currentSubMenu);
		if (this.currentSubMenu > 0) { // do we have a sub menu for this menu item?
			document.write('--- sub menu DOM ID: ' + this.sub_menu_id + '<br>');;
			for (var j=0; j<this.currentSubMenu; j++) {
				this.sub_menu[j].DumpSubMenu();
			}
		}
	}
	
	// when Active is true, the onMousOut image is img_down
	// when Active is false, the onMousOut image is img_up
	this.ShowMenuItem = function(Active) {
		//alert('in NTZmenuItem.ShowMenuItem');
		var str   ='<A href="' + this.the_link + '"';
		str = str +' onMouseOver="NTZchangeImages(\u0027'+ this.id +'\u0027, \u0027'+this.img_down+'\u0027);'; 
		if (this.currentSubMenu > 0) { // do we have a sub menu for this menu item?
			str = str + ' NTZ_show(\u0027'+ this.sub_menu_id +'\u0027);"';
		} else {
			str = str + ' return true;"';
		}
		//document.write('onMouseOver="NTZchangeImages(\u0027index\u0027, \u0027images/menu_index_o.gif\u0027); NTZ_show(\u0027about\u0027);"');
		if (Active) {
			str = str +' onMouseOut ="NTZchangeImages(\u0027'+ this.id +'\u0027, \u0027'+this.img_down+'\u0027);';
		} else {
			str = str +' onMouseOut ="NTZchangeImages(\u0027'+ this.id +'\u0027, \u0027'+this.img_up+'\u0027);';
		}
		if (this.currentSubMenu > 0) { // do we have a sub menu for this menu item?
			str = str + ' NTZ_timed_hideall(NTZ_menu_out_delay);"';
		} else {
			str = str + ' return true;"';
		}
		if (Active) {
			str = str + '> <IMG id="'+ this.id +'" src="'+this.img_down+'" width='+ this.item_width +' height='+ this.item_height +' border=0 alt="'+this.alt+'"></A>';
		} else {
			str = str + '> <IMG id="'+ this.id +'" src="'+this.img_up+'" width='+ this.item_width +' height='+ this.item_height +' border=0 alt="'+this.alt+'"></A>';
		}
		//document.write('onMouseOut ="NTZchangeImages(\u0027index\u0027, \u0027images/menu_index.gif\u0027); NTZ_timed_hideall(NTZ_menu_out_delay);"> <IMG id="index" src="images/menu_index.gif" width=160 height=26 border=0 alt="עמוד הבית"></A>');
		//alert(str);
		document.write(str);
		
	}
	
	// writes the HTML for the sub menu div
	this.ShowSubMenu = function() { 
		if (this.currentSubMenu > 0) { // do we have a sub menu for this menu item?
			//alert('in NTZmenuItem.ShowSubMenu');
//			document.write('<div id="'+ this.sub_menu_id +'" style="position:relative; visibility:hidden;  width:10px; height:10px; left: -160px; top: -310px" onMouseOver="NTZ_clear_timer()" onMouseOut="NTZ_timed_hideall(NTZ_submenu_out_delay)">');
			document.write('<div id="'+ this.sub_menu_id +'" style="position:absolute; visibility:hidden;  width:10px; height:10px; left: 10px; top: 10px" onMouseOver="NTZ_clear_timer()" onMouseOut="NTZ_timed_hideall(NTZ_submenu_out_delay)">');
			document.write('<table width="10" border="1" bordercolor="#103E7A" cellspacing="0" cellpadding="5" bgcolor="#B7C3E7">');
			document.write('<tr><td class="openmenu"><p dir="rtl" lang="he"><font size="-1">');
					
			// all but the last
			for (var j=0; j<this.currentSubMenu-1; j++) {
				this.sub_menu[j].ShowSubMenu();
				document.write('<img src="images/hr.gif" width='+ this.sub_menu_width+'><br>');
			}
			// the last
			this.sub_menu[this.currentSubMenu-1].ShowSubMenu();
			if (this.currentSubMenu == 1) {
				document.write('<img src="images/hr.gif" width='+ this.sub_menu_width+'><br>');				
			}
			document.write('</font></p></td></tr></table></div>');
		}
	}

}

// a global var with the menu object. it is used by the hide_all function and to check we have only one instance 
// of the menu
var NTZGLOBALMENU = null;

var NTZ_menu_out_delay = 100; //    delay between mouseout of a menu and clearing the submenu
var NTZ_submenu_out_delay = 500; //  delay between mouseout of a submenu and clearing the submenu

function NTZmenu(Item_Width,Item_Height,Sub_Menu_Width,Menu_Out_Delay,Sub_Menu_Out_Delay) {
	
	if (NTZGLOBALMENU) {
		alert('Sorry, we can have only one instance of the NTZ menu');
		return ;
	}
	
	if (Menu_Out_Delay != undefined) { NTZ_menu_out_delay = Menu_Out_Delay;}
	if (Sub_Menu_Out_Delay != undefined) { NTZ_submenu_out_delay = Sub_Menu_Out_Delay;}
	
	this.activeItem = null; // to insicate which menu item is active so it will not change image on mouse over and out
	
	this.item_width     = Item_Width;
	this.item_height    = Item_Height;
	this.sub_menu_width = Sub_Menu_Width;
	
	//alert('in NTZmenu');
	this.currentMenuItem = 0;
	this.menuItems = new Array();
	
	this.AddMenuItem = function(Img_Up,Img_Down,The_Link,Alt) {
		//alert('in NTZmenu.AddMenuItem item no. ' + this.currentMenuItem);
		this.menuItems[this.currentMenuItem] = new NTZmenuItem(Img_Up,Img_Down,The_Link,Alt,this.currentMenuItem,this.item_width,this.item_height,this.sub_menu_width);
		this.currentMenuItem++;
	}
	
	// adding the sub_menu to the current 
	this.AddSubMenuItem = function(Text,The_Link) {
		//alert('in NTZmenu.AddSubMenuItem ' + this.currentMenuItem);
		if (this.currentMenuItem > 0) {
			this.menuItems[this.currentMenuItem-1].AddSubMenuItem(Text,The_Link);
		} else {
			var str = 'You must add a menu item before addig a sub-menu item, so this sub-menu item is not getting in:   ';
			str = str + Text + ' ' + The_Link;
			alert(str);
		}
	}
	
	this.GetNumMenuItems = function(){
		return(this.currentMenuItem);
	}
	
	
	
	// get the id of the sub-menu i (the sub-menu of menu item i) or return null
	this.GetSubMenu = function(i){
		//alert('in GetSubMenu ' + i); 
		if (i < this.currentMenuItem) { // do we have a menu item i?
			//alert(i + ' < ' + this.currentMenuItem);
			return(this.menuItems[i].get_sub_menu_id());
		} else {
			return(null);
		}
	}
	
	// for debugging: display the menu data into the HTML
	this.DumpMenu = function(){
		document.write('<br>'+'The menu content:' + '<br>');
		//alert(this.currentMenuItem);
		if (this.currentMenuItem > 0) {
			for (var i=0; i<this.currentMenuItem; i++) {
				document.write('item ' + i + '<br>');
				this.menuItems[i].DumpMenuItem();
			}
		}
	}
	
	// do the magic!  -- put the menu as HTML, ready for action.
	this.ShowMenu = function(ActiveItem){
		
		this.activeItem = ActiveItem;
		
		document.write('<table width="'+ this.item_width +'" border="0" cellpadding="0" cellspacing="0" align="right">');
		//alert(this.currentMenuItem);
		// do we have menu items to show?
		if (this.currentMenuItem > 0) {
			
			// for every menu item
			for (var i=0; i<this.currentMenuItem; i++) {
				document.write('<tr><td>');
				if (ActiveItem == i+1) { // the first menu item's number is 0
					this.menuItems[i].ShowMenuItem(true);
				} else {
					this.menuItems[i].ShowMenuItem(false);
				}
				//alert(this.menuItems[i].id);
				document.write('</td></tr>');
			}
	
			// and for every submenu
			for (var i=0; i<this.currentMenuItem; i++) {
				document.write('<tr><td>');
				this.menuItems[i].ShowSubMenu();
				document.write('</td></tr>');
			}	
		}
		
		document.write('</table>');
	}

	// set the global
	NTZGLOBALMENU = this;
}

// the sub-menus are positioned relative to their menu items.
// we do not want the sub-menu divs to have relative position style since this makes 
// the table they are in longer. Instead we use absolute positioning of the sub-menu divs  
// but then we need to know the absolute positions of their menu items. This is possible to do only after the page 
// is loaded! (in IE javascript is perfored prior to full HTML display so before that all positioning vales are zero)
// This function is called by the onload or onresize events, see below
function NTZmenu_position() {
	for (var i=0; i<NTZGLOBALMENU.GetNumMenuItems(); i++) {
		
		// do we have a sub menu?
		var sub_menu_id = NTZGLOBALMENU.GetSubMenu(i);
		if (sub_menu_id) {
			//alert(sub_menu_id);

			// get the position of the menu item
			var xpos = NTZfindPosX(NTZgetTheElementID(NTZGLOBALMENU.menuItems[i].id));
			var ypos = NTZfindPosY(NTZgetTheElementID(NTZGLOBALMENU.menuItems[i].id));
			//alert(NTZGLOBALMENU.menuItems[i].id + '    x: ' + xpos + '  y:' + ypos)
			
			var sub_menu = NTZgetTheElementID(sub_menu_id);
			// now position the sub-menu relative to its menu item
			sub_menu.style.top = (ypos-1) + 'px';
			sub_menu.style.left = (xpos-(NTZGLOBALMENU.sub_menu_width+10)) + 'px';
		}
	}
}

function NTZaddEvent(obj, evType, fn) { 
	if (obj.addEventListener) { 
		obj.addEventListener(evType, fn, false); 
	return true; 
	} else if (obj.attachEvent) { 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

// the NTZmenu_position function will be called on the load and resize events
NTZaddEvent(window, 'load', NTZmenu_position);
NTZaddEvent(window, 'resize', NTZmenu_position);


// what browser are we using?
NTZ_ns4=(document.layers)?true:false; 
NTZ_ie4=(document.all)?true:false;
NTZ_ns6=(!document.all&&document.getElementById)?true:false;

//alert(NTZ_ns4);
//alert(NTZ_ie4);
//alert(NTZ_ns6);

var NTZ_timer = null;

//var NTZMENUPOSITIONED = false;

// hides all submenues of the menu NTZGLOBALMENU
function NTZ_hideall() {
	//alert('in NTZ_hideall');
	//if (!NTZMENUPOSITIONED) { // in case the menu is not positioned yet by the onload event
		NTZmenu_position();
	//	NTZMENUPOSITIONED = true;
	//}
	// clear current timer
	NTZ_clear_timer();
	//	alert(NTZGLOBALMENU.GetNumMenuItems());

	// hide all sub menu of the only menu we have 
	for (i=0; i<NTZGLOBALMENU.GetNumMenuItems(); i++) {
		var ToHide = NTZGLOBALMENU.GetSubMenu(i);
		//alert(ToHide);
		if (ToHide) {
			NTZ_hide(ToHide);
		}
	}
	//alert('out of NTZ_hideall');
}

function NTZ_clear_timer() {
	//alert('in NTZ_clear_timer');
	
	// clear current timer
	if (NTZ_timer) {
		clearTimeout(NTZ_timer);
		}
	NTZ_timer = null;
}

function NTZ_timed_hideall(NTZ_close_time) {
	//alert('in NTZ_timed_hideall');
	
	// clear current timer
	NTZ_clear_timer();
	// and set a new one		
	NTZ_timer=setTimeout('NTZ_hideall()',NTZ_close_time);
}

function NTZ_show(name) {
	// clear current timer
	NTZ_clear_timer();
    // hide previous sub-menu
	NTZ_hideall();
	// show the sub-menu
	if (NTZ_ie4) 		{
		document.all[name].style.visibility='visible';		
	}
	else if (NTZ_ns4) 	{
		document.layers[name].visibility='show';		
	}
	else if (NTZ_ns6) 	{
		document.getElementById(name).style.visibility = "visible";		
	}
	return true;
}



function NTZ_hide(name) {
       // hide the sub-menu
	if (NTZ_ie4) 		{
		document.all[name].style.visibility='hidden';
	}
	else if (NTZ_ns4) 	{
		document.layers[name].visibility='hide';
	}
	else if (NTZ_ns6) 	{
		document.getElementById(name).style.visibility = "hidden";
	}
	return true;
}

// using DOM's get element by ID, 
// note also the use of IMG ID instead of IMG name, in the HTML that defines the image below 
function NTZchangeImages() {
	if (document.images) {
		for (var i=0; i<NTZchangeImages.arguments.length; i+=2) {
			theImg=document.getElementById(NTZchangeImages.arguments[i]);
			theImg.setAttribute("src",NTZchangeImages.arguments[i+1]);
		}
	}
}

function NTZgetTheElementID() {
		for (var i=0; i<NTZgetTheElementID.arguments.length; i+=2) {
			return(document.getElementById(NTZgetTheElementID.arguments[i]));
	}
}


function NTZfindPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function NTZfindPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}




