//--- www.astorservices.org -------------------
//--- menus.js
//--- javascript for menus
//--- this also covers footer positioning (footer positioning script is in sitescripts.js);
//--- this also covers constant contact mailinglist button hover events

//--- NOTE: onload and onresize functions are at the bottom of this file

//function test() {
//	if (document.execCommand) {
//		alert('IE6?');
//		}
//	}

//-- Note: variables "thissection" and "thispage" are set by PHP and placed as JS variables in the header of the page;
//-- "thissection" is the id of the section menu <a> tag;
//-- thissection + -menu is the id of the page menu <div> tag;
//-- "thispage" is the id of the page menu <a> tag;
//-- thispage is also set as a literal class name of the <a> tag by this script;
//-- Check to see if thissubmenu variable is set on the page and set one if not:
if (!(thissubmenu)) {
	var thissubmenu = "no-submenu";
	}

function thisSectionlink() {
if (document.getElementById(thissection)) {
	document.getElementById(thissection).className = "top-link thissectionlink";
	}
}

function thisSection() {
if (document.getElementById(thissection + '-menu')) {
	document.getElementById((thissection + '-menu')).className = "section-menu thissection";
	}
if (!(document.getElementById(thissection))) {
	document.getElementById('home-menu').className = "section-menu thissection";
	}
}

//function thisPage() {
//if (document.getElementById(thispage)) {
//	document.getElementById(thispage).className = "thispage";
//	}
//}

function thisSubmenu() {
if (document.getElementById(thissubmenu)) {
	document.getElementById(thissubmenu).className = "subsection-menu";
	}
}

function resetSection() {	
	thisSectionlink();
	thisSection();
//	thisPage();
	thisSubmenu();
}

function hoverSection() {
	//--   set what style changes happen to the hovered-over section on mouseout: function mouseAway() {
	
	function mouseAway() { 
		this.className = "section-menu";
		document.getElementById(idOfThisSectionLink).className = "top-link";
		}
	    	
	//-- get the id of the hovered-over section-menu:
		var idOfThisSectionMenu = this.id;
		
	//-- create variable to identify corresponding section link (top menu link)
		var idOfThisSectionLink = idOfThisSectionMenu.replace(/-menu/,"");
		
	//-- change the hovered-over section to selected state:
		document.getElementById(idOfThisSectionMenu).className = "section-menu hoveredsection";
		
	//-- change the pre-selected link to a default state:	
		if (document.getElementById(thissection)) {
			document.getElementById(thissection).className = "top-link";
			}
		
	//-- change the corresponding link to selected state:
	if (document.getElementById(thissection)) {
		if (idOfThisSectionLink == (document.getElementById(thissection).id)) {
			document.getElementById(idOfThisSectionLink).className = "top-link thissectionlink";
			} else {
				document.getElementById(idOfThisSectionLink).className = "top-link thissectionmenuhover";
			}
		}
		
	//-- change the hovered-over section back to default on mouseout:
		this.onmouseout = mouseAway;
		//this.onmouseout = setTimeout(mouseAway, 300);
}
	
function changeMenu() {
	//--   set what style changes happen to the hovered-over link on mouseout: function mouseAway() {
	function mouseAway() {
    	this.className = "top-link";
    	if ((idOfThis) !== (thissection)) {
    		document.getElementById((idOfThis + '-menu')).className = "section-menu";
    		}
    	}
		
	//--   get the id of the hovered-over link:
		var idOfThis = this.id;
	
	//-- change the pre-selected link to a default state:	
		if (document.getElementById(thissection)) {
		document.getElementById(thissection).className = "top-link";
		}
		
	//--   change the style property(s) of the hovered-over element:
		if (this == (document.getElementById(thissection))) {
			this.className = "top-link thissectionlink";
			} else {
		this.className = "top-link thissectionlinkhover";
		}
		
		
	//-- change the corresponding section to selected state:
		if (document.getElementById((idOfThis + '-menu'))) {
    		document.getElementById((idOfThis + '-menu')).className = "section-menu hoveredsection";
    		}
		
	//-- change the hovered-over link back to default on mouseout:
		this.onmouseout = mouseAway;
	
}

function showSubmenu() {
		
	//--   set what style changes happen to the appropriate submenu on mouseout: function mouseAway() {
	function mouseAway() {
		document.getElementById(idOfThisSubmenu).className = "subsection-menu";
    	}
   //--  change the submenu class on mouseover
   function changeSubmenuClass() {
   	//-- change the appropriate submenu to selected state:
		document.getElementById(idOfThisSubmenu).className = "subsection-menu thissubmenu";
   	}
	    	
	//-- get the id of the hovered-over trigger link:
		var idOfThisLink = this.id;
	//-- make an identifier for the corresponding sub-menu
		var idOfThisSubmenu = idOfThisLink + "-submenu";
   
   
   //-- change the appropriate submenu to selected state: 
   changeSubmenuClass();	
   //-- make sure the menu stays visible when mousing off the trigger link and onto the submenu
   	document.getElementById(idOfThisSubmenu).onmouseover = changeSubmenuClass;	
    	
	//-- change the appropriate submenu back to default on mouseout:
		document.getElementById(idOfThisSubmenu).onmouseout = mouseAway;
		document.getElementById(idOfThisLink).onmouseout = mouseAway;
}

function mailingListButtonMouseover() {
	document.getElementById('go').style.backgroundPosition = "0 0";
	}
function mailingListButtonMouseout() {
	document.getElementById('go').style.backgroundPosition = "0 -51px";
	}

//------------------------------------------------------------------------------
//--- onload and onresize functions:

function init() {
			setFooter();
			externalLinks();
			thisSectionlink();
			thisSection();
			thisSubmenu();
//			thisPage();
			document.getElementById('menus-area').onmouseout = resetSection;
			
      	document.getElementById('home').onmouseover = changeMenu;
      	document.getElementById('about-astor').onmouseover = changeMenu;
      	document.getElementById('our-services').onmouseover = changeMenu;
      	document.getElementById('news-events').onmouseover = changeMenu;
      	document.getElementById('you-can-help').onmouseover = changeMenu;
      	document.getElementById('training').onmouseover = changeMenu;
      	document.getElementById('more').onmouseover = changeMenu;
      	document.getElementById('contact-us').onmouseover = changeMenu;
      	
      	if (document.getElementById('home-menu')) {
          	document.getElementById('home-menu').onmouseover = hoverSection;
          	}
         if (document.getElementById('about-astor-menu')) {
          	document.getElementById('about-astor-menu').onmouseover = hoverSection;
          	}
      	if (document.getElementById('our-services-menu')) {
          	document.getElementById('our-services-menu').onmouseover = hoverSection;
          	}
         if (document.getElementById('news-events-menu')) {
          	document.getElementById('news-events-menu').onmouseover = hoverSection;
          	}
         if (document.getElementById('you-can-help-menu')) {
          	document.getElementById('you-can-help-menu').onmouseover = hoverSection;
          	}
         if (document.getElementById('training-menu')) {
          	document.getElementById('training-menu').onmouseover = hoverSection;
          	}
         if (document.getElementById('more-menu')) {
          	document.getElementById('more-menu').onmouseover = hoverSection;
          	}
         if (document.getElementById('contact-us-menu')) {
          	document.getElementById('contact-us-menu').onmouseover = hoverSection;
          	}
      	
      	if (document.getElementById('go')) {
      		document.getElementById('go').onmouseover = mailingListButtonMouseover;
      		document.getElementById('go').onmouseout = mailingListButtonMouseout;
      		}
      	
        document.getElementById('residential').onmouseover = showSubmenu;
      	
      	//if (thissection == "home") {
      	//	homeFeed();
      	//	}
      	if (document.getElementById('rolloverfour-b')) {
      	document.getElementById('t01').onmouseover = viewImage;
      	document.getElementById('t02').onmouseover = viewImage;
      	document.getElementById('t03').onmouseover = viewImage;
      	document.getElementById('t04').onmouseover = viewImage;
      	document.getElementById('t05').onmouseover = viewImage;
      	document.getElementById('t06').onmouseover = viewImage;
      	document.getElementById('t07').onmouseover = viewImage;
      	document.getElementById('t08').onmouseover = viewImage;
      	document.getElementById('t09').onmouseover = viewImage;
      	document.getElementById('t10').onmouseover = viewImage;
      	document.getElementById('t11').onmouseover = viewImage;
      	document.getElementById('t12').onmouseover = viewImage;
      	origImg();
      	//preloadImages();
      	setTimeout('loadImages()',200);
    		//dropShadowArray();
      	}
      	if (document.getElementById('page-event-photos')) {
      	document.getElementById('t13').onmouseover = viewImage;
      	document.getElementById('t14').onmouseover = viewImage;
      	document.getElementById('t15').onmouseover = viewImage;
      	document.getElementById('t16').onmouseover = viewImage;
      	document.getElementById('t17').onmouseover = viewImage;
      	document.getElementById('t18').onmouseover = viewImage;
      	document.getElementById('t19').onmouseover = viewImage;
      	document.getElementById('t20').onmouseover = viewImage;
      	document.getElementById('t21').onmouseover = viewImage;
      	document.getElementById('t22').onmouseover = viewImage;
      	document.getElementById('t23').onmouseover = viewImage;
      	document.getElementById('t24').onmouseover = viewImage;
      	}
      	if (document.getElementById('page-soc-workshops')) {
      	document.getElementById('reference').onmouseover = changePseudolink;
      	}
      	if (document.getElementById('page-news')) {
      	onOff('news-archive');
      	}
}
window.onload = init;
		
window.onresize = function() {
			setFooter();
};

