var headlines;
var currentHeadline = 0;

//page load events.
Event.observe(window,'load',function() {
	handleHighlights();
	headlines = $$('.NewsHeadline').toArray();
	toggleHeadline();
});

//handle the 3 images on the bottom of the page.
function handleHighlights() {
	if($('Highlights')) {
		$('Highlights').select('img').each(function(linkImage){
			Event.observe(linkImage,'mouseover',function() {
				this.noHoverImage = this.src;
				this.src = this.getAttribute('hoverImage');
			});
			Event.observe(linkImage,'mouseout',function() {
				this.src = this.noHoverImage;
			});
			Event.observe(linkImage,'click',function() {
				window.location = this.getAttribute('url');
			});
		});
	}
}

//handle the news headline ticker.
function toggleHeadline() {
	if(headlines[currentHeadline]) {
		Effect.Fade(headlines[currentHeadline],{duration:0.5,queue:'end'});
		currentHeadline = (currentHeadline+1) % (headlines.length);
		Effect.Appear(headlines[currentHeadline],{duration:0.2,queue:'end'});
		setTimeout('toggleHeadline()', 2250);
	}
}

//Menu functions
menu = {timer : null, current : null};
menu.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	if($(name)) $(name).setStyle({visibility:'visible'});
	currentTab = $(name+'Tab');
	if(currentTab.state != 1) {
		currentTab.state = 1;
		currentTab.oldSrc = currentTab.src;
		currentTab.src = '/images/nav/'+name+'Over.gif';
	}
	this.current = name;
}
menu.hide = function(){
	this.timer = setTimeout("menu.doHide()",300);
}
menu.doHide = function(){
	if(this.current){
		if($(this.current)) $(this.current).setStyle({visibility:'hidden'});
		currentTab = $(this.current+'Tab');
		currentTab.state = 0;
		currentTab.src = currentTab.oldSrc;
		this.current = null;
	}
}