/*
jQuery functions for ixda.nl
Copyright (c) 2011 Ylab, www.ylab.nl
*/
function scanMail() {
	var i, allmail, replacemail, spt, lbl;
	allmail = document.getElementsByTagName('dfn');

	for (i=0; i<allmail.length; i++) {
		replacemail = allmail[i].innerHTML;
		spt = replacemail.split(' | ');

		lbl = spt[0].replace(' at ','@');

		replacemail = spt.length>1 ? spt[1] : lbl;

		replacemail = replacemail.replace(' at ','@');
		allmail[i].innerHTML = "<a class='link' href='mailto:"+replacemail+"'>" + lbl + "<\/a>";
	}
}

function pics_init(carousel){
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.click(function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.click(function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});

	//
	$('.jcarousel-control span').each(function(i){
		var n = i+1;
		$(this).click(function(e){
			e.preventDefault();
			carousel.scroll(n);
			return false;
		});
	});
};

function pics_itemFirstIn(carousel, obj, index, state){
	var n = index > 0 ? (index - 1) % 3 : (index % -3) + 2;
	$('.jcarousel-control span:eq(' + n + ')').addClass('active').siblings().removeClass('active');
}

function initCarousel(){
	//add manual control handles based on content
	/*
	var $control = $('.jcarousel-control');
	$('#pics p').each(function(i){
		var str = $(this).html().substring(6);
		var $span = $('<span></span>').html(str);
		$control.append($span);
	});*/

	//addidtional styling
	//$('#pics li').append('<div class="verticalline"></div>');
	//$('a.a_all', $control).css({float:'right'});

	//init carousel
	$('#pics').jcarousel({
		auto: 8, /* seconds to periodically autoscroll the content */
		scroll: 1, /* number of items to scroll by */
		wrap: 'circular',
		initCallback: pics_init,
		itemFirstInCallback: pics_itemFirstIn
	});
}

jQuery(document).ready(function($) {
	initCarousel();
	scanMail();
});

