// CONFIGURABLE CONSTANTS

var menuID = 'menu-new';			// the ID of the UL menu
var M2mp = 36;					// optional - the padding or margin of the 2nd menu items


// INITIALIZE MENU
// set the events (onmouseover, onmouseout) on the menu
// set the width of the menu items (LI) by the width of its wrap (UL)
window.onload = function(){
	var $ = jQuery;
	$(document).ready(
		function() {

			// 1st Menu
			$('#' + menuID + ' > li').each(function(i) {

				// Set the mouse events if the 2nd UL submenu exists
				if (this.getElementsByTagName('UL')[0] && this.getElementsByTagName('UL')[0].tagName == 'UL') {
					this.onmouseover = function() {
						this.getElementsByTagName('UL')[0].style.visibility = "visible";
					}
					this.onmouseout = function() {
						this.getElementsByTagName('UL')[0].style.visibility = "hidden";
					}
				}

				// 2nd Menu
				var M2AwG = 0;
				$("> ul > li", this).each(function(i) {

					// Set the mouse events if the 3rd UL submenu exists
					if (this.getElementsByTagName('UL')[0] && this.getElementsByTagName('UL')[0].tagName == 'UL') {
						this.onmouseover = function() {
							this.getElementsByTagName('UL')[0].style.visibility = "visible";
						}
						this.onmouseout = function() {
							this.getElementsByTagName('UL')[0].style.visibility = "hidden";
						}
					}

					// Get the A width
					var M2Aw = $('> a', this).width();
					if (M2Aw > M2AwG)
						M2AwG = M2Aw;

				});

				// 2nd Menu - Apply width of the greater A to UL and its A tags
				$("> ul > li", this).each(function(i) {
					$("> a", this).css( {display: 'block', width: M2AwG+'px'} );
					$(this).parent().css( {width: (M2AwG+M2mp)+'px'} );

				});

				// Returns the CSS styles back for the IE7 fixing
				$(this).css( { 'float': 'left', 'clear': 'none' } );
				// MSIE 6 fix
				$(this).css( { 'borderLeft': '1px solid transparent' } );
			});

			// MSIE 6 fix back
			$('#' + menuID + ' > li').css( { borderLeft: '0px none' } );
			// Returns the CSS styles back for the IE7 fixing
			$('#' + menuID).css( { visibility: 'visible', overflow: 'visible' } );
		}
	);
	
	// Roman L. => this funsion is used in checkboxes.js
	init();
}