// JavaScript Document

var lostFocus = 1;
var boolAutoNews = true;

function autoNews()
{
	// si ya no esta en auto salirse
	if (!boolAutoNews)
		return;
	
	showNews((lostFocus % 3) + 1, false);
	boolAutoNews = true;
	
	// recall...
	setTimeout("autoNews()", 5000);
}

function showNews(onFocus)
{
	boolAutoNews = false; // stop auto scrolling!
	
	if (lostFocus == onFocus)
		return; // no hace nada!
	
	document.getElementById('imgNews' + lostFocus).src="images/layout_v2/navi_right_no" + lostFocus + ".png";
	document.getElementById('imgNews' + onFocus).src="images/layout_v2/navi_right_hi" + onFocus + ".png";
	
	lostFocus = onFocus;
	
	newsFadeOut('navi-news-swap', 10, onFocus);
}

function newsFadeIn(tag, iFade)
{
	// ya termino?
	if (iFade++ == 10) //(tag.style.opacity == 1 || tag.style.filter == "alpha(opacity = 100)")
		return; // game over!
		
	else // no esta opaco...
	{
		if (iFade > 0)
		{
			document.getElementById(tag).style.opacity = iFade * 0.1; //tag.style.opacity + 0.05;
			document.getElementById(tag).style.filter = "alpha(opacity = " + iFade * 10 + ")";
		}
		
		// recall...
		setTimeout("newsFadeIn('" + tag + "', " + iFade + ")", 33);
	}
}

function newsFadeOut(tag, iFade, toText)
{
	// ya termino?
	if (iFade-- == 0) //(tag.style.opacity == 1 || tag.style.filter == "alpha(opacity = 100)")
	{
		setNewsSwaps(tag, toText);
		newsFadeIn(tag, 0); //return; // game over!
		return;
	}
	
	//else // no esta opaco...
	document.getElementById(tag).style.opacity = iFade * 0.1; //tag.style.opacity + 0.05;
	document.getElementById(tag).style.filter = "alpha(opacity = " + iFade * 10 + ")";
	
	// recall...
	setTimeout("newsFadeOut('" + tag + "', " + iFade + ", " + toText + ")", 33);
}

function setNewsSwaps(tag, toText)
{
	switch (toText)
	{
		case 1: // order!
			SetHTML('navi-news-swap', document.getElementById('navi-news-swap-order').innerHTML);
			break;
		
		case 2: // blog!
			SetHTML('navi-news-swap', document.getElementById('navi-news-swap-blog').innerHTML);
			break;
		
		case 3: // contest!!
			SetHTML('navi-news-swap', document.getElementById('navi-news-swap-contest').innerHTML);
			break;
		
	}
}

function SetHTML(tag, text)
{
	document.getElementById(tag).innerHTML = text;
}

// ABBR support for IE
function styleAbbr()
{
	var oldBodyText, newBodyText, reg;
	
	if (isIE)
	{
		oldBodyText = document.body.innerHTML;
		reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
		newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"abbr\" $1>$2</SPAN></ABBR>');
		document.body.innerHTML = newBodyText;
	}
}