function ini() {
	linksExternos();
	cambiarMails();
	oyentesThumbs();
	oyentesGalerias();
}
function linksExternos() {
	$$('.external').addEvent('click', function(e) {
		e.stop();
		open(this.href);
	});
}
function cambiarMails() {
	$$('.mail').each(function(elem) {
		elem.href = elem.href.replace('(ARROBA)', '@');
		var nodo = elem.firstChild;
		nodo.nodeValue = nodo.nodeValue.replace('(ARROBA)', '@');
	});
}
function cargarImg(gal, img) {
	var d = 'g='+gal;
	if(img != null) {
		d += '&f='+img;	
	}
	new Request.HTML({
		url: 'includes/imagen.php',
		method: 'get',
		data: d,
		update: $('image'),
		evalScripts: true
	}).send();
}
function cargarGal(gal) {	
	new Request.HTML({
		url: 'includes/galeria.php',
		method: 'get',
		data: 'g='+gal,
		update: $('gallery'),
		evalScripts: true,
		onComplete: function(a, b, c, d) {
			cargarImg(gal);
		}
	}).send();
}
function eventoGal(e) {
	e.stop();
	if(this != galActual) {
		cargarGal(this.rel);
		if (galActual != null) { galActual.removeClass('selected'); }
		this.addClass('selected');
		galActual = this;
		//navCambiarGaleria(this.firstChild.nodeValue);
	}
}
function eventoImg(e) {
	e.stop();
	cargarImg(galActual.rel, this.rel);
}
function oyentesGalerias() {
	$$('.mGallery').addEvent('click', eventoGal);	
}
function oyentesThumbs() {
	$$('.thumb').addEvents({'mouseenter': thumbOver, 'mouseleave': thumbOut, 'click': eventoImg});
}
function navCambiarGaleria(texto) {
	$('galleryName').set('html', ' / '+texto);
}
function navCambiarImagen(texto) {
	$('caption').set('html', ' / '+texto);
}
function thumbOver(){
	this.getElements('img')[0].fade(0.5);	
}
function thumbOut(){
	this.getElements('img')[0].fade(1);	
}
function codificarURLS() {
	$$('.thumb').each(function(elem){
		elem.href = encodeURIComponent(elem.href);
	});
}