byu.feature = {
	transitionSpeed : 750,//how many milliseconds for fade to take
	
	loadFeatures : function() {
		var featureContainer = $("Features");
		var featureSelector = $("FeatureSelector");
		var featureStories = byu.util.getElementsByClassName("featureStory", featureContainer, "DIV");
		
		byu.setInnerText(featureSelector, "");
		for(var i=0; i<featureStories.length; ++i)
		{
			var storyLink = byu.createElement("a",{"className":"storyLink","href":"javascript:byu.none();"});
			byu.setInnerText(storyLink,"Feature Story %s".format(i + 1));
			
			storyLink.parentContainer = featureContainer;
			storyLink.story = featureStories[i];
			
			byu.event.observe(storyLink, "click", byu.makeBound(storyLink,function(){
				var thisStoryLink = this;
				byu.effects.fade(this.parentContainer,byu.feature.transitionSpeed,"out", function(){
					byu.css.removeClass(thisStoryLink.parentContainer.currentStory,"selected");
					byu.map(thisStoryLink.parentNode.childNodes,function(e){
						byu.css.removeClass(e,"selected");
					});
					byu.css.addClass(thisStoryLink,"selected");
					byu.css.addClass(thisStoryLink.story,"selected");
					thisStoryLink.parentContainer.currentStory = thisStoryLink.story;
					byu.effects.fade(thisStoryLink.parentContainer,byu.feature.transitionSpeed,"in");
				});
			}));
			
			featureSelector.appendChild(storyLink);
		}
		
		var randomStart = Math.abs(Math.round(Math.random() * featureStories.length) - 1);
		if(randomStart > featureStories.length - 1 || randomStart < 0)
		{
			randomStart = 0;
		}
		byu.css.addClass(featureStories[randomStart],"selected");
		byu.css.addClass(featureSelector.childNodes[randomStart],"selected");
		featureContainer.currentStory = featureStories[randomStart];
	}
};

byu.event.observe(window, 'load', byu.feature.loadFeatures);