/*

# ------------------------------------------------------------------------
# JA Kyanite II - Version 1.1 - Licence Owner JA49652
# ------------------------------------------------------------------------
# Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: J.O.O.M Solutions Co., Ltd
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# This file may not be redistributed in whole or significant part.
# ------------------------------------------------------------------------

*/ 



window.addEvent ('domready', function() {

	var sfEls = $$('.ja-megamenu li.mega');

	sfEls.each (function(li) {

		if ((a = li.getElement('a.mega')) && li.hasChild (a)) li.a = a;

		else li.a = null;

	});

	sfEls.each (function(li){

		li.addEvent('mouseenter', function(e) {

			if (this.hasClass ('group')) return;

			clearTimeout(this.timer);

			jaMegaHoverOutOther (this);

			if (this.hasClass ('haschild')) this.removeClass ('haschild').addClass ('haschild-over');

			else this.addClass ('over');

			if (this.a) {

				this.a.addClass ('over');

			}

		});

		li.addEvent('mouseleave', function(e) {

			this.timer = setTimeout(jaMegaHoverOut.bind(this, e), 500);

		});

	});

	function jaMegaHoverOut(e) {

		clearTimeout(this.timer);

		if (this.hasClass ('haschild-over')) this.removeClass ('haschild-over').addClass ('haschild');

		else this.removeClass ('over');

		if (this.a) {

			this.a.removeClass ('over');

		}

	}

	function jaMegaHoverOutOther(el) {

		sfEls.each (function(li) {

			if (li != el && !li.hasChild (el)) {

				if (li.hasClass ('haschild-over'))

					li.removeClass ('haschild-over').addClass ('haschild');

				else

					li.removeClass ('over');

				if (li.a) {

					li.a.removeClass ('over');

				}

			}

		});

	}

});
