var MainNavigation = Class.create({
	
	nav : '',
	closing: null,
	opening: null,
	timeout: 0,
	speed: 150, // old 300

	initialize: function( nav ){
		this.nav = jQuery('#'+nav);
		this.nav.children().each( (function(i,el){
			// mof b women bike
			var liClass = jQuery(el).attr('class')
//			console.log(liClass.substring(0, 14));
			if(liClass.substring(0, 27) != 'bike level0 nav-2 level-top'){			
			// mof e
			jQuery(el).mouseenter( (function(e){
				this.opening = jQuery(e.currentTarget);
				if( this.closing == null ) {
					if(this.timeout){
						clearTimeout(this.timeout);
						this.timeout = 0;
					}
					this.timeout = setTimeout( this.fireOpenWithTimeout.bind(this), this.speed );
				}
			}).bind(this));
			jQuery(el).mouseleave( (function(e){
				if(this.timeout && !this.closing){
					clearTimeout(this.timeout);
					this.timeout = 0;
					this.opening = null;
					return;
				} else if(this.closing){
					if( this.opening.get(0) == e.currentTarget ) this.opening = null;
					return;
				}
				this.closing = jQuery(e.currentTarget);
				this.timeout = setTimeout( this.fireCloseWithTimeout.bind(this), this.speed );
			}).bind(this));
			// mof b women bike
			}
			// mof e
		}).bind(this));
		if(jQuery.browser.msie && jQuery.browser.version=="6.0" && !level){
			document.execCommand("BackgroundImageCache", false, true);
		}
	},
	
	fireCloseWithTimeout: function(){
		if( this.closing ) {
			this.closing.removeClass("over").children('ul').stop(true,true).slideUp('fast', this.handleQueue.bind(this) );
			this.timeout = 0;
		}
	},
	
	fireOpenWithTimeout: function(){
		if(this.opening){
			this.opening.stop(true,true).addClass('over').children('ul').addClass('shown-sub').hide().slideDown();
			this.timeout = 0;
			this.opening = null;
		}
	},
	
	handleQueue : function( action ) {
		if( this.closing != null ) { 
			this.closing.stop(true,true).removeClass('shown-sub');
			this.closing = null;
			if(this.opening){
				this.opening.stop(true,true).addClass('over').children('ul').addClass('shown-sub').hide().slideDown();
				this.opening = null;
			}
		}
	}
});


document.observe('dom:loaded', function() {
	try{
		var mainNav = new MainNavigation("nav");
	} catch( e ) {
		//console.log(e);
	}
});
