/* --- Player de noticias --- */
var ids = new Array();
var currentPosition = 0;
var isPlaying = false;
var wasPlaying = false;
var PLAYING_TIMER = null;
var PLAYER_DELAY_TIME = 10000;

function initializeNewsPlayer(newsIds) {
	ids = newsIds.split(",");
	currentPosition = 0;
	isPlaying = (ids.length > 1);

	if (PLAYING_TIMER != null) {
		clearTimeout(PLAYING_TIMER);
	}

	showNew();
}

function showNew() {
	var newId = ids[currentPosition];
	if (document.getElementById("homeNew_" + newId) != undefined) {
		document.getElementById("homeNew_" + newId).style.display = '';
		if (isPlaying) {
			clearTimeout(PLAYING_TIMER);
			PLAYING_TIMER = setTimeout("showNextNew();", PLAYER_DELAY_TIME);
		}
	}
}

function hiddeNew() {
	var newId = ids[currentPosition];
	if (document.getElementById("homeNew_" + newId) != undefined) {
		document.getElementById("homeNew_" + newId).style.display = 'none';
	}
}

function showLastNew() {
	hiddeNew();
	currentPosition = (currentPosition - 1 + ids.length) % ids.length;
	showNew();
}

function showNextNew() {
	hiddeNew();
	currentPosition = (currentPosition + 1) % ids.length;
	showNew();
}

function pauseNewsPlayer() {
	wasPlaying = isPlaying;
	isPlaying = false;
	clearTimeout(PLAYING_TIMER);
}

function playNewsPlayer() {
	if (wasPlaying) {
		clearTimeout(PLAYING_TIMER);
		isPlaying = true;
		PLAYING_TIMER = setTimeout("showNextNew();", PLAYER_DELAY_TIME);
	}
}

function playOrPause(anchorId) {
	var anchor = document.getElementById(anchorId);
	if (isPlaying) {
		anchor.className = "continue";
		anchor.innerHTML = "Continuar";
		pauseNewsPlayer();
	} else {
		anchor.className = "pause";
		anchor.innerHTML = "Pausa";
		wasPlaying = true;
		playNewsPlayer();
	}
}
/* -------------------------- */

/* --- Efecto de galerķa de imagenes --- */
var doMoveGallery;
var useMoveGallery;

function evaluateMovingGallery(containerId, originalId, repeatedId) {
	var container = document.getElementById(containerId);
	var original = document.getElementById(originalId);
	var repeated = document.getElementById(repeatedId);

	if (container != undefined && original != undefined && repeated != undefined) {
		if (original.clientHeight > container.clientHeight) {
			repeated.style.display = '';
			doMoveGallery = true;
			useMoveGallery = true;
			moveGallery(containerId);
		} else {
			doMoveGallery = false;
			useMoveGallery = false;
		}
	}
}

function stopMovingGallery() {
	doMoveGallery = false;
}

function continueMovingGallery(container) {
	if (useMoveGallery) {
		doMoveGallery = true;
		moveGallery(container);
	}
}

function moveGallery(containerId) {
	var container = document.getElementById(containerId);
	if (doMoveGallery && container != undefined) {
		container.scrollTop = container.scrollTop + 1;

		if (container.scrollHeight == container.scrollTop + container.clientHeight) {
			container.scrollTop = 0;
		}

		setTimeout("moveGallery('" + containerId + "');", 50);
	}
}
/* -------------------------------------- */