
// //
// Discovery Home and Health Javascript
// May 2006
window.onload = _hh_init

function _hh_init() {

	//make_slideshow()
	//make_article_links()
	make_module_links()

}

// 
// if the #body div has a width of 750px, then CSS might well be enabled! add a few more for more accuracy
//
function css_enabled() {
	// return (document.getElementById("body").offsetWidth==750)?true:false;
	return true;
}


// 
// javascript assisted linking for homepage articles. makes whole div clickable ... by using the 1st <a> tag href info
// each clickable module must have an id of "homemodule" + sequential number (starting from 1)
//
/*
function make_article_links() {
	var home_module=1;
	while (eval("document.getElementById('homemodule"+home_module+"')")) {
		hm=document.getElementById("homemodule"+home_module)
		hm.style.cursor="pointer";
		hm.onclick=function() {
			if (css_enabled()) {
				(document.all)?this.getElementsByTagName("a")[0].click():location.href=this.getElementsByTagName("a")[0].href;
			}
		}
		home_module++
	}
}
*/

//
// find all divs with class name "modulexxx", with a single link, and make the whole div clickable to the <a>'s href
// oh, and only if css is enabled

function make_module_links() {

	divs=document.getElementsByTagName("div")
	for (var i=0; i<divs.length; i++) {
		if (divs[i].className.indexOf("module") !==-1) {
			if ((divs[i].getElementsByTagName("a").length > 0) && (divs[i].getElementsByTagName("a")[0].getAttribute("name") == "uselink")) {
				divs[i].style.cursor="pointer";
				divs[i].onclick=function() {
					if(css_enabled()) {
						(document.all)?this.getElementsByTagName("a")[0].click():location.href=this.getElementsByTagName("a")[0].href;
					}
				}
			}
		}
	}
}




//
// homepage slideshow feature
//
var NUMBER_SLIDES;
var ON_COLOR="lightGrey";
var OFF_COLOR="black";
var SLIDE_SPEED=10000;




function make_slideshow(numberSlides) {
	NUMBER_SLIDES = numberSlides;
	if (document.getElementsByTagName("body")[0].id=="homepage") {
		var s_controls='<span class="slideshowcontrols"><a id="a_play_pause" href="javascript:stopSlideShow()"><img id="img_play_pause" src="/_hhdocs/_includes/images/btn_pause.gif" alt="Pause" border="0" /></a>'
		for (var i = 1;i<=NUMBER_SLIDES;i++){
				var col=OFF_COLOR;
				if (i==1){
					col=ON_COLOR;
				}else{
					col=OFF_COLOR;
					}
				s_controls = s_controls + '<a style="color:'+col+'" id="a_control_'+i+'" href="javascript:showSlide(\''+i+'\')" title="'+i+'">'+i+'</a>';
				if (i!=NUMBER_SLIDES){s_controls = s_controls + ' | '}
	}
		
		s_controls = s_controls + '</span>';
		var s_head=document.getElementById("slideshowheader")
		s_head.innerHTML=s_head.innerHTML+s_controls
	}
}


function showSlide(number){
	for (var i = 1;i<=NUMBER_SLIDES;i++){
	  var a_element = document.getElementById("a_control_"+i);
	  var homemodule_element = document.getElementById("homemodule"+i);

		if (number==i){
			homemodule_element.style.display="";
			a_element.href="#";
			a_element.style.color=ON_COLOR;
		}else{
			homemodule_element.style.display="none";
			a_element.href="javascript:showSlide(\'"+i+"\')";
			a_element.style.color=OFF_COLOR;
		}
	}
}

var SLIDESHOW_RUNNING;
var SLIDE_NUMBER=2;
function runSlideshow(){
		document.getElementById("img_play_pause").src='/_hhdocs/_includes/images/btn_pause.gif';
		document.getElementById("a_play_pause").href='javascript:stopSlideShow()';
		if ((NUMBER_SLIDES+1)==SLIDE_NUMBER){
			SLIDE_NUMBER = 1;
		}
		showSlide(SLIDE_NUMBER)
		SLIDE_NUMBER++;
		SLIDESHOW_RUNNING=setTimeout('runSlideshow()', SLIDE_SPEED);
}





	
	function stopSlideShow(){
		document.getElementById("img_play_pause").src='/_hhdocs/_includes/images/btn_play.gif';
		document.getElementById("a_play_pause").href='javascript:runSlideshow()';
		clearTimeout(SLIDESHOW_RUNNING)
	}
	

