	Core.onload(function(){
		Core.SubAnimate.init();
		Core.sidebar.init();
	});

	Core.sidebar = {
		init: function(){
			var sidebar = $('sidebar');
			if(sidebar){
				var listItems = sidebar.getElementsByTagName("li"); //get all child list items 
				var el;
				for(i=0, j=listItems.length; i<j; i++){
					if(!Core.hasClass(listItems[i].parentNode, "sub")){ //if the parent node is not sub-nav
						if(!Core.hasClass(listItems[i], "active")){ //if the li is not active
							el = listItems[i];
							Core.sidebar.addEvents(el);
						}
					}
				}
			}
		},
		
		addEvents: function(el){
			Core.attachEvent(el, 'mouseover', function(e){
				Core.setStyle(el, {background: '#f4f4f4 url(/img/sidebar_bg.gif) bottom left repeat-x'}); //root referenced - will only work on server
			});
			Core.attachEvent(el, 'mouseout', function(e){
				Core.setStyle(el, {background: '#f8f8f8'});
			});
			Core.attachEvent(el, 'click', function(e){ //necessary for when using back/forward browser buttons
				Core.setStyle(el, {background: '#f8f8f8'});
			});
		}				
	};
	
	Core.SubAnimate = {
		init: function(){
			var sub = $$('sub', document.body, 'ul')[0];
			if(sub){
				Core.setFade(sub,0);
				var h1=0;
				var h2=sub.offsetHeight + 20; //get the height of the sub-nav plus 20px
				var s = {display:'block',height:h1+'px',overflow:'hidden'};
				Core.setStyle(sub,s);
				new Core.Animator(sub,h1,h2, function(o,v){Core.setStyle(o,{height:v+'px'});}, 2000, Core.SubAnimate.fadeSubIn(sub));
			}
		},

		fadeSubIn: function(theSub){
			Core.Animate.fadeIn(theSub, 100, 2000);
		}
	}