var currentFoto = 1;
var currentTeam = 1;
var Site = {

	beforeStart : function () {
		if ($("carrusel")  && $("carrusel").hasClass("random")) {
			Site.startCarrusel();
		}
		
		if ($$("div.persona_equipo").length > 0) {
			Site.prepareTeamTranstion();
		}
		
	},
	
	startCarrusel : function() {
		$$("#carrusel img").each(function(element) { if (element.id != 'foto_1') element.setStyle('opacity', 0); });
		
	},
	
	changeFoto : function() {
		var fx_out_foto = $('foto_' + currentFoto).effects({duration: 2500, transition: Fx.Transitions.Quint.easeOut});
		currentFoto++;
		if (!$('foto_' + currentFoto)) { currentFoto = 1; }
		var fx_in_foto = $('foto_' + currentFoto).effects({duration: 2500, transition: Fx.Transitions.Quint.easeOut});
		fx_out_foto.start({'opacity' : 0});
		fx_in_foto.start({'opacity' : 1});
	},
	
	prepareTeamTranstion : function() {
		$$("#columna_2 div.persona_equipo").each(function(element) { if (element.id != 'persona_1') element.setStyle('display', 'none'); });
		$$("#columna_3 div.foto_equipo").each(function(element) { if (element.id != 'foto_equipo_1') element.setStyle('display', 'none'); });
	},
	changeTeamMember : function(_which) {
		$("persona_" + currentTeam).setStyle("display", "none");
		$("foto_equipo_" + currentTeam).setStyle("display", "none");
		$("mnu_" + currentTeam).removeClass("activo");
		$("persona_" + _which).setStyle("display", "block");
		$("foto_equipo_" + _which).setStyle("display", "block");
		$("mnu_" + _which).addClass("activo");
		currentTeam = _which;
	},
	
	start : function() {
		Site.prepareExternalLinks();
		if ($("carrusel")  && $("carrusel").hasClass("random")) { setInterval("Site.changeFoto()", 5000); }
	},		
	
	prepareExternalLinks : function() {
		var linkList = $$("a");
		linkList.each(function(el) {
			if (el.getProperty('rel')=="external") el.target = "_blank";
		}, this);
	},
	
	getBaseUrl : function() {
		return (document.location.href).substring(0, (document.location.href).lastIndexOf("/") +1);
	}
	
	
};


Window.addEvent('domready', function() { Site.beforeStart(); });
Window.addEvent('load', function() { Site.start(); });

