// Title: COOLjsMenu Professional
// With popup support module
// With frames support module
// URL: http://javascript.cooldev.com/scripts/coolmenupro/
// Version: 2.3.0
// Last Modify: 9 December 2004
// Author: Sergey Nosenko <darknos@cooldev.com>
// Notes: Registration needed to use this script on your web site.
// Copyright (c) 2001-2004 by CoolDev.Com
// Copyright (c) 2001-2004 by Sergey Nosenko

_fieldNames = { // {{{
	_width:1,
	_height:0,
	_left:3,
	_top:2
}; // }}}

_reverseFieldNames = {};

window.CMenus = [];

_bw = {}; // {{{
	_bw._version = navigator.appVersion;
	_bw._agent = navigator.userAgent;
	_bw._opera = window.opera;
	_bw._opera7 = _bw._agent.match(/opera(\/| )7/i);
	_bw._operaOld = _bw._opera && !_bw._opera7;
	_bw._dom = document.getElementById;
	_bw._ie55 = _bw._version.match(/MSIE 5.5/) && _bw._dom && !_bw._opera;
	_bw._ie5 = _bw._version.match(/MSIE 5/) && _bw._dom && !_bw._ie55 && !_bw._opera;
	_bw._ie6 = _bw._version.match(/MSIE 6/) && _bw._dom && !_bw._opera;
	_bw._ie4 = document.all && !_bw._dom && !_bw._opera;
	_bw._ie = _bw._ie4 || _bw._ie5 || _bw._ie6;
	_bw._mac = _bw._agent.match(/Mac/);
	_bw._hotjava = _bw._agent.match(/hotjava/i);
	_bw._ns4 = document.layers && !_bw._dom && !_bw._hotjava;
	_bw._gecko = _bw._agent.match(/gecko/i);
// }}}

_defaultMenu = { // {{{
	pos:'relative',
	delay:[1,300],
	popupoff:[0,0],
	blankImage:'img/b.gif'
} // }}}


_defaultLayer = { // {{{
	main:false,
	image:null,
	color:'',
	cssStyle:'',
	cssClass:'',
	attributes:'',
	size:['+item','+item'],
	offset:[0,0],
	code:_bw._operaOld ? '&nbsp;' : '',
	zIndex:1,
	_width:0,
	_height:0,
	_left:0,
	_top:0,
	_visible:false,
	_updatePosition:function () {
		with (this) {
			_updatePosition = _nop;

			_width = _layer._getWidth();
			_height = _layer._getHeight();

			_width = size[1](_item, this);
			_height = size[0](_item, this);
			_layer._resize(_width, _height);

			_left = offset[1](_item, this);
			_top = offset[0](_item, this);

			_layer._move(_left, _top);

			_item._parent._level._includeRectangle(_left, _top, _width, _height);
		}
	},
	_updateVisibility:function () {
		if (this._visible != this._item._shouldBeVisible(this.visibility)) {
			this._visible = !this._visible;
			var _transition = (this._item._parent._level._visible && _bw._ie && this._item._menu._isDynamic && this[this._visible ? 'fadeIn' : 'fadeOut']) || '';
			var _filters = (this._item._menu._isDynamic && _bw._ie && !_bw._mac && this.filters) || '';
			if (_transition || _filters)
				this._layer._style.filter = _transition + ' ' + _filters;

			this._updatePosition();

			with (this._layer) {
				if (_transition)
					_layer.filters[0].apply();
				_setVisibility(this._visible);
				if (_transition)
					_layer.filters[0].play();
			}
		}
	}
} // }}}

_defaultStyle = { // {{{
	size:[ '+main', '+maxMain' ],
	leveloff:[ 0, '+parentItem' ],
	itemoff:[ '+previousItem', 0 ],
	wrapoff:[ 'level', '+previousItem' ]
} // }}}

_processLayer = function (_layer, _context) { // {{{
	if (_layer._processed)
		return;

	_layer._processed = true;

	if (!_layer.size && (_layer.main || _layer.code))
		_layer.size = [ '+self', '+self' ];

	_applyDefaults(_layer, _defaultLayer);

	with (_layer) {
		if (image)
			code = '<img src="' + image + '" width="' + size[1] + '" height="' + size[0] + '"' + (_bw._ns4 ? '' : ' style="display:block"') +' />';
		else if (code && code != '{trigger}')
			code = '<table cellspacing="0" cellpadding="0" border="0"><tr><td nowrap="nowrap"><div' + _attribute('class', cssClass) + _attribute('style', cssStyle) + '>' + code + '</div></td></tr></table>';

		code = '<div' + attributes + ' id="" style="z-index:' + zIndex + ';position:absolute;visibility:hidden;' + (_bw._operaOld ? 'width:1px;' : '') + (_bw._ie ? 'overflow:hidden;' : '') + (color ? 'background-color:' + color + ';' : '') + cssStyle + '"' + _attribute('class', cssClass) + '>' + code + '</div>';
		if (_bw._ns4)
			code = code.replace(/background([-\w]*:)/g, 'layer-background$1');

		offset = _copyObject(offset);
		size = _copyObject(size);

		if (_isNumber(offset[0]))
			offset[0] = _formatNumber(offset[0]) + 'px';

		if (_isNumber(offset[1]))
			offset[1] = _formatNumber(offset[1]) + 'px';

		switch (_layer.align) {
		case 'center':
			offset[1] += '+0.5' + _context + '-0.5self';
			break;
		case 'right':
			offset[1] += '+' + _context + '-self';
			break;
		}

		switch (_layer.valign) {
		case 'middle':
			offset[0] += '+0.5' + _context + '-0.5self';
			break;
		case 'bottom':
			offset[0] = '+' + _context + '-self';
			break;
		}

		if (!_isUndefined(_layer.margin)) {
			var _left, _top, _right, _bottom;
			if (_isNumber(_layer.margin))
				_left = _top = _right = _bottom = _layer.margin;
			else if (_layer.margin.length == 2) {
				_top = _bottom = _layer.margin[0];
				_left = _right = _layer.margin[1];
			} else {
				_top = _layer.margin[0];
				_right = _layer.margin[1];
				_bottom = _layer.margin[2];
				_left = _layer.margin[3];
			}

			if (_isNumber(size[0]))
				size[0] = _formatNumber(size[0]) + 'px';

			if (_isNumber(size[1]))
				size[1] = _formatNumber(size[1]) + 'px';

			if (!main) {
				size[0] += _formatNumber(-_top - _bottom) + 'px';
				size[1] += _formatNumber(-_left - _right) + 'px';
			}
			offset[0] += _formatNumber(_top) + 'px';
			offset[1] += _formatNumber(_left) + 'px';
		}

		_preparePairedCalculator(size);
		_preparePairedCalculator(offset, 'item');
	}
} // }}}

_processStyle = function (_style) { // {{{
	if (!_style._processed) {
		var i, j;

		_style._processed = true;

		if (!_isUndefined(_style.itemLayers))
			for (i in _style.itemLayers)
				_processLayer(_style.itemLayers[i], 'item');

		if (!_isUndefined(_style.levelLayers)) {
			for (i in _style.levelLayers) {
				if (_isUndefined(_style.levelLayers[i].size))
					_style.levelLayers[i].size = [ '+level', '+level' ];
				if (_isUndefined(_style.levelLayers[i].visibility))
					_style.levelLayers[i].visibility = 'f';
			}

			for (i in _style.levelLayers)
				_processLayer(_style.levelLayers[i], 'level');
		}

		if (!_isUndefined(_style.layers))
			for (i in _style.layers)
				_processLayer(_style.layers[i], 'item');

		if (_style.inherit) {
			var _parentStyle = _processStyle(_style.inherit);
			_style.inherit = null;

			if (_isUndefined(_style.layers) && !_isUndefined(_parentStyle.layers))
				_style.layers = _copyObject(_parentStyle.layers);

			_applyDefaults(_style, _parentStyle);

			if (_style.replacedLayers)
				for (i in _style.replacedLayers)
					for (j in _style.layers)
						if (!_isUndefined(_style.layers[j].name) && _style.layers[j].name == _style.replacedLayers[i].name) {
							_style.layers[j] = _style.replacedLayers[i];
							_processLayer(_style.layers[j]);
						}
		}

		_applyDefaults(_style, _defaultStyle);

		var _offset = '+previousItem';

		if (!_isUndefined(_style.spacing))
			_offset += (_style.spacing >= 0 ? '+' : '') + _style.spacing + 'px';

		switch (_style.orientation) {
		case 'vertical':
			_style.itemoff = [ _offset, 0 ];
			_style.wrapoff = [ 'level', '+previousItem' ];
			break;
		case 'horizontal':
			_style.itemoff = [ 0, _offset ];
			_style.wrapoff = [ '+previousItem', 'level' ];
			break;
		}
	}

	return _style;
} // }}}

function _applyDefaults(_object, _template) { // {{{
	for (var i in _template)
		if (_isUndefined(_object[i]))
			_object[i] = _template[i];
} // }}}

function COOLjsMenuPRO(_name, _items) { // {{{
	this._isDynamic = (_bw._dom && !_bw._operaOld && !(_bw._ie && _bw._mac)) || _bw._ns4;

	_applyDefaults(_items[0], _defaultMenu);


	if (!_name) {
		_name = 'menu_';
		do _name += Math.round(Math.random() * 10); while (!_isUndefined(window.CMenus[_name]))
	}

	window.CMenus[this._name = _name] = this;
	this._jsPath = 'window.CMenus.' + _name;
this._isPopup = _items[0].popup;
this._isFramed = _items[0].frames;
	this._isTopFrame = this._isFramed && _items[0].frames[0] == window.name;
	this._isRelative = !this._isPopup &&_items[0].pos == 'relative'&& (!this._isFramed || this._isTopFrame);
	this.$root = this._root = {
		_menu:this,
		_name:this._name,
		_jsPath:this._jsPath + '.$root',
		_parent:null,
		_left:0,
		_top:0,
		_properties:_items[0],
		frameoff:_items[0].pos?_items[0].pos:[0,0],
		_setState:_nop,
		_index:'R',
		_hasSubmenu:true,
		_depth:-1,
		_rawSubmenu:_items,
		_getRelativePath:function () { return [] },
		_getPath:function () { return [] },
		_getId:_CMenuItem.prototype._getId
	};

	if (this._isFramed && !this._isTopFrame) {
		this._root._left = 0;
		this._root._top = 0;
	} else if (!this._isRelative&& !this._isPopup) {
		this._root._left = _items[0].pos[0];
		this._root._top = _items[0].pos[1];
	}

	this._ns4OffsetLeft = this._ns4OffsetTop = 0;
	this._root.$level = this._root._level = new _CMenuLevel(this, this._root);

	with (this._root) {
		if (_isNumber(_properties.delay))
			_properties.delay = [ 400, _properties.delay ];

		_properties._dropDownDelay = _properties.delay[0];
		_properties._closeUpDelay = _properties.delay[1];
	}

	this.items = this._items = [];

	this._handlers = '';

	for (var i in this)
		if (i.match(/^\$(on.*)$/))
			this._handlers += _attribute(RegExp.$1, 'return ' + this._jsPath + '.processEvent(\'' + RegExp.$1 + '\', {index});');

	this._triggerLayer = { name:'trigger', size:[ '+item', '+item' ], zIndex:1000, code:'{trigger}' };
	_processLayer(this._triggerLayer);

	this._root._level._ensureChildren();
	this._timeouts = [];
	this._lastActiveItem = null;
	this._lastShownLevel = null;
	this._selectedItem = null;

	if (_isUndefined(window._onload)) {
		window._onload = window.onload;
		window.onload = function () {
			CLoadNotify();
			if (window._onload) {
				var _o = window._onload;
				window._onload = null;
				return _o();
			}
		}
	}

	if (_bw._operaOld) {
		if (!window.$CDOperaResizeFix) {
			$iw = innerWidth;
			$ih = innerHeight;
			$tiw = top.innerWidth;
			$tih = top.innerHeight;
			window.$CDOperaResizeFix = window.setInterval('if($iw!=innerWidth||$ih!=innerHeight||$tiw!=top.innerWidth||$tih!=top.innerHeight)document.location.reload();', 300);
		}

		_Layer = _OldOperaLayer;
	} else if (_bw._ns4) {
		window.onresize = function () {
			document.location.reload();
		}

		_Layer = _Ns4Layer;
	} else {
if (this._isFramed && this._isTopFrame) {
			window.onresize = function () {
				for (var i in window.CMenus) {
					window.CMenus[i]._show();
					var _menu = window.CMenus[i]._getOtherMenu();
					if (_menu)
						_menu._show();
				}
			}
		}
		if (_bw._gecko || _bw._opera7)
			_Layer = _GeckoLayer;
		else
			_Layer = _CommonLayer;
	}

	_Layer._cache = {};
} // }}}

$ = COOLjsMenuPRO.prototype;

$._getId = function (_suffix) { // {{{
	return this._name + '_' + _suffix;
} // }}}

$._getAbsoluteLeft = function () { // {{{
	var _result = 0, o = this._rootDiv._layer;

	while (o) {
		_result += o.offsetLeft;
		o = o.offsetParent;
	}

	return _result;
} // }}}

$._getAbsoluteTop = function () { // {{{
	var _result = 0, o = this._rootDiv._layer;

	while (o) {
		_result += o.offsetTop;
		o = o.offsetParent;
	}

	return _result;
} // }}}

$.$$onscroll = function () { // {{{
	if (!this._onload)
		this._updateCrossFramePosition();
} // }}}

$._updateCrossFramePosition = function () { // {{{
	if (this._isFramed && !this._isTopFrame) {
		var scrollYOffset = 0, scrollXOffset = 0;
		if (_bw._ie) {
			scrollYOffset = document.body.parentElement.scrollTop;
			scrollXOffset = document.body.parentElement.scrollLeft;
			var _frame = this._getOtherFrame();
			if (_frame)
				scrollYOffset -= _frame.document.body.parentElement.clientHeight;
			var _menu = this._getOtherMenu();
			if (_menu) {
				scrollXOffset += _menu._getAbsoluteLeft();
				scrollYOffset += _menu._getAbsoluteTop();
			}
		} else if (_bw._gecko) {
			var _frame = this._getOtherFrame();
			if (_frame)
				scrollYOffset -= _frame.innerHeight;
			var _menu = this._getOtherMenu();
			if (_menu) {
				scrollXOffset += _menu._getAbsoluteLeft();
				scrollYOffset += _menu._getAbsoluteTop();
			}
		}
		this._updatePositions(scrollXOffset, scrollYOffset);
	}
} // }}}

$._getOtherFrame = function () { // {{{
	return top.frames[this._root._properties.frames[this._isTopFrame ? 1 : 0]];
} // }}}

$._getOtherMenu = function () { // {{{
	var _frame = this._getOtherFrame();
	return _frame && _frame.CMenus && _frame.CMenus[this._name];
} // }}}

$.processEvent = function (_event, _index, _dontContinue) { // {{{
	var _result = true, _item = this._items[_index];

	if (_item) {
if (this._isFramed) {
			if (!_dontContinue) {
				var _menu = this._getOtherMenu();
				if (_menu)
					_menu.processEvent(_event, _menu._root._level._getItemByRelativePath(_item._getRelativePath())._index, true);
			}
			this._updateCrossFramePosition();
		}
		_result = this['$' + _event](_item);
		if (this[_event])
			this[_event](_item);
	}

	return _result;
} // }}}

$._getBlankImage = function () { // {{{
	return this._root._properties.blankImage;
} // }}}

$._onload = function () { // {{{
if (!this._isPopup) {
		if (_bw._ns4 && this._isRelative)
			with (document.anchors[this._getId('da')]) {
				this._root._left = x;
				this._root._top = y;
			}
		this._show();
}
	this._onload = _nop;
} // }}}

$.initTop = function () { // {{{
	var w = 0, h = 0, i, s;

	if (this._root._properties.placeholder)
		with (this._root._properties) {
			w = placeholder[1];
			h = placeholder[0];
		}
	else with (this._root._level) {
		i = _children.length - 1;
		w += _children[i]._width(_children[i]);
		h += _children[i]._height(_children[i]);
		for (i--; i > 0; i--) {
			w += _children[i]._itemOffset[1](_children[i]);
			h += _children[i]._itemOffset[0](_children[i]);
		}
	}

	this._withPlaceholder = _isNumber(w + h) && w + h == w + h;

	if (!_bw._ns4) {
		s = '<div id="' + this._getId('r') + '" style="position:';
		if (this._isFramed && !this._isTopFrame && _bw._gecko)
			s += 'fixed;top:0;left:0;';
		else if (this._isRelative)
			s += 'relative;' + (this._withPlaceholder ? 'width:' + w + 'px;height:' + h + 'px;' : '');
		else
			s += 'absolute;left:' + this._root._left + 'px;top:' + this._root._top + 'px;';
		s += '">' + (this._isDynamic ? '' : this._root._level._getHtml(true)) +'</div>';
		document.write(s);
		this._rootDiv = new _Layer(this._getId('r'));
	} else if (this._isRelative)
		document.write('<div><a name="' + this._getId('da') + '" href="#"><img src="' + this._getBlankImage() + '"' + (this._withPlaceholder ? 'width="' + w + '" height="' + h + '"' : 'width="1" height="1"') + ' border="0" /></a></div>');
} // }}}

$._popup = function (ev, offX, offY) { // {{{
	var x = ev.pageX || ev.x;
	var y = ev.pageY || ev.y;

	var _popupOffset = this._root._properties.popupoff;

	x += _isUndefined(offX) ? _popupOffset[1] : offX;
	y += _isUndefined(offY) ? _popupOffset[0] : offY;

	this._popupAt(x, y);
} // }}}

$._popupAt = function (_x, _y) { // {{{
	this._updatePositions(_x, _y);
	this._show();
	this._popupHandler = new Function('return ' + this._jsPath + ".$popDown()");
	if (_bw._ie6) {
		this._rootDiv._layer.setCapture(false);
		this._rootDiv._layer.onclick = this._popupHandler;
		this._rootDiv._layer.onlosecapture = this._popupHandler;
	} else if (_bw._dom) {
		document.addEventListener('click', this._popupHandler, true);
	} else if (_bw._ns4) {
		document.captureEvents(Event.CLICK);
		document.onclick = this._popupHandler;
	}
} // }}}

$.$popDown = function () { // {{{
	this._cancelQueued();
	this._showLevel(null);
	if (_bw._ie6) {
		this._rootDiv._layer.releaseCapture();
		//if (event.srcElement != this._rootDiv._layer)
		//	event.srcElement.fireEvent('onclick', event);
	} else if (_bw._dom) {
		document.removeEventListener('click', this._popupHandler, true);
	} else if (_bw._ns4) {
		document.releaseEvents(Event.CLICK);
		document.onclick = null;
	}
} // }}}

$._show = function () { // {{{
this._updateCrossFramePosition();
	this._showLevel(this._root._level);
} // }}}


$._updatePositions = function (_x, _y) { // {{{
	if (_bw._ns4) {
		this._ns4OffsetLeft = _x;
		this._ns4OffsetTop = _y;
		this._root._level._ns4UpdatePosition();
	} else
		this._rootDiv._move(_x, _y);
} // }}}

$._enqueue = function (_method, _parameter, _delay) { // {{{
	this._timeouts[this._timeouts.length] = window.setTimeout(this._jsPath + '.' + _method + '(' + (_parameter ? _parameter._jsPath : 'null') + ')', _delay);
} // }}}

$.cancelQueued = $._cancelQueued = function () { // {{{
	for (var i in this._timeouts)
		window.clearTimeout(this._timeouts[i]);
	this._timeouts = [];
} // }}}

$.setActiveItem = $._setActiveItem = function (_item, _delay) { // {{{
	if (_delay)
		this._enqueue('setActiveItem', _item, _delay);
	else {
		var _paths = _pathDifference(this._lastActiveItem, _item), i;

		for (i in _paths[0])
			_paths[0][i]._setState(1);
		for (i in _paths[1])
			_paths[1][i]._setState(2);

		this._lastActiveItem = _item;

		if (this._root._properties.exclusive)
			for (i in window.CMenus)
				if (window.CMenus[i] != this)
					window.CMenus[i]._showLevel(null);
	}
} // }}}

$.setSelectedItem = $._setSelectedItem = function (_item, _delay) { // {{{
	if (_delay)
		this._enqueue('setSelectedItem', _item, _delay);
	else {
		var _previous = this._selectedItem;
		this._selectedItem = _item;
		(_previous || this._root)._setState('', true);
		(_item || this._root)._setState('', true);
	}
} // }}}

$.showLevel = $._showLevel = function (_level, _delay) { // {{{
	if (_delay)
		this._enqueue('showLevel', _level, _delay);
	else {
		if (_level && _level._dummy)
			_level = _level._parent._parent._level;

		var _paths = _pathDifference(this._lastShownLevel, _level), i;

		if (!_paths[1].length&& !this._isPopup)
			_paths[1][0] = this._root._level;

		_setVisibility(_paths[0], false);
		_setVisibility(_paths[1], true);

		this._lastShownLevel = _level;

		this._fixGecko();
	}
} // }}}

$._fixGecko = function () { // {{{
	if (_bw._gecko) {
		if (this._isRelative) {
			var o = this._rootDiv._layer.parentNode;
			if (o.tagName != 'BODY') {
				// TODO!!!
				o.style.width = this._rootDiv._layer.offsetWidth + 'px';
				o.style.height = this._rootDiv._layer.offsetHeight + 'px';
			}
		}
	}
} // }}}

$.$ondragstart = $.$onselect = function () { return false }

$.$onfocus = function (_item) { // {{{
	this._cancelQueued();
	this._showLevel(_item._level);
	_item._setStatus(true);
	this._setActiveItem(_item);
} // }}}

$.$onblur = function (_item) { // {{{
	this._cancelQueued();
	if (!_item._data.sticky)
		this._showLevel(null);
	this._setActiveItem(null);
	_item._setStatus(false);
} // }}}

$.$onmouseover = function (_item) { // {{{
	this._cancelQueued();
	this._showLevel(_item._level, this._root._properties._dropDownDelay);
	_item._setStatus(true);
	this._setActiveItem(_item);
	return true;
} // }}}

$.$onclick = function (_item) { // {{{
	var _result = false;
	this._cancelQueued();
	this._setSelectedItem(_item);
	if (_item._data.url) {
		window.open(_item._data.url, _item._data.target ||'_self');
		_result = !_item._data.url.match(/^javascript:/);
		if (!_item._data.sticky) {
if (this._isPopup)
				this.$popDown();
			else
				this._showLevel(null);
		}
	} else
		this._showLevel(_item._level._visible ? _item._level._parent._parent._level : _item._level);

	return _result;
} // }}}

$.$onmouseout = function (_item) { // {{{
	this._cancelQueued();
	this._showLevel(this._isPopup ? this._root._level :null, this._root._properties._closeUpDelay);
	this._setActiveItem(null, this._root._properties._closeUpDelay);
	_item._setStatus(false);
} // }}}

function _CMenuLevel(_menu, _parent) { // {{{
	this._menu = _menu;
	this._parent = _parent;
	this._isTopLevel = _parent == _menu._root;
	this._isPersistent = !_menu._isPopup &&this._isTopLevel;
	this._jsPath = this._parent._jsPath + '.$level';
	this._maxMain = { _width:0, _height:0 };
	this._name = this._menu._getId('l' + this._parent._index);
} // }}}

$ = _CMenuLevel.prototype;

$._children = [];
$._left = 0;
$._top = 0;

$._getItemByRelativePath = function (_path) { // {{{
	if (_path.length) {
		this._ensureChildren();
		return this._children[_path[0]]._level._getItemByRelativePath(_path.slice(1));
	}
	return this._parent;
} // }}}

$._ensureChildren = function () { // {{{
	if (!this._children.length) {
		var i, _items = this._parent._rawSubmenu, _last = _items.length - 1;

		if (_isUndefined(_items[_last]))
			_last--;

		this._children = _items.slice(1, _last + 1);

		if (this._children.length == 1 && this._children[0].array) {
			var _definition = this._children[0];
			this._children = [];

			for (i = 0; i < _definition.array.count; i++) {
				this._children[i] = _copyObject(_definition);
				this._children[i].array.prepare(this._children[i], i);
			}
		}

		for (i in this._children)
			this._children[i] = new _CMenuItem(this._menu, this._parent, this._children[i], i);
	}
} // }}}

$._getId = function (_suffix) { // {{{
	return this._name + '_' + _suffix;
} // }}}

$._hasIframe = function () { // {{{
	return !this._isPersistent && (_bw._ie55 || _bw._ie6) && !this._getFilters(true) && !this._getTransition(true) && !this._getTransition(false);
} // }}}

$._ns4UpdatePosition = function () { // {{{
	if (this._dynLayer) {
		this._dynLayer._move(this._menu._ns4OffsetLeft, this._menu._ns4OffsetTop);
		for (var i in this._children)
			this._children[i]._level._ns4UpdatePosition();
	}
} // }}}

$._getHtml = function (_recursive) { // {{{
	this._ensureChildren();

	var i, _result = (this._hasIframe() ? '<iframe tabindex="-1" frameborder="0" id="' + this._getId('f') + '" src="' + (location.protocol == 'https:' ? this._menu._root._properties.https_fix_blank_doc : '') + '" scroll="none" style="FILTER:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);visibility:hidden;height:1px;position:absolute;width:1px;"></iframe>' : '') + '<div id="' + this._getId('l') + '" style="position:absolute;visibility:hidden;">';

	for (i in this._children)
		_result += this._children[i]._getHtml(_recursive);

	return _result + '</div>';
} // }}}

$._getPath = function () { // {{{
	with (this._parent)
		return _parent ? _parent._level._getPath().concat([this]) : [this];
} // }}}

$._includeRectangle = function (_left, _top, _width, _height) { // {{{
	this._minLeft = Math.min(this._minLeft, _left);
	this._minTop = Math.min(this._minTop, _top);
	this._maxRight = Math.max(this._maxRight, _left + _width);
	this._maxBottom = Math.max(this._maxBottom, _top + _height);
} // }}}

$._excludeAllRectangles = function () { // {{{
	this._minLeft = this._minTop = 65535;
	this._maxRight = this._maxBottom = -65535;
} // }}}

$._isFilteringEnabled = function () { // {{{
	return this._menu._isDynamic && _bw._ie && !_bw._mac;
} // }}}

$._getFilters = function () { // {{{
	return this._isFilteringEnabled() ? this._children[0]._properties.filters : '';
} // }}}

$._getTransition = function (_isItFadeIn) { // {{{
	return !this._isPersistent && this._isFilteringEnabled() ? this._children[0]._properties[_isItFadeIn ? 'fadeIn' : 'fadeOut'] : '';
} // }}}

$._setVisibility = function (_value) { // {{{
	if (this._visible != _value) {
		var i;
		this._visible = _value;
		this._parent._setState('', true);

		if (!this._initialized) {
			this._initialized = true;

			if (this._menu._isDynamic)
				this._dynLayer = new _Layer(this._getHtml(false), this._menu._rootDiv || 1);

			if (!this._isTopLevel) {
				this._left = this._children[0]._levelOffset[1](this._children[0]);
				this._top = this._children[0]._levelOffset[0](this._children[0]);
			} else if (_bw._ns4) {
				this._left = this._menu._root._left;
				this._top = this._menu._root._top;
			}

			if (this._hasIframe())
				this._iframe = new _Layer(this._getId('f'));

			this._layer = new _Layer(this._getId('l'));

			this._excludeAllRectangles();

			for (i in this._children)
				this._children[i]._initializeLayers();

			for (i in this._children)
				this._children[i]._calculateSizeAndPosition();

			this._width = this._maxRight - this._minLeft;
			this._height = this._maxBottom - this._minTop;

			this._excludeAllRectangles();
		}

		var _filters = '';

		if (this._isFilteringEnabled()) {
			_filters = this._getTransition(_value) + ' ' + this._getFilters();

			this._dynLayer._style.filter = _filters;

			if (_filters)
				for (var i = 0; i < this._dynLayer._layer.filters.length; i++)
					this._dynLayer._layer.filters[i].apply();
		}

		_setVisibility(this._children, _value);

		if (this._menu._isDynamic) {
			if (this._hasIframe())
				this._iframe._move(-this._minLeft, -this._minTop);
			this._layer._move(-this._minLeft, -this._minTop);
			this._dynLayer._move(this._left + this._minLeft, this._top + this._minTop);
			this._layer._resize(this._maxRight - this._minLeft, this._maxBottom - this._minTop);
			this._dynLayer._resize(this._maxRight - this._minLeft, this._maxBottom - this._minTop);
			if (_bw._ns4) {
				with (this._dynLayer._layer.clip) {
					left = this._minLeft;
					top = this._minTop;
				}
				with (this._layer._layer.clip) {
					left = this._minLeft;
					top = this._minTop;
				}
			}
		} else {
			if (this._hasIframe())
				this._iframe._move(this._minLeft, this._minTop);
			this._layer._move(this._left, this._top);
		}

		if (this._hasIframe())
			this._iframe._resize(this._maxRight - this._minLeft, this._maxBottom - this._minTop);

		if (!_bw._ns4 && !_bw._operaOld && this._isPersistent && this._menu._isRelative && !this._menu._withPlaceholder)
			this._menu._rootDiv._resize(this._width, this._height);

		if (this._menu._isDynamic)
			this._dynLayer._setVisibility(_value);

		this._layer._setVisibility(_value);

		if (_filters)
			for (var i = 0; i < this._dynLayer._layer.filters.length; i++)
				this._dynLayer._layer.filters[i].play();

		if (this._hasIframe())
			this._iframe._setVisibility(_value);
		else if (this._isPersistent) {
			var _list = this._menu._root._properties.forms_to_hide;
			if (_list)
				for (i in _list)
					new _Layer(_list[i])._setVisibility(!this._menu._lastShownLevel || this._menu._lastShownLevel == this._menu._root._level);
		}
	}
} // }}}

function _CMenuItem(_menu, _parent, _data, _minorIndex) { // {{{
	this._menu = _menu;
	this._parent = _parent;
	this._data = _data;
	this._minorIndex = _minorIndex;

	var i, _format = _data.format || {}, _style;

	this._isSeparator = true;
	for (i in _data) {
		this._isSeparator = false;
		break;
	}

	this._depth = _parent._depth + 1;
	this._data.index = this._index = _menu._items.length;

	this._name = this._menu._getId('i' + this._index);

	_menu._items[this._index] = this;
	this._jsPath = _menu._jsPath + '.items[' + this._index + ']';
	this._properties = _copyObject(_parent._properties, _parent._rawSubmenu[0], _format);
	this._previousItem = _minorIndex && _parent._level._children[_minorIndex - 1];
	this._isTopLevel = _menu._root == _parent;
	this._isFirst = this._minorIndex == 0;
	this._isLast = this._minorIndex == this._parent._level._children.length - 1;
	this._rawSubmenu = _data.sub;
	this._hasSubmenu = this._rawSubmenu && this._rawSubmenu.length;
	this._levelOffset = this._properties.leveloff;
	this._main = {};

	_style = this._properties.style;

	if (_isObject(_style) && _style.length)
		_style = _style[this._depth] || _style[0];

	if (this._isSeparator) {
		if (!_style.separator.inherit)
			_style.separator.inherit = _style;
		_style = _style.separator;
	}


	this._properties = _copyObject(this._properties, _processStyle(_style), _parent._rawSubmenu[0], _format);

	this._data = _copyObject(this._data, this._properties.parameters);

	this._data.$0 = null;
	this._visible = false;
	this._state = 1;
	this._itemOffset = this._properties.itemoff;
	this._wrapOffset = this._properties.wrapoff;

	_preparePairedCalculator(this._properties.size);
	_preparePairedCalculator(this._properties.leveloff, 'parentItem');
	_preparePairedCalculator(this._properties.itemoff, 'previousItem');
	_preparePairedCalculator(this._properties.wrapoff, 'previousItem');
	this._width = this._properties.size[1];
	this._height = this._properties.size[0];

	this.$level = this._level = this._hasSubmenu ?  new _CMenuLevel(_menu, this) : {
		_dummy:true,
		_parent:this,
		_jsPath:this._jsPath + '.$level',
		_getPath:_CMenuLevel.prototype._getPath,
		_getHtml:_nop,
		_ns4UpdatePosition:_nop,
		_getItemByRelativePath:_CMenuLevel.prototype._getItemByRelativePath
	};

	this._data.trigger = '<a' + _classOrStyleAttribute(this._properties.trigger) + _attribute('accesskey', this._data.key) + ' href="' + (this._data.url || '#') + '" ' + _attribute('target', this._data.target) + this._menu._handlers + '>' + (_bw._operaOld ? '' : '<img src="' + this._menu._getBlankImage() + '" width="100%" height="100%"' + _attribute('alt', this._data[this._properties.alt || 'alt']) + ' border="0" />') + '</a>';

	this._layers = [];
	this._htmlCode = '';

	if (_style.levelLayers)
		for (i in _style.levelLayers)
			this._addLayer(_style.levelLayers[i]);

	if (_style.itemLayers)
		for (i in _style.itemLayers)
			this._addLayer(_style.itemLayers[i]);

	if (_style.layers)
		for (i in _style.layers)
			this._addLayer(_style.layers[i]);

	this._addLayer(this._menu._triggerLayer);

	this.main = this._main;
	this.maxMain = this._parent._level._maxMain;
	this.item = this;
	this.previousItem = this._previousItem;
	this.level = this._parent._level;
	this.parentItem = this._parent;
	if (!this._isTopLevel)
		this.parentLevel = this._parent._parent._level;
} // }}}

$ = _CMenuItem.prototype;

$._getId = function (_suffix) { // {{{
	return this._name + '_' + _suffix;
} // }}}

$._setStatus = function (_flag) { // {{{
	var _text = this._data[this._properties.status || 'status'];
	if (_text)
		window.status = _flag ? _text : window.defaultStatus;
} // }}}

$._getPath = function () { // {{{
	return this._parent._getPath().concat([this]);
} // }}}

$._getRelativePath = function () { // {{{
	return this._parent._getRelativePath().concat([this._minorIndex]);
} // }}}

$._addLayer = function (_definition) { // {{{
	if (this._isPotentiallyVisible(_definition.visibility)) {
		var i, _code = _definition.code, _match;

		while (_match = _code.match(/\{([\w\d]+)=([^}]*)\}/))
			_code = _code.replace(new RegExp(_match[0], 'g'), _isUndefined(this._data[_match[1]]) ? _match[2] : this._data[_match[1]]);

		while (_match = _code.match(/\{([\w\d]+)\}/)) {
			if (_isUndefined(this._data[_match[1]]))
				return;
			_code = _code.replace(new RegExp(_match[0], 'g'), this._data[_match[1]]);
		}

		i = this._layers.length;
		this._layers[i] = _copyObject(_definition);
		this._htmlCode += _code.replace('id=""', 'id="' + this._getId(i) + '"');
	}
} // }}}

$._getHtml = function (_recursive) { // {{{
	return this._htmlCode + (_recursive ? this._level._getHtml(_recursive) : '');
} // }}}

$._initializeLayers = function () { // {{{
	var i, _previousMainIndex, _self;
	for (i in this._layers) {
		with (this._layers[i]._layer = new _Layer(this._getId(i)))
			if (this._layers[i].main) {
				if (!_isUndefined(_previousMainIndex))
					this._layers[_previousMainIndex].main = false;
				_self = { _width:_getWidth(), _height:_getHeight() };
				this._layers[i]._width = this._main._width = this._layers[i].size[1](this, _self);
				this._layers[i]._height = this._main._height = this._layers[i].size[0](this, _self);
				with (this._parent._level._maxMain) {
					_width = Math.max(_width, this._main._width);
					_height = Math.max(_height, this._main._height);
				}
				_previousMainIndex = i;
			}

		this._layers[i]._item = this;
	}
} // }}}

$._calculateSizeAndPosition = function () { // {{{
	this._width = this._width(this);
	this._height = this._height(this);

	if (this._previousItem) {
		if (this._data.wrapPoint) {
			this._left = this._wrapOffset[1](this);
			this._top = this._wrapOffset[0](this);
		} else {
			this._left = this._itemOffset[1](this);
			this._top = this._itemOffset[0](this);
		}
	} else {
		this._left = 0;
		this._top = 0;
	}

	this._parent._level._includeRectangle(this._left, this._top, this._width, this._height);
} // }}}

$._setVisibility = function (_value) { // {{{
	this._visible = _value;
	this._setState(this._state, true);
} // }}}

$._isPotentiallyVisible = function (_string) { // {{{
	if (_string) {
		var j, _value, _negate = false;

		for (j = 0; j < _string.length; j++) {
			_value = null;

			switch (_string.charAt(j)) {
			case '!':
				_negate = !_negate;
				break;
			case 'G':
				_value = !!_bw._gecko;
				break;
			case 'c':
				_value = !!this._hasSubmenu;
				break;
			case 'C':
				_value = _negate != !!this._hasSubmenu;
				break;
			case 's':
			case 'n':
			case 'N':
			case 'o':
			case 'O':
				_value = !_negate;
				break;
			case 'f':
				_value = this._isFirst;
				break;
			case 'l':
				_value = this._isLast;
				break;
			default:
				_value = _string.charAt(j) == this._depth;
				break;
			}

			if (_value !== null)
				if (_value == _negate)
					return false;
				else
					_negate = false;
		}
	}

	return true;
} // }}}

$._shouldBeVisible = function (_string) { // {{{
	if (!this._visible)
		return false;

	if (_string) {
		var j, _value, _negate = false;

		for (j = 0; j < _string.length; j++) {
			_value = null;

			switch (_string.charAt(j)) {
			case '!':
				_negate = !_negate;
				break;
			//case 'c':
			//	_value = !!this._hasSubmenu;
			//	break;
			case 'G':
				_value = !!_bw._gecko;
				break;
			case 'C':
				_value = !!(this._hasSubmenu && this._level._visible);
				break;
			case 's':
				_value = this._menu._selectedItem == this;
				break;
			case 'n':
				_value = this._state == 1;
				break;
			case 'N':
				_value = this._parent._state == 1;
				break;
			case 'o':
				_value = this._state == 2;
				break;
			case 'O':
				_value = this._parent._state == 2;
				break;
			//case 'f':
			//	_value = this._isFirst;
			//	break;
			//case 'l':
			//	_value = this._isLast;
			//	break;
			default:
				//_value = _string.charAt(j) == this._depth;
				_value = !_negate;
				break;
			}

			if (_value !== null)
				if (_value == _negate)
					return false;
				else
					_negate = false;
		}
	}

	return true;
} // }}}

$._setState = function (_state, _force) { // {{{
	if (_state != this._state || _force) {
		if (_state)
			this._state = _state;

		for (var i in this._layers)
			this._layers[i]._updateVisibility();
	}
} // }}}

// Layers {{{
_Layer = _nop;

function _gatherNs4Layers(_collection) { // {{{
	for (var i in _collection) {
		_Layer._cache[_collection[i].id] = _collection[i];
		if (_collection[i].layers && _collection[i].layers.length)
			_gatherNs4Layers(_collection[i].layers);
	}
} // }}}

function _CommonLayer(_id, _parent) { // {{{
	if (_parent) {
		this._layer = document.createElement('div');
		with (this._layer.style) {
			position = 'absolute';
			left = top = 0;
			visibility = 'hidden';
		}
		this._layer.innerHTML = _id;
		_parent._layer.appendChild(this._layer);
	} else {
		if (_isObject(_id))
			this._layer = _id;
		else {
			if (!_Layer._cache[_id])
				_Layer._cache[_id] = document.getElementById ? document.getElementById(_id) : document.all[_id];

			this._layer = _Layer._cache[_id];
		}
	}

	this._style = this._layer.style;
} // }}}

$ = _CommonLayer.prototype;

$._setVisibility = function (_value) { this._style.visibility = _value ? 'inherit' : 'hidden'; }
$._getWidth = function () { return this._layer.offsetWidth; }
$._getHeight = function () { return this._layer.offsetHeight; }
$._move = function (_left, _top) { with (this._style) { left = _left + 'px'; top = _top + 'px'; } }
$._resize = function (_width, _height) { with (this._style) { width = _width + 'px'; height = _height + 'px'; } }

function _GeckoLayer(_id, _parent) { // {{{
	_applyDefaults(this, new _CommonLayer(_id, _parent));
} // }}}

$ = _GeckoLayer.prototype = _copyObject(_CommonLayer.prototype);

$._getWidth = function () { with (this._layer) return childNodes[0] ? childNodes[0].offsetWidth : offsetWidth; }
$._getHeight = function () { with (this._layer) return childNodes[0] ? childNodes[0].offsetHeight : offsetHeight; }

function _OldOperaLayer(_id) { // {{{
	if (_isObject(_id))
		this._layer = _id;
	else
		this._layer = document.getElementById(_id);
	this._style = this._layer.style;
} // }}}

$ = _OldOperaLayer.prototype;

$._setVisibility = function (_value) { this._style.visibility = _value ? 'visible' : 'hidden'; }
$._getWidth = function () { return this._style.pixelWidth; }
$._getHeight = function () { return this._style.pixelHeight; }
$._move = function (_left, _top) { with (this._style) { left = _left; top = _top; } }
$._resize = function (_width, _height) { with (this._style) { width = _width; height = _height; } }

function _Ns4Layer(_id, _parent) { // {{{
	if (_parent) {
		this._layer = new Layer(1000);
		with (this._layer) {
			visibility = 'hide';
			document.open('text/html');
			document.write(_id);
			document.close();
			_gatherNs4Layers(layers);
		}
	} else if (_isObject(_id))
		this._layer = _id;
	else
		this._layer = _Layer._cache[_id];
} // }}}

$ = _Ns4Layer.prototype;

$._setVisibility = function (_value) { this._layer.visibility = _value ? 'inherit' : 'hide'; }
$._getWidth = function () { return this._layer.clip.width; }
$._getHeight = function () { return this._layer.clip.height; }
$._move = function (_left, _top) { this._layer.moveTo(_left, _top); }
$._resize = function (_width, _height) { this._layer.resize(_width, _height); }
// }}}

function _isUndefined(_value) { return typeof(_value) == 'undefined'; }
function _isNumber(_value) { return typeof(_value) == 'number'; }
function _isObject(_value) { return typeof(_value) == 'object'; }
function _nop() { return ''; }
function _attribute(_name, _value) { return _value ? ' ' + _name + '="' + _value + '"' : ''; }
function _classAttribute(_string) { return ('' + _string).match(/:/) ? '' : _attribute('class', _string); }
function _styleValue(_string) { return ('' + _string).match(/:/) ? _string : ''; }
function _classOrStyleAttribute(_string) { return _classAttribute(_string) + _attribute('style', _styleValue(_string)); }

function _copyObject (_object) { // {{{
	if (!_isUndefined(_object.length) && _object.concat)
		return ([]).concat(_object);

	var i, j, _result = {};

	for (j = 0; j < arguments.length; j++)
		if (_isObject(arguments[j]))
			for (i in arguments[j])
				_result[i] = arguments[j][i];

	return _result;
} // }}}

function _preparePairedCalculator(_array, _defaultOrigin) { // {{{
	if (!_isUndefined(_array)) {
		_array[1] = _prepareCalculator(_array[1], _defaultOrigin, 1);
		_array[0] = _prepareCalculator(_array[0], _defaultOrigin, 0);
	}
} // }}}

function _getFieldName(_index) { // {{{
	if (_isUndefined(_reverseFieldNames[_index]))
		for (var i in _fieldNames)
			_reverseFieldNames[_fieldNames[i]] = i;

	return '.' + _reverseFieldNames[_index];
} // }}}

function _formatNumber(_value) { // {{{
	switch (_value) {
	case '':
		_value = '+';
	case '-':
	case '+':
		_value += '1';
		return _value;
	default:
		return (_value >= 0 ? '+' : '') + parseFloat(_value);
	}
} // }}}

function _prepareCalculator(_value, _defaultOrigin, _dimension) { // {{{
	if (typeof(_value) == 'function')
		return _value;

	var _code = 'return ';

	if (_isNumber(_value))
		_code += _value;
	else {
		_code = 'with(i)' + _code;
		var _field = _getFieldName(_dimension), _magnitude, _match;

		while (_match = _value.match(/^([-+\.\d+]*)\*?(\w+)/)) {
			if (_match[1] == '')
				_defaultOrigin = _match[2];
			else
				_code += _formatNumber(_match[1]) + (_match[2] == 'px' ? '' : '*' + _match[2] + _field);
			_value = _value.slice(_match[0].length);
		}
	}

	if (_defaultOrigin) {
		var _end = '+i.' + _defaultOrigin + '{.}';

		switch (_defaultOrigin) {
		case 'item':
		case 'previousItem':
			break;
		case 'parentItem':
			_end += '+i.parentLevel{.}';
		default:
			_end += '-i.level{.}';
		}

		_code += _end.replace(/{.}/g, _getFieldName(_dimension + 2));
	}

	return new Function('i,self,container', _code);
} // }}}

function _pathDifference(_object1, _object2) { // {{{
	var _path1 = _object1 ? _object1._getPath() : [], _path2 = _object2 ? _object2._getPath() : [], i = 0;
	while (i < _path1.length && i < _path2.length && _path1[i] == _path2[i])
		i++;

	return [ _path1.slice(i), _path2.slice(i) ];
} // }}}

function _setVisibility(_objects, _value) { // {{{
	for (var i in _objects)
		_objects[i]._setVisibility(_value);
} // }}}

function CMenuPopUp(_menu, _evn, _offX, _offY) { window.CMenus[_menu]._popup(_evn, _offX, _offY); }
function CMenuPopUpXY(_menu, _x, _y) { window.CMenus[_menu]._popupAt(_x, _y); }
function CLoadNotify() { for (var i in window.CMenus) window.CMenus[i]._onload(); }
