/****************************************************
#####################################################
##-------------------------------------------------##
##            RY River - Version 1.0.1             ##
##-------------------------------------------------##
## Copyright = Raya Web Design - 2010              ##
## Date      = 02 November 2010                    ##
## License   = free template                       ##
## Author    = Heri siswanto                       ##
## Websites  = http://www.rayawebdesign.com        ##
##                                                 ##
#####################################################
****************************************************/

//Call noconflict if detect jquery
//Apply jquery.noConflict if jquery is enabled
if ($defined(window.jQuery) && $type(jQuery.noConflict)=='function') {
	jQuery.noConflict();
	jQuery.noConflict();
}

window.addEvent ('domready', function() {
	var sfEls = $$('div.ry-mainnav ul li');
	sfEls.each (function(li) {
		if ((a = li.getElement('a')) && li.hasChild (a)) li.a = a;
		else li.a = null;
	});	
	sfEls.each (function(li){
		li.addEvent('mouseenter', function(e) {
			clearTimeout(this.timer);
			if(this.hasClass("havechild")) this.addClass('havechildsfhover').removeClass('havechild');
			else if(this.hasClass("havesubchild")) this.addClass('havesubchildsfhover').removeClass('havesubchild');
			this.addClass ('sfhover');
			if (this.a) this.a.addClass ('sfhover');
		});
		li.addEvent('mouseleave', function(e) {
			this.timer = setTimeout(sfHoverOut.bind(this, e), 100);
		});
	});
});

function sfHoverOut() {
	clearTimeout(this.timer);
	if(this.hasClass("havechildsfhover")) this.addClass('havechild').removeClass('havechildsfhover');
	else if(this.hasClass("havesubchildsfhover")) this.addClass('havesubchild').removeClass('havesubchildsfhover');
	this.removeClass ('sfhover');
	if (this.a) this.a.removeClass ('sfhover');
}

