function us_menu_nopen (url)
{
	window.open (url,"", "");
}

var IE = document.all?true:false;
if (!IE)
{
        window.captureEvents(Event.MOUSEMOVE);
//        window.captureEvents(Event.MOUSEDOWN);
}
window.onmousemove = adjustMenus;
//window.onmousedown = adjustMenus;

function adjustMenus(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0;}
  if (tempY < 0){tempY = 0;}
  checkMouse(tempX,tempY);

  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
/*  document.Show.MouseX.value = tempX;
  document.Show.MouseY.value = tempY;*/
  return true;
}

var level1 = null;
var level2 = null;
var level3 = null;
var level4 = null;
var level5 = null;


var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
displacement=0;
if ( browser == "Microsoft Internet Explorer" )
	displacement=2;

function SubMenu (_divName,_parent,_parentSubMenu,_className,_displayType,_css,_bp,_rtl,_horizontal_offset,_vertical_offset,_add_parent_bottom,_add_parent_top_offset,_include_calculated_top,_opera_horizontal_offset,_opera_vertical_offset,_opera_add_parent_bottom,_opera_add_parent_top_offset,_opera_include_calculated_top,_ie_horizontal_offset,_ie_vertical_offset,_ie_add_parent_bottom,_ie_add_parent_top_offset,_ie_include_calculated_top,_level)
{
	this.divName = _divName;
	this.parent = _parent;
	this.parentSubMenu = _parentSubMenu;
	this.className = _className;
	this.displayType = _displayType;
	this.css = _css;
	this.mouseOver = false;
	this.members = new Array ();
	this.membersCount = 0;
	this.nextHeightStart = document.getElementById(this.divName).style.top;
	this.bp=_bp;
	this.rtl=_rtl;
	this.horizontal_offset=_horizontal_offset;
	this.vertical_offset=_vertical_offset;
	this.add_parent_bottom=_add_parent_bottom;
	this.add_parent_top_offset=_add_parent_top_offset;
	this.include_calculated_top=_include_calculated_top;
	this.opera_horizontal_offset=_opera_horizontal_offset;
	this.opera_vertical_offset=_opera_vertical_offset;
	this.opera_add_parent_bottom=_opera_add_parent_bottom;
	this.opera_add_parent_top_offset=_opera_add_parent_top_offset;
	this.opera_include_calculated_top=_opera_include_calculated_top;
	this.ie_horizontal_offset=_ie_horizontal_offset;
	this.ie_vertical_offset=_ie_vertical_offset;
	this.ie_add_parent_bottom=_ie_add_parent_bottom;
	this.ie_add_parent_top_offset=_ie_add_parent_top_offset;
	this.ie_include_calculated_top=_ie_include_calculated_top;
	this.level = _level;
	document.getElementById(this.divName).style.visibility = "hidden";
	
}


SubMenu.prototype.parent;
SubMenu.prototype.parentSubMenu;
SubMenu.prototype.divName;
SubMenu.prototype.className;
SubMenu.prototype.mouseOver;
SubMenu.prototype.displayType;
SubMenu.prototype.css;
SubMenu.prototype.members;
SubMenu.prototype.membersCount;
SubMenu.prototype.nextHeightStart;
SubMenu.prototype.bp;
SubMenu.prototype.rtl;
SubMenu.prototype.horizontal_offset;
SubMenu.prototype.vertical_offset;
SubMenu.prototype.add_parent_bottom;
SubMenu.prototype.add_parent_top_offset;
SubMenu.prototype.include_calculated_top;
SubMenu.prototype.opera_horizontal_offset;
SubMenu.prototype.opera_vertical_offset;
SubMenu.prototype.opera_add_parent_bottom;
SubMenu.prototype.opera_add_parent_top_offset;
SubMenu.prototype.opera_include_calculated_top;
SubMenu.prototype.ie_horizontal_offset;
SubMenu.prototype.ie_vertical_offset;
SubMenu.prototype.ie_add_parent_bottom;
SubMenu.prototype.ie_add_parent_top_offset;
SubMenu.prototype.ie_include_calculated_top;
SubMenu.prototype.level;


SubMenu.prototype.addMember = function (_member) {
	this.members [this.membersCount] = _member;
	this.members[this.membersCount].setParentSubMenu (this);
	this.membersCount ++;
}	

SubMenu.prototype.adjustMembers = function () {
	var r = this.getRegion();
	var h = r.top;
	var i = 0;
	for ( i = 0 ; i < this.membersCount ; i ++ )
	{
		r = this.members[i].getRegion();
		document.getElementById(this.members[i].getDivName()).style.top = h+'px';
		h += r.bottom-r.top;
		document.getElementById(this.members[i].getDivName()).style.bottom = h+'px';
	}
}

SubMenu.prototype.getMemberTop = function (_divName) {
	var r = this.getRegion();
	var h = r.top;
	var i = 0;
	for ( i = 0 ; i < this.membersCount ; i ++ )
	{
		if ( this.members[i].getDivName() == _divName) return h;
		r = this.members[i].getRegion();
		h += (r.bottom-r.top);
	}
	return -1;
}
SubMenu.prototype.clearOtherMembers = function (_divName) {
	var i = 0;
	for ( i = 0 ; i < this.membersCount ; i ++ )
		if ( this.members[i].getDivName() != _divName) this.members[i].hide(false);
}
SubMenu.prototype.clearSubMenus = function () {
	var i = 0;
	for ( i = 0 ; i < this.membersCount ; i ++ )
	{
		var s = this.members[i].getSubMenu();
		if ( s != null) s.clearSubMenus();
		this.hideAnyway();	
	}
}
SubMenu.prototype.checkCoordinates = function (x,y) {
	var myleft = document.getElementById(this.divName).style.left;
	var myright = document.getElementById(this.divName).style.right;
	var mytop = document.getElementById(this.divName).offsetTop;
	var r = this.getRegion();
	var mybottom = r.bottom+mytop;
	if ( x >= r.left && x <= r.right && y >= mytop && y <= mybottom ) return true;
	else 
	{
		var i = 0;
		for ( i = 0 ; i < this.membersCount ; i ++ )
		{
			var s = this.members[i].getSubMenu();
			if ( s != null) 
				if (s.checkCoordinates(x,y)) return true;
		}
	}
	return false;
}

SubMenu.prototype.getRegion = function () {
	return YAHOO.util.Dom.getRegion(document.getElementById(this.divName));
}	
SubMenu.prototype.onMouseOver = function () {
	if ( ! SubMenu.prototype.mouseOver ) SubMenu.prototype.mouseOver = !SubMenu.prototype.mouseOver;
	this.render();
}
SubMenu.prototype.onMouseOut = function () {
	if ( SubMenu.prototype.mouseOver ) SubMenu.prototype.mouseOver = !SubMenu.prototype.mouseOver;
	this.hide(true);
}
SubMenu.prototype.render = function () {

	if ( this.level == 1 )
 	{
 		if ( level1 != this )
 		{
 			if ( level1 != null ) 
			{
				level1.hideSimple();
				level1.parent.hideSimple();
//				if ( level2 != null ) level2.hideSimple();
//				if ( level3 != null ) level3.hideSimple();
//				if ( level4 != null ) level4.hideSimple();
			}
 			level1 = this;
 		}
 	}

	if ( this.level == 2 )
	{
		if ( level2 != this )
		{
			if ( level2 != null )
			{
				level2.hideSimple();
				level2.parent.hideSimple();
//				if ( level3 != null ) level3.hideSimple();
//				if ( level4 != null ) level4.hideSimple();
			}
			level2 = this;
		}
	}

	if ( this.level == 3 )
 	{
 		if ( level3 != this )
 		{
 			if ( level3 != null ) 
			{
				level3.hideSimple();
				level3.parent.hideSimple();
//				if ( level4 != null ) level4.hideSimple();
			}
 			level3 = this;
 		}
 	}
 
 	if ( this.level == 4 )
 	{
 		if ( level4 != this )
 		{
 			if ( level4 != null ) 
			{
				level4.hideSimple();
				level4.parent.hideSimple();
			}
 			level4 = this;
 		}
 	}

	if ( this.parent != null ) 
	{
		this.parent.renderBySubmenu(true);
		region = this.parent.getRegion ();
		if ( this.displayType == 0 )
		{
			if ( browser == "Opera" ) 
			{
				offsetTop = document.getElementById(this.parent.getDivName()).offsetTop;

				if ( this.rtl == 0 )
				document.getElementById(this.divName).style.left = (region.left-displacement+this.opera_horizontal_offset) + 'px';
				else 
				{
					var smRegion = this.getRegion ();
					var pRegion = this.parent.getRegion();
					delta = Math.abs((region.right-region.left)-document.getElementById(this.divName).offsetWidth);
					if (smRegion.right-smRegion.left < pRegion.right-pRegion.left )
						document.getElementById(this.divName).style.left = (region.left-displacement-this.opera_horizontal_offset+delta) + 'px';
					else
						document.getElementById(this.divName).style.left = (region.left-displacement-this.opera_horizontal_offset-delta) + 'px';
				}

//				document.getElementById(this.divName).style.left = (region.left-displacement+this.opera_horizontal_offset) + 'px';
				var style_top = 0;
				if (this.opera_add_parent_bottom == 1 ) style_top += region.bottom;
				if (this.opera_add_parent_top_offset == 1) style_top += offsetTop;
				style_top = style_top - displacement + this.opera_vertical_offset;
				document.getElementById(this.divName).style.top =  style_top + 'px';
			}
			else if ( browser == "Microsoft Internet Explorer" )
			{
				offsetTop = 0;
				if ( this.rtl == 0 )
					document.getElementById(this.divName).style.left = (region.left-displacement+this.ie_horizontal_offset) + 'px';
				else 
				{
					var smRegion = this.getRegion ();
					var pRegion = this.parent.getRegion();
					var myLeft = region.left;
					delta = Math.abs((region.right-region.left)-document.getElementById(this.divName).offsetWidth);
					if (smRegion.right-smRegion.left < pRegion.right-pRegion.left )
						document.getElementById(this.divName).style.left = (myLeft-this.ie_horizontal_offset+delta) + 'px';
					else
						document.getElementById(this.divName).style.left = (myLeft-this.ie_horizontal_offset-delta) + 'px';
				}
				var style_top = 0;
				if (this.ie_add_parent_bottom == 1 ) style_top += region.bottom;
				if (this.ie_add_parent_top_offset == 1) style_top += offsetTop;
				style_top = style_top - displacement + this.ie_vertical_offset;
				document.getElementById(this.divName).style.top =  style_top + 'px';
			}
			else
			{
				offsetTop = 0;
//				document.getElementById(this.divName).style.left = (region.left-displacement+this.horizontal_offset) + 'px';
				if ( this.rtl == 0 )
					document.getElementById(this.divName).style.left = (region.left-displacement+this.horizontal_offset) + 'px';
				else 
				{
					var smRegion = this.getRegion ();
					var pRegion = this.parent.getRegion();
					var myLeft = region.left;
					delta = Math.abs((region.right-region.left)-document.getElementById(this.divName).offsetWidth);
					if (smRegion.right-smRegion.left < pRegion.right-pRegion.left )
						document.getElementById(this.divName).style.left = (myLeft-this.horizontal_offset+delta) + 'px';
					else
						document.getElementById(this.divName).style.left = (myLeft-this.horizontal_offset-delta) + 'px';
				}
				var style_top = 0;
				if (this.add_parent_bottom == 1 ) style_top += region.bottom;
				if (this.add_parent_top_offset == 1) style_top += offsetTop;
				style_top = style_top - displacement + this.vertical_offset;
				document.getElementById(this.divName).style.top =  style_top + 'px';
			}

		}
		else
		{
			if ( this.parentSubMenu != null ) calculatedTop = this.parentSubMenu.getMemberTop (this.parent.getDivName());
			else calculatedTop = region.top;
			if ( browser == "Opera" ) 
			{
				offsetTop = document.getElementById(this.parent.getDivName()).offsetTop;
//				document.getElementById(this.divName).style.left = (region.right-displacement+this.opera_horizontal_offset) + 'px';

				if ( this.rtl == 0 )
					document.getElementById(this.divName).style.left = (region.right-displacement+this.opera_horizontal_offset) + 'px';
				else
				{
					delta = document.getElementById(this.divName).offsetWidth;
					document.getElementById(this.divName).style.left = (region.left-displacement+this.opera_horizontal_offset-delta) + 'px';

				}

				var style_top = 0;
				if (this.opera_include_calculated_top == 1 ) style_top += calculatedTop;
				if (this.opera_add_parent_top_offset == 1) style_top += offsetTop;
				style_top = style_top - displacement + this.opera_vertical_offset;
				document.getElementById(this.divName).style.top = style_top + 'px';
			}
			else  if ( browser == "Microsoft Internet Explorer" )
			{
				offsetTop = 0;
//				document.getElementById(this.divName).style.left = (region.right-displacement+this.horizontal_offset) + 'px';
				if ( this.rtl == 0 )
					document.getElementById(this.divName).style.left = (region.right-displacement+this.ie_horizontal_offset) + 'px';
				else
				{
					delta = document.getElementById(this.divName).offsetWidth;
					document.getElementById(this.divName).style.left = (region.left-displacement+this.ie_horizontal_offset-delta) + 'px';
				}

				var style_top = 0;
				if (this.include_calculated_top == 1 ) style_top += calculatedTop;
				if (this.add_parent_top_offset == 1) style_top += offsetTop;
				style_top = style_top - displacement + this.ie_vertical_offset;
				document.getElementById(this.divName).style.top = style_top + 'px';
			}

			else
			{
				offsetTop = 0;
//				document.getElementById(this.divName).style.left = (region.right-displacement+this.horizontal_offset) + 'px';
				if ( this.rtl == 0 )
					document.getElementById(this.divName).style.left = (region.right-displacement+this.horizontal_offset) + 'px';
				else
				{
					delta = document.getElementById(this.divName).offsetWidth;
					document.getElementById(this.divName).style.left = (region.left-displacement+this.horizontal_offset-delta) + 'px';
				}

				var style_top = 0;
				if (this.include_calculated_top == 1 ) style_top += calculatedTop;
				if (this.add_parent_top_offset == 1) style_top += offsetTop;
				style_top = style_top - displacement + this.vertical_offset;
				document.getElementById(this.divName).style.top = style_top + 'px';
			}
		}
	}
	document.getElementById(this.divName).style.visibility = "visible";
}
function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}

SubMenu.prototype.hide = function ( _wait) {
	if ( !SubMenu.prototype.mouseOver )
	{
		if ( !_wait ) 
		{
			if ( this.parent != null )
			{
//				pausecomp(100);
				if ( this.parent.isShown() && this.parent.getRenderBySubmenu())
				{
					document.getElementById(this.divName).style.visibility = "hidden";
					if ( this.parent != null ) this.parent.hide(true);
					if ( this.parentSubMenu != null ) this.parentSubMenu.hide(false);
				}
			}
			else
			{
				document.getElementById(this.divName).style.visibility = "hidden";
				if ( this.parent != null ) this.parent.hide(true);
				if ( this.parentSubMenu != null ) this.parentSubMenu.hide(false);
			}
		}
		else setTimeout(this.className+'.hide(false)',500);
	}
}
SubMenu.prototype.hideAnyway = function () {
	document.getElementById(this.divName).style.visibility = "hidden";
	if ( this.parentSubMenu != null ) this.parentSubMenu.hide(false);
}
SubMenu.prototype.hideSimple = function () {
	document.getElementById(this.divName).style.visibility = "hidden";
}

function RootMenu (_divName,_parent,_display,_displayHighlight,_url,_newwin,_displayType,_css,_cssHighlight,_root)
{
	this.divName = _divName;
	this.parent = _parent;
	this.subMenu = null;
	this.displayType = _displayType;
	this.url = _url ;
	this.newwin = _newwin ;
	this.root = _root;
	if ( this.displayType == 1 )
	{
		this.preload = new Image();
		this.preloadHighlight = new Image();
		this.preload.src= _display;
		this.preloadHighlight.src= _displayHighlight;
		this.display ="<img src='"+ _display+"' border=0 >";
		this.displayHighlight = "<img src='"+_displayHighlight+"' border=0 >";
	}
	else
	{
		this.display = _display;
		this.displayHighlight = _displayHighlight;
		this.css = _css;
		this.cssHighlight = _cssHighlight;
	}
	document.getElementById(this.divName).innerHTML = this.display;
	this.parentSubMenu != null;
	this.submenuAskedForRender = false;
	this.shown=true;
	this.hide(false);
	
}


RootMenu.prototype.parent;
RootMenu.prototype.parentSubMenu;
RootMenu.prototype.divName;
RootMenu.prototype.display;
RootMenu.prototype.displayHighlight;
RootMenu.prototype.url;
RootMenu.prototype.newwin;
RootMenu.prototype.displayType;
RootMenu.prototype.preload;
RootMenu.prototype.preloadHighlight;
RootMenu.prototype.css;
RootMenu.prototype.cssHighLight;
RootMenu.prototype.shown;
RootMenu.prototype.subMenu;
RootMenu.prototype.root;
RootMenu.prototype.submenuAskedForRender;

RootMenu.prototype.setDisplay= function  (_display,_displayHighlight,_css,_cssHighlight)
{
	if ( this.displayType == 1 )
	{
		this.preload = new Image();
		this.preloadHighlight = new Image();
		this.preload.src= _display;
		this.preloadHighlight.src= _displayHighlight;
		this.display ="<img src='"+ _display+"' border=0 >";
		this.displayHighlight = "<img src='"+_displayHighlight+"' border=0 >";
	}
	else
	{
		this.display = _display;
		this.displayHighlight = _displayHighlight;
		this.css = _css;
		this.cssHighlight = _cssHighlight;
	}
	document.getElementById(this.divName).innerHTML = this.display;	
}

RootMenu.prototype.setSubMenu = function (_subMenu) {
	this.subMenu = _subMenu;
}
RootMenu.prototype.getSubMenu = function () {
	return this.subMenu;
}
RootMenu.prototype.setParentSubMenu = function (_subMenu) {
	this.parentSubMenu = _subMenu;
}

RootMenu.prototype.getDivName = function (_subMenu) {
	return this.divName;
}

RootMenu.prototype.getRenderBySubmenu = function () 
{
	return this.submenuAskedForRender;
}
RootMenu.prototype.isShown = function () 
{
	return this.shown;
}
RootMenu.prototype.renderBySubmenu = function (_backward)
{
	this.render(_backward);
	this.submenuAskedForRender = true;
}

RootMenu.prototype.render = function (_backward) {
	if (this.root == 1) resetAll(this.divName);
	if ( this.parent != null ) this.parent.render();
	if ( !_backward && this.subMenu != null ) this.subMenu.render(true);
	else if ( this.subMenu == null && this.parentSubMenu != null ) this.parentSubMenu.clearOtherMembers(this.divName);
	if ( this.shown == false )
	{
		 if ( this.displayType==0 || ( this.displayType== 1 &&  this.displayHighlight != this.display))
		document.getElementById(this.divName).innerHTML = this.displayHighlight;
		if ( this.displayType==0 && this.cssHightlight!="" ) document.getElementById(this.divName).className = this.cssHighlight;
		document.body.style.cursor = 'hand';
		this.shown=true;
	}
	this.submenuAskedForRender = false;
}
RootMenu.prototype.hide = function (_backward) {
	if ( this.shown == true )
	{
		 if ( this.displayType==0 || ( this.displayType== 1 &&  this.displayHighlight != this.display))
		document.getElementById(this.divName).innerHTML = this.display;
		if ( this.displayType==0 && this.css!="" ) document.getElementById(this.divName).className = this.css;
		document.body.style.cursor = 'default';
		this.shown=false;
	}
	if ( !_backward && this.subMenu != null ) this.subMenu.hideAnyway();
	if ( this.parent != null ) this.parent.hide();
}
RootMenu.prototype.hideSimple = function () {
 	if ( this.shown == true )
 	{
 		 if ( this.displayType==0 || ( this.displayType== 1 &&  this.displayHighlight != this.display))
 		document.getElementById(this.divName).innerHTML = this.display;
 		if ( this.displayType==0 && this.css!="" ) document.getElementById(this.divName).className = this.css;
 		document.body.style.cursor = 'default';
 		this.shown=false;
 	}
 }

RootMenu.prototype.doAction = function () {
	if ( this.url != "" ) 
	{
		if ( this.newwin == 1 ) us_menu_nopen (this.url);
		else document.location = this.url;
	}

}
RootMenu.prototype.getRegion = function () {
	return YAHOO.util.Dom.getRegion(document.getElementById(this.divName));
}
RootMenu.prototype.clearAll = function () {
	this.hide(true);
	if ( this.subMenu != null ) this.subMenu.clearSubMenus();
}
RootMenu.prototype.checkCoordinates = function (x,y) {
	var myleft = document.getElementById(this.divName).style.left;
	var myright = document.getElementById(this.divName).style.right;
	var mytop = document.getElementById(this.divName).offsetTop;
	var r = this.getRegion();
	var mybottom = r.bottom+mytop;
	if ( x >= r.left && x <= r.right && y >= mytop && y <= mybottom ) return true;
	else if ( this.subMenu != null ) return this.subMenu.checkCoordinates(x,y);
	else return false;
}

