﻿window.addEvent('domready', function() {
  initializeMenu('home', 'homeLink', 'homeBar');  
  initializeMenu('studyOverview', 'studyOverviewLink', 'studyOverviewBar');
//  initializeMenu('schedule', 'scheduleLink', 'scheduleBar');
  initializeMenu('getInvolved', 'getInvolvedLink', 'getInvolvedBar');
  initializeMenu('CAG', 'CAGLink', 'CAGBar');
  initializeMenu('studyDocuments', 'studyDocumentsLink', 'studyDocumentsBar');
  initializeMenu('bigPicture', 'bigPictureLink', 'bigPictureBar');
  initializeMenu('contactUs', 'contactUsLink', 'contactUsBar');
});

function initializeMenu(elementId, linkId, barId) { 
  var element = $(elementId);
  var link = $(linkId);
  var bar = $(barId);
  
  var morph = new Fx.Morph(link, {duration: 150, link: 'cancel'});   
  var tween = new Fx.Tween(bar, {duration: 150, link: 'cancel'});  
  
  element.addEvents({
    'mouseenter': function(e) {
      if (!element.hasClass('selected')) {
        e.stop();
        morph.start({		
		      //color: '#7abbe6'
		      color: '#145DAA'
	      });
        tween.start('height', '6px');
        bar.fade(1);           
      }
    },
    'mouseleave': function(e) {    
      if (!element.hasClass('selected')) {              
        e.stop();
        morph.start({		
		      //color: '#617eaa'
		      color: '#D19558'
	      });
        tween.start('height', '0'); 
        bar.fade(0);        
      }
    }
  });    
}