
// Homepage Feature Area Slideshow
function setHomepageFeature(whichFeature, overrideSlideshow){
	// whichFeature: integer 1-n, representing which link to show
	// overrideSlideshow: boolean - if true, slideshow stops.
	
	// user-controlled tabs on homepage
	
	// restyle the link buttons themselves
	
	linkDiv = $("homepageFeatureLink_" + whichFeature);
	oldLinkDiv = $("homepageFeatureLink_" + document.currentFeature);
	if ($(oldLinkDiv)){
		oldLinkDiv.style.background = 'url("http://cahce.babyzone.com/inc/img/clear.gif")';
	}
	linkDiv.style.background = 'url("http://cahce.babyzone.com/inc/img/front/featureLinkBackgroundOn.gif")';
	
	//hide the old display panel, show the new one
	
	featureDisplayDiv = $("homepageFeature_" + whichFeature);
	oldFeatureDisplayDiv = $("homepageFeature_" + document.currentFeature);
	if ($(oldFeatureDisplayDiv)){
		oldFeatureDisplayDiv.style.display = 'none';
	}
	featureDisplayDiv.style.display = 'block';
	
	// save reference to the currently-viewed feature
	document.currentFeature = whichFeature;
	if (overrideSlideshow){
		clearTimeout(document.slideshowTimer);
	}
}

function initializeHomepage(){
	document.currentFeature = 0;
		runSlideshow(true, true);
	}
function initializePage(){
	return true;
}
function runSlideshow(direction, keepRunning){
	// advance the slideshow one step
	// direction: boolean - if true, forwards, if false backwards
	// keepRunning: boolean - if true, slideshow continues (forward) via time-delay, if false, it stops.
	
	if (direction){
		// forward
		nextFeature = document.currentFeature + 1;
		//alert("runslideshow seeks " + nextFeature);
		if (!($("homepageFeatureLink_" + nextFeature))){
			// if that element doesn't exist, reset to 1.
			nextFeature = 1;
		}
	} else {
		// backward
		if (document.currentFeature == 1){
			// we're at the beginning
		} else {
			nextFeature = document.currentFeature -1;
		}
		
		if (!($("homepageFeatureLink_" + nextFeature))){
			// if that element doesn't exist, reset to 1.
			nextFeature = 1;
		}
	}
	setHomepageFeature(nextFeature);
	
	if (keepRunning){
		document.slideshowTimer = setTimeout("runSlideshow(true, true)",3000);
	} else {
		clearTimeout(document.slideshowTimer);
	}
}

/// select menu navigation
function selectMenuNavigation(selectId){
	newUrl = $(selectId).options[$(selectId).selectedIndex].value;
	if (newUrl != "#"){
		window.location.href = newUrl;
	}
}