jQuery.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
	});
}
 
jQuery.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
}

jQuery.fn.mailme = function() {
	var at = / at /;
    var dot = / dot /g;
    this.each( function() {
        var addr = jQuery(this).text().replace(at,"@").replace(dot,".");
        var title = jQuery(this).attr('title')
        $(this)
            .after('<a href="mailto:'+addr+'" title="'+title+'">'+ addr +'</a>')
            .remove();
    });
};

$(document).ready(function()
{
	$('.slideshow').shuffle();
	
	$('.slideshow').cycle({
		fx: 'fade',
		timeout: 10000
	});
	
	$(function() {
		$(".gallery").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".previous"
		});
	});
	
	$("a.thumbnail").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	500, 
		'speedOut'		:	250, 
		'overlayShow'	:	true
	});
	
	$('span.mail').mailme();
	
});
