/**
 * lotsenhaus.js
 * 
 * Lotsenhaus-eigene Funktionen für den Content-Bereich
 * 
 */

function replaceMail() {
	$$('a[href^="xmail:"]').each(function(el) {
		el.innerHTML = el.innerHTML.replace(/(\[bei\])/img, "@");
		el.href = el.href.replace(/(\[bei\])/img, "@").replace(/(xmail\:)/img, "mailto:");
	});
}
document.observe("dom:loaded", replaceMail);


/*
 * updates the indexBlocks within the carousel after switching 
 * carousel to the right position
 */
function updateCarouselIndex(event) {
	if (event.memo && event.memo.carousel) {
		event.memo.carousel.element.select('.index li a.selected').invoke('removeClassName', 'selected');
		event.memo.carousel.element.select('.index li:nth-child('+(event.memo.carousel.currentIndex()+1)+') a').invoke('addClassName', 'selected');
	}
}

function createIndex(carousel, varname) {

	if (!varname || !window[varname]) {
		return;
	}

	if (carousel.elements.length) {
		var obj_liTemplate = new Template('<li><a href="#" class="#{classname}" onclick="window[\'#{varname}\'].scrollTo(#{index}); return false;">#{showIndex}<\/a><\/li>');
		var obj_wrapTemplate = new Template('<ul>#{list}<\/ul>');
		var listStr = '';

		for (var i = 0; i < carousel.elements.length; i++) {
			listStr += obj_liTemplate.evaluate({
				classname: (i == carousel.currentIndex()) ? 'selected' : '',
				varname: varname,
				index: i,
				showIndex: i+1
			});
		}

		var listStr = obj_wrapTemplate.evaluate({list: listStr});
		carousel.element.select('.index').each(function(el) {
			el.innerHTML = listStr;
		});
	}
}

