var mouseover_flag = 0;
var obj;
var ii;
function initializeNews() {
	fadeNews('initialize', 0, 0);
}
function fadeNews(action, news_id, opacity) {
	if (mouseover_flag) {
		window.setTimeout("fadeNews('"+action+"', "+news_id+", "+opacity+")", time_fade);
		return;
	}
	obj = document.getElementById("newsentryfade" + news_id);
	switch(action) {
		case 'initialize':
			obj = document.getElementById('newsboxfade');
			obj.style.height = newsbox_height + 'px';
			if (num_news_entryfade == 1)
			{
				return;
			}
			for (ii = 1; ii <= num_news_entryfade; ii++) {
				obj = document.getElementById("newsentryfade" + ii);
				obj.style.display = 'none';
			}
			fadeNews('fadein', 1, 0);
			break;
		case 'fadein':
			if (opacity <= 100) {
				obj.style.display = 'block';
				setOpacity("newsentryfade" + news_id, opacity);
				opacity += 10;
				window.setTimeout("fadeNews('fadein', "+news_id+", "+opacity+")", time_fade);
			}
			else
			{
				window.setTimeout("fadeNews('fadeout', "+news_id+", "+time_fade+")", time_pause);
			}
			break;
		case 'fadeout':
			if (opacity > 0) {
				setOpacity("newsentryfade" + news_id, opacity);
				opacity -= 10;
				window.setTimeout("fadeNews('fadeout', "+news_id+", "+opacity+")", time_fade);
			}
			else
			{
				obj.style.display = 'none';
				if (news_id == num_news_entryfade)
				{
					window.setTimeout("fadeNews('fadein', 1, 0)", time_fade);
				}
				else
				{
					news_id++;
					window.setTimeout("fadeNews('fadein', "+news_id+", 0)", time_fade);
				}
			}
			break;
	}

}



////////////////////////
//                    //
//  FADING FUNCTIONS  //
//                    //
////////////////////////

//
// DESCRIPTION : Sets the opacity of an element.
// INPUTS :
//    1) obj - the name of the element
//    2) opacity - the desired opacity of the element
//
function setOpacity(obj_id, opacity) {
	//
	// Get the object.
	//
	obj = document.getElementById(obj_id);
	//
	// Set opacity to 99.999 if it is 100.
	//
	if (opacity == 100)
	{
		opacity = 99.999;	
	}
	//
	// Set the opacity for different browsers.
	//
	obj.style.filter = "alpha(opacity:"+opacity+")";  // IE/Win
	obj.style.KHTMLOpacity = opacity / 100;           // Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity / 100;             // Older Mozilla and Firefox
	obj.style.opacity = opacity / 100;                // Safari 1.2, newer Firefox and Mozilla, CSS3
}


//
// DESCRIPTION : Fade an element in.
// INPUTS :
//    1) obj - the name of the element
//    2) opacity - the desired opacity of the element
//
function fadeIn(obj_id, opacity) {
	//
	// Get the object.
	//
	obj = document.getElementById(obj);
	//
	// Set the opacity of the object.  Set a timer to iteratively
	// call this function with a reduced opacity.
	//
	if (opacity <= 100) {
		setOpacity(obj_id, opacity);
		opacity += 10;
		window.setTimeout("fadeIn('"+obj_id+"',"+opacity+")", 100);
	}
}


//
// DESCRIPTION : Fade an element out.
// INPUTS :
//    1) obj - the name of the element
//    2) opacity - the desired opacity of the element
//
function fadeOut(obj_id, opacity) {
	//
	// Get the object.
	//
	obj = document.getElementById(obj);
	//
	// Set the opacity of the object.  Set a timer to iteratively
	// call this function with a reduced opacity.
	//
	if (opacity > 0) {
		setOpacity(obj_id, opacity);
		opacity -= 10;
		window.setTimeout("fadeOut('"+obj_id+"',"+opacity+")", 100);
	}
}
