// section and page titling and subheadline animation
var pageName = "";
var subHeadline = "";

// menu control things
var currentMenu = "";
var closeTimer = -1;

// section over and out colors
var colors = {
	"Services":		{ "over": "#afc5e6", "out": "#eff3fa" }, 
	"Packages":		{ "over": "#bfbfbf", "out": "#e5e5e5" }, 
	"Wellness":		{ "over": "#1e61ac", "out": "#d2dfde" }, 
	"Testimonials":	{ "over": "#b5b716", "out": "#f0f1d0" }, 
	"Articles":		{ "over": "#dfdcc0", "out": "#f9f8f2" } 
};

function trace( m ) {
	$('tracer').innerHTML += m + "<br />\n";
}

function navToString( nav ) {
	return $(nav).getAttribute( "id" ).substr( 3 ).toLowerCase();
}

function menuToString( menu ) {
	return $(menu).getAttribute( "id" ).substr( 4 ).capitalize();
}

function navMouseOver( nav ) {
	var pageType = pageName == "home" ? "home" : "int";
	$(nav).src = "images/" + pageType + "_topnav_" + navToString( nav ) + "_over.gif";
}

function navMouseOut( nav ) {
	if( pageName != "home" && pageName.toLowerCase() == navToString( nav ) ) {
		// don't switch vert nav images back to lighter color when we're in that section
		return;
	}
	var pageType = pageName == "home" ? "home" : "int";
	$(nav).src = "images/" + pageType + "_topnav_" + navToString( nav ) + ".gif";
}

function openMenu( menu ) {
	if( !$("menu" + menu) || $("menu" + menu).getAttribute( "active" ).toLowerCase() != "yes" ) {
		return;
	}
	clearTimeout( closeTimer ); // always kill timer when opening a menu
	if( currentMenu != menu && currentMenu != "" ) {
		closeMenu( true ); // close immediately
	}
	$("menu" + menu.toLowerCase().capitalize()).show();
	currentMenu = menu.toLowerCase().capitalize();
}

function closeMenu( immediate ) {
	if( currentMenu == "" ) {
		return;
	}
	if( arguments.length == 0 ) {
		immediate = false;
	}
	if( immediate ) {
		clearTimeout( closeTimer );
		$("menu" + currentMenu.toLowerCase().capitalize()).hide();
		currentMenu = "";
	} else {
		closeTimer = setInterval( function () {
			$("menu" + currentMenu.toLowerCase().capitalize()).hide();
			currentMenu = "";
			clearTimeout( closeTimer );
		}, 250 );
	}
}

function setupDropdown( ddName ) {
	$("menu" + ddName).hide();
	$("menu" + ddName).setOpacity( 0.9 );
	var xOffset = 5; //isIE() ? 15 : 5;
	var yOffset = -6; //isIE() ? 9 : -6;
	moveElement( "menu" + ddName, getElementX( "nav" + ddName ) + xOffset, getElementY( "nav" + ddName ) + getElementHeight( "nav" + ddName ) + yOffset );
	$$("#menu" + ddName + " a").each( function ( a ) {
		$(a).style.color = "#636363";
		$(a).onmouseover = function () {
			$(a).style.color = colors[ddName].over;
		};
		$(a).onmouseout = function () {
			$(a).style.color = "#636363";
		};
	} );
}

function pageSetup() {
	if( pageName == "home" ) {
		// put flash in its place on the home page
		var so = new SWFObject( "flash/home.swf", "homeswf", "380", "229", "9", "#fff" );
		so.addParam( "quality", "best" );
		so.addParam( "align", "tl" );
		so.write( "flashDiv" );
	} else if( ![ "staff", "photos", "giftcerts", "specials", "contact" ].contains( pageName.toLowerCase() ) ) {
		// make current interior page vertical nav darker version of color
		$("nav" + pageName).src = "images/int_topnav_" + pageName.toLowerCase() + "_over.gif";
	}
	// in order to get the bars to butt up against each other, we need to strip whitespace out from between
	$("navHeader").cleanWhitespace();
	// position and hide the vertical nav dropdowns, also fix the rollovers for the links contained in the dropdowns
	$$(".dropDownMenu").each( function ( ddm ) {
		if( ddm.getAttribute( "active" ).toLowerCase() == "yes" ) {
			// only fully setup menus that are marked as active
			setupDropdown( menuToString( ddm ) );			
		}
		// hide all menus, active or not, in the beginning
		$("menu" + menuToString( ddm )).hide();
	} );
	if( pageName != "home" ) {
		if( subHeadline == "" ) {
			$('subHeader').hide();
		} else {
			// start the subheadline at fully transparent
			$("subHeader").setOpacity( 0 );
			// set the aniimated header's color
			$("subHeader").className = pageName + "Over";
			// set the headline
			$("subHeader").innerHTML = subHeadline;
			// slide the subHeader little thing into place on pages that use it
			new Effect.Move( 
				$("subHeader"), 
				{ 
					x: -250, 
					y: 0, 
					mode: 'relative',
					beforeStart: function ( el ) {
						new Effect.Opacity( $("subHeader"), { duration: 1.0, from: 0.0, to: 1.0 } );
					} 
				} 
			);
		}
	}
	if( $("photosMap") ) {
		$("photosMap").cleanWhitespace();
	}
}

var currentPhoto = 'imgReception';

function selectPhoto( showThis ) {
	$(currentPhoto).hide();
	currentPhoto = showThis;
	$(showThis).show();
}

var currentArticle = 'article1';

function selectArticle() {
	$(currentArticle).hide();
	currentArticle = $('selArticles').value;
	$(currentArticle).show();
}
