(function(){
	
	var RemoteCourseBase = function(options){
		//Chain parent constructor
		//RemoteCourseBase.superclass.constructor.call(this, options);
		this.timers = {};
		this.options = {};
		this.init();
	};
	
	RemoteCourseBase.prototype = {
		
		/**
		* I initialize everything after the Constructor is called
		* @return void
		*/
		init: function(){
			
			//call super class init() method if necessary
			//RemoteCourseBase.superclass.init.call(this);
			
			//initialize the right accordion
			if (typeof YAHOO.com.webucator.Accordion != 'undefined'){
				this.rightAccordion = new YAHOO.com.webucator.Accordion('rightContainer', 'rightPodContainer', 'rightPodHeader', 'rightPodContent');
			}
			
			//initialize all popups
			if (typeof YAHOO.com.webucator.Popup != 'undefined') {
		  		this.popup = new YAHOO.com.webucator.Popup();
		  	}
			
			this.navigationInit();
			
			
		},
		
		/**
		* I set the Class configuration options object with the default options
		* @param options <Object> (optional) If present, it will be used to set the options for the current class.
		* @return void
		*/
		setOptions: function(options){
			var o = {
				navigationTopHideDelay: 300,
				navigationSubShowDelay: 300
			};
			YAHOO.lang.augmentObject(o, options || {}, true);
			RemoteCourseBase.superclass.setOptions.call(this, o);
		},
		
		
		
		/**
		* I attach the event handlers to each top level navigation node
		* @param node <HTML Element> The top level node element
		* @return void
		*/
		navigationAttachEvents: function(node){
			var id = YAHOO.util.Dom.generateId(node);
			var subNavContainerId = id +'-subNav';
			
			if (typeof this.navigationSubNavs == 'undefined'){
				this.navigationSubNavs = {};
			}
				
			if ($(subNavContainerId)){
				YAHOO.util.Event.on(node, 'mouseover', function(e){
					YAHOO.util.Event.stopPropagation(e);
					var target = YAHOO.util.Event.getTarget(e);
					var id = target.id;
					//Lazy creation of the sub nav panel
					if (typeof this.navigationSubNavs[id] == 'undefined'){
						this.navigationSubNavs[id] = new YAHOO.widget.Panel(subNavContainerId, {
							visible: false,
							draggable: false,
							constraintoviewport: false,
							close: false,
							context: [id, "tl", "bl"]
						});
						$(subNavContainerId).style.display = 'block';
						this.navigationSubNavs[id].render();
					}
					this.navigationClearTimeouts();
					this.navigationClearHover();
					this.navigationSetTimer('SHOWTOP',{id:id});
				}, this, true);
				YAHOO.util.Event.on(node, 'mouseout', this.navigationHide, this, true);
				YAHOO.util.Event.on(subNavContainerId, 'mouseover', this.navigationClearTimeouts, this, true);
				YAHOO.util.Event.on(subNavContainerId, 'mouseout', this.navigationHide, this, true);
			}else{
				YAHOO.util.Event.on(node, 'mouseover', function(e){
					YAHOO.util.Event.stopPropagation(e);
					this.navigationClearTimeouts();
					this.navigationClearHover();
					this.navigationSetTimer('SHOWTOP',{id:id});
				}, this, true);
				YAHOO.util.Event.on(node, 'mouseout', this.navigationClearHover, this, true);
			}
		},
		
		/**
		* I clear the hover state for the top level navigation nodes
		* @return void
		*/
		navigationClearHover: function(){
			//remove active class from all top level1node elements
			var level1nodes = YAHOO.util.Selector.query('div#topNavBarContainer ol.level1 li div.level1heading');
			for (var i=0; i< level1nodes.length; i++){
				if (YAHOO.util.Dom.hasClass(level1nodes[i],'hover')){
					YAHOO.util.Dom.removeClass(level1nodes[i], 'hover');
				}
				if (window.webucator.navigationSubNavs[level1nodes[i].id]){
					window.webucator.navigationSubNavs[level1nodes[i].id].hide();
				}
			}
		},
		
		/**
		* I clear the top level navigation timeouts
		* @return void
		*/
		navigationClearTimeouts: function(){
			if (this.timers[this.HIDETOP] != null){
				window.clearTimeout(this.timers[this.HIDETOP]);
			}
			if (this.timers[this.SHOWTOP] != null){
				window.clearTimeout(this.timers[this.SHOWTOP]);
			}
		},
		
		/**
		* I clear the hover state after a short time out
		* @return void
		*/
		navigationHide: function(){
			this.navigationClearTimeouts();
			this.navigationSetTimer('HIDETOP');
		},
		
		/**
		* I initialie the top level navigation
		* @return void
		*/
		navigationInit: function(){
			this.HIDETOP = 1;
			this.SHOWTOP = 2;
			var level1nodes = YAHOO.util.Dom.getElementsByClassName('level1heading');
			for (var i=0; i<level1nodes.length; i++){
				var level1node = level1nodes[i];

				//remove inner <a> tag and append event handler to div
				
				while (level1node.childNodes.length >= 1){
					var text = level1node.firstChild.innerHTML;
					var href = level1node.firstChild.href;
					if (typeof href != 'undefined' && href != null){
						YAHOO.util.Event.on(level1node, 'click', function(e, params){
							window.location.href = params.href;
						}, {href:href});
					}
					level1node.removeChild(level1node.firstChild);
				}
				level1node.innerHTML = text;
				//attach event handlers to leve1node div
				this.navigationAttachEvents(level1node);
				
			}
		},
		
		/**
		* I set the timers for the top level navigation
		* @param type <String> The time type to set
		* @param params <Object> An object of parameters to pass to the callback
		* @return void
		*/
		navigationSetTimer: function(type,params){
			switch (type.toUpperCase()){
				case 'HIDETOP':
					this.timers[this[type]] = window.setTimeout(this.navigationClearHover, this.options.navigationTopHideDelay);
				break;
				case 'SHOWTOP':
					YAHOO.util.Dom.addClass(params.id, 'hover'); 
					var callback = "if (window.webucator.navigationSubNavs['"+params.id+"']){window.webucator.navigationSubNavs['"+params.id+"'].show();}";
					this.timers[this[type]] = window.setTimeout(callback, this.options.navigationSubShowDelay);
				break;
			}
		},
		
		
	};
	
	//YAHOO.lang.extend(RemoteCourseBase, YAHOO.com.webucator.Base, proto);
	YAHOO.com.webucator.Base = RemoteCourseBase;
})();
