/**
 * control display of quotes
 */
var current = 1;
var rotate_delay = 15; // in seconds
function rotate_quotes (id)
{
	index = current % quotes.length;
	index = index == 0 ? 1 : index;

	if (document.getElementById(id))
	{
		$('#' + id).fadeOut(2000, function ()
		{
			document.getElementById(id).innerHTML = '"' + quotes[index][0] + '"' + '<br/><span class="name">- ' + quotes[index][1] + ' -</span>';
		});
		$('#' + id).fadeIn(2000);
		current++;

		setTimeout("rotate_quotes('" + id + "')", rotate_delay * 1000);
	}
}


/**
 * control display of home navigation buttons
 */
function nav_hover (cell, section, action, tab_name, highlighted_tab, is_first, is_last)
{
	if (tab_name != highlighted_tab)
	{
		cell.className = action;

		if (document.getElementById(section + '-nav-left-' + tab_name))
		{
			document.getElementById(section + '-nav-left-' + tab_name).className = action + ' separator';
		}
		if (document.getElementById(section + '-nav-right-' + tab_name))
		{
			document.getElementById(section + '-nav-right-' + tab_name).className = action + ' separator';
		}

		if (is_first && document.getElementById(section + '-nav-first-' + tab_name))
		{
			document.getElementById(section + '-nav-first-' + tab_name).className = 'first-' + action;
		}
		if (is_last && document.getElementById(section + '-nav-last-' + tab_name))
		{
			document.getElementById(section + '-nav-last-' + tab_name).className = 'last-' + action;
		}
	}
}


/**
 * hide or show the given element id
 */
function show_or_hide (id)
{
	if (document.getElementById(id))
	{
		if (document.getElementById(id).style.display == 'none')
		{
			document.getElementById(id).style.display = '';
		}
		else
		{
			document.getElementById(id).style.display = 'none';
		}
	}

	return false;
}


/**
 * control display of news item
 */
function update_news (news_id)
{
	// highlight the new story
	if (document.getElementById('news-story-' + news_id))
	{
		document.getElementById('news-story-' + news_id).style.display = '';
	}
	// highlight the new headline
	if (document.getElementById('news-headline-top-' + news_id))
	{
		document.getElementById('news-headline-top-' + news_id).className = 'top-on';
	}
	if (document.getElementById('news-headline-middle-' + news_id))
	{
		document.getElementById('news-headline-middle-' + news_id).className = 'middle-on';
	}
	if (document.getElementById('news-headline-bottom-' + news_id))
	{
		document.getElementById('news-headline-bottom-' + news_id).className = 'bottom-on';
	}
	if (document.getElementById('news-headline-' + news_id))
	{
		document.getElementById('news-headline-' + news_id).className = 'arrow-on';
	}

	if (highlighted_news_id != news_id)
	{
		// unhighlight the old story
		if (document.getElementById('news-story-' + highlighted_news_id))
		{
			document.getElementById('news-story-' + highlighted_news_id).style.display = 'none';
		}
		// unhighlight the old headline
		if (document.getElementById('news-headline-top-' + highlighted_news_id))
		{
			document.getElementById('news-headline-top-' + highlighted_news_id).className = 'top-off';
		}
		if (document.getElementById('news-headline-middle-' + highlighted_news_id))
		{
			document.getElementById('news-headline-middle-' + highlighted_news_id).className = 'middle-off';
		}
		if (document.getElementById('news-headline-bottom-' + highlighted_news_id))
		{
			document.getElementById('news-headline-bottom-' + highlighted_news_id).className = 'bottom-off';
		}
		if (document.getElementById('news-headline-' + highlighted_news_id))
		{
			document.getElementById('news-headline-' + highlighted_news_id).className = 'arrow-off';
		}
	}

	highlighted_news_id = news_id;

	$('#news-stories').jScrollPane({scrollbarWidth:15});

	return false;
}


/**
 * control display of the localization box
 */
var show_localization_box = false;
function choose_language ()
{
	if (document.getElementById('languages') && document.getElementById('localization'))
	{
		// current status off
		if (show_localization_box)
		{
			document.getElementById('languages').style.backgroundImage = 'none';
			document.getElementById('localization').style.display = 'none';
		}
		// current status on
		else
		{
			document.getElementById('languages').style.backgroundImage = "url('/resources/images/layout/language-bg.png')";
			document.getElementById('languages').style.display = '';
			document.getElementById('localization').style.display = 'block';
		}
		show_localization_box = show_localization_box ? false : true;
	}
}

