/* confuse the damn spambots */

function email_address() {
	var str = "moc." + "sdeesorcim@" + "8ofni";
	var email = "";
	for (i=str.length; i>=0; --i) {
		email = email + str.substr(i, 1);
	}
	return "<a href=\"mailto:" + email + "\">" + email + "</a>";
}


/* blog ImageGallery, displays the numbered photo */

var galleryPhotoCount = $H({});				// keep track of the images in each gallery

function startGalleryN(n) {					// usage: startGalleryN(1);
	startGallery("gallery" + n);
}

function startGallery(id) {					// usage: startGallery('gallery1')
	var images = $$('#' + id + " img");
	galleryPhotoCount[id] = images.length;	// set galleryPhotoCount to the number of images found
	var i = 0;								// set the id for each img
	var links = "<div id='" + id + "_caption' class='caption'></div>";
	links = links + "<ul class=\"links\">";		// build list of links
	images.each(function(img) {
		img.id = id + "_photo" + (++i);
		var title = img.title;				// extract image title
		links = links + '<li id="' + id + '_link' + i + '">'
			+ '<a href="#" title="' + title + '" onclick="showGalleryPhoto(this); return false;">' + i + '</a>'
			+ '</li>';
	});
	links = links + "</ul><div style='clear: both'></div>";
	
	new Insertion.Bottom(id, links);
	showGalleryPhoto(id);
}

function showGalleryPhoto(el) {			// usage: showGalleryPhoto('gallery1') or showGalleryPhoto(this)
	el = $(el);
	var n = 1;										// image# we'll show
	var id = el.id;
	if (el.tagName == 'A') {						// get gallery ID & extract image#
		id = el.parentNode.parentNode.parentNode.id;
		var this_id = el.parentNode.id;
		n = parseInt(this_id.substr(id.length+5));
	}
	for (var i=1; i<=galleryPhotoCount[id]; i++) {	// hide all images
		$(id + '_photo' + i).hide();
		$(id + '_link' + i).removeClassName('hilite');
	}
	$(id + '_photo' + n).show();					// show image# n
	$(id + '_link' + n).addClassName('hilite');
	var title = $(id + '_photo' + n).title;
	$(id + '_caption').innerHTML = title;
}
