var KIOS = {

	menuId: null,

	menuHeightOpened: '155px',
	menuHeightClosed: '42px',
	menuAnimationDuration: 0.3,

	/**
	 * v this je li element
	 */
	menuItemMouseOver: function(event) {
		var obj;

//debugger;
//		if (event.target.tagName.toLowerCase() == 'a') {
//			return;
//		}

		obj = this;
//		obj = $A(arguments)[1];
//		obj = event.currentTarget;
//		obj = $(Event.element(event));
		$(KIOS.menuId).immediateDescendants().each(function(item) {
//debugger;
			if (item.firstChild == obj) {
				if (item.getStyle('height') != KIOS.menuHeightOpened) {
//					if (item.efekt) {
//						item.efekt.cancel();
//					}
//					item.efekt = new Effect.Morph(item, {style:{height: KIOS.menuHeightOpened}, duration: KIOS.menuAnimationDuration});
					new Effect.Morph(item, {style:{height: KIOS.menuHeightOpened}, duration: KIOS.menuAnimationDuration});
				}
			} else {
//				if (item.getStyle('height') != KIOS.menuHeightClosed) {
//					if (item.efekt) {
//						item.efekt.cancel();
//					}
//					item.efekt = new Effect.Morph(item, {style:{height: KIOS.menuHeightClosed}, duration: KIOS.menuAnimationDuration});
//				}

//				item.efekt = new Effect.Morph(item, {style:{height: KIOS.menuHeightClosed}, duration: KIOS.menuAnimationDuration});
				new Effect.Morph(item, {style:{height: KIOS.menuHeightClosed}, duration: KIOS.menuAnimationDuration});
			}
		});

	},

	/**
	 * @param string id: identifikator hlavneho ul menu
	 */
	menuInit: function(id) {

		KIOS.menuId = id;

		$(KIOS.menuId).immediateDescendants().each(function(item) {
//debugger;
			// ak je to neaktivna polozka, nastavime vysku
			if (item.hasClassName('v-menu-l1n')) {
				item.setStyle({height: KIOS.menuHeightClosed});
			}

//debugger;
			// vytvorime efekt, nastavime mu vysku taku aka je aktualna, aby to teraz nic nespravilo
//			item.efekt = new Effect.Morph(item, {style: {height: item.getStyle('height')}, duration: KIOS.menuAnimationDuration});
			// pridame udalost na mousover
			Event.observe(item.firstChild, 'mouseclick', KIOS.menuItemMouseOver.bindAsEventListener(item.firstChild));
//			item.firstChild.observe('mouseover', KIOS.menuItemMouseOver.bindAsEventListener(item.firstChild));
//debugger;

			// kazdej linke v submenu dame udalost (ak sa pohybuje po menu pomocou tabulatora)
			$(item.lastChild).immediateDescendants().each(function (item1) {
//debugger;
//				var aaa = item1.firstChild;
				if (item1.firstChild.tagName.toLowerCase() == 'a') {
//					aaa.observe('focus', KIOS.menuItemMouseOver.bindAsEventListener(item1.parentNode.parentNode.firstChild));
					Event.observe(item1.firstChild, 'focus', KIOS.menuItemMouseOver.bindAsEventListener(item1.parentNode.parentNode.firstChild));
				}
			});

		});
	}
}


