// JavaScript Document
sfHover = function() {
	var sfUls = document.getElementsByTagName('ul');
	for( var j=0; j<sfUls.length; j++ ){
	  if( sfUls[j].className.indexOf('sf_menu')==-1 ) continue;
	  
	  var sfEls = sfUls[j].getElementsByTagName("li");
	  for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			cat = ($(this).attr('page').indexOf('top_')!=-1 ) ? 'head' : 'sub';
			latest[cat]=this;
			top_idx = this.className.indexOf('top');
			if(top_idx!=-1){
				this.className+= " top"+  this.className.substring(top_idx+3,top_idx+4) + "_sfhover sfhover";
			}else
				this.className+=" sfhover";
			//if(event.cancelBubble!= undefined) event.cancelBubble = true;
			//alert(this.className)
		}
		sfEls[i].onmouseout=function() {
			cat = ($(this).attr('page').indexOf('top_')!=-1 ) ? 'head' : 'sub';
			DelayfadeThis(this,cat);
			//if(event.cancelBubble!= undefined) event.cancelBubble = true;
			//alert(this.className)
		}
	  }
	}
	
}

var latest={ "head":null , "sub":null};
var delay_pool={ "head":[] , "sub":[]};

function clean_pool(cat){
	for( p in delay_pool[cat]){
		if( latest[cat] != delay_pool[cat][p].obj ) (delay_pool[cat][p])();

	}
}

function DelayfadeThis(e,cat){
	//	clean_pool();
	//	delay_pool.push( function(){ fadeThis(e) } );
	//	setTimeout( clean_pool , 300);
		setTimeout( function(){ fadeThis(e) } , 300);
}
function DelayfadeThis2(e,cat){
		
		clean_pool(cat);
		f = function(){ fadeThis(e) }
		f.obj = e;
		delay_pool[cat].push( f );
		setTimeout( function(){clean_pool(cat) }, 300);

}
function fadeThis(e){
		e.className=e.className.replace(new RegExp("( top[0-9]_sfhover)? sfhover\\b"), "");
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
else{ $( function() { sfHover() } ) }
