
$(document).ready(function() {
	$("#rotacita div:first").fadeIn("slow");

	rotate = function() {
		var container = $("#rotacita");
		var totale = container.find("div").size();
		var current = 0;
		play = setInterval(function() {
			if (current >= totale) current = 0;
			$("#rotacita div").filter(":eq("+current+")").fadeIn("slow").end().not(":eq("+current+")").fadeOut("slow");
			current++;
		}, 10000);
	};
	rotate();
});

function popup(url, width, height, name){
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
 
	if (!name) {
		name = '_popup';
	}

	var win = window.open(url.replace(/&amp;/g, '&'), name, 'top=' + top + ',left=' + left + 'height=' + height + ',resizable=yes,scrollbars=yes,width=' + width);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return false;
}

//Blog,galeria,noticias,calendario
/*
	*Cambia la visibilidad de 'elemento' de none a inline
	*Si 'elemento2' != 'no' cambia su visibilidad de inline a none
	*usuarios = variable o array de los usuarios a los que se aplicará el cambio de visibilidad
	*userId = id del usuario que está viendo la página
	*administrador = si es 'yes' se aplica el cambio de visibilidad
*/
function visibilidad(elemento, elemento2, usuarios, userId, administrador) {
	function cambio(el1, el2){
		document.getElementById(elemento).style.display='inline';
		if (elemento2 != 'no') {
			document.getElementById(elemento2).style.display='none';
		}
	}
	var anonymous = 1;
	if (userId != anonymous) {
		if(administrador == 'yes') {
			cambio(elemento, elemento2);
		}
		else {
			if(usuarios instanceof Array) {
				for (i=0;i<usuarios.length;i++){
					if (usuarios[i] == userId) {
						cambio(elemento, elemento2);
					}
				}
			}
			else if (usuarios == userId) {
				cambio(elemento, elemento2);
			}
		}
	}
}
//calendario, blog
function noAnonymous(elemento, userId) {
	var anonymous = 1;
	if (userId == anonymous) {
		document.getElementById(elemento).style.display='none';
	}
}

function mostrar(panel, boton) {
	var pan = document.getElementById(panel);
	if(pan.style.height == '100px') {
		$("div#"+panel).animate({ height: "0px" }, "fast");
		$("div."+boton).toggle();
	}
	else {
		$("div#"+panel).animate({ height:"100px" }, "fast");
		$("div."+boton).toggle();
	}
}

function displayTab(tab_id, panel_id) {
	var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i;

	panelElm= document.getElementById(panel_id);
	panelContainerElm = panelElm ? panelElm.parentNode : null;
	tabElm = document.getElementById(tab_id);
	tabContainerElm = tabElm ? tabElm.parentNode : null;

	if (tabElm && tabContainerElm) {
		nodes = tabContainerElm.childNodes;

		// Hide all other tabs
		for (i = 0; i < nodes.length; i++) {
			if (nodes[i].nodeName == "LI")
				nodes[i].className = '';
		}

		// Show selected tab
		tabElm.className = 'current';
	}

	if (panelElm && panelContainerElm) {
		nodes = panelContainerElm.childNodes;

		// Hide all other panels
		for (i = 0; i < nodes.length; i++) {
			if (nodes[i].nodeName == "DIV")
				nodes[i].className = 'panel';
		}

		// Show selected panel
		panelElm.className = 'current';
	}
}
