$(document).ready(function(){
	// image fade in
	$("img").each(function(index, el){
	    var img_src = el.src;
	    $(el).load(function () {
		      $(this).animate({ opacity: 1 }, 'normal')
	    }).attr('src', img_src).css('opacity', 0);
	});
  
	// navigation 
	//$("#navigation a").blend();
		
	// body snippet
	$('.snippet').prepend('<div class="top"></div>').append('<div class="btm"></div>');
	
	// sidebar snippet
	$('#sidebar .snippet ul.tabs li:last').css({'border-bottom':'none','margin':'0'});
			
	// defuscate email address
	$('.contact-email').defuscate();

	// equal column
	$('#body, #sidebar').setAllToMaxHeight();	
});

// converts obfuscated email addresses into normal, working email addresses
jQuery.fn.defuscate = function( settings ) {
    settings = jQuery.extend({
        link: true,
        find: /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi,
        replace: '$1@$2'
    }, settings);
    return this.each(function() {
        if ( $(this).is('a[@href]') ) {
            $(this).attr('href', $(this).attr('href').replace(settings.find, settings.replace));
            var is_link = true;
        }
        $(this).html($(this).html().replace(settings.find, (settings.link && !is_link ? '<a href="mailto:' + settings.replace + '">' + settings.replace + '</a>' : settings.replace)));
    });
};

// Make columns of equal height
jQuery.fn.setAllToMaxHeight = function(){
	return this.height( Math.max.apply(this, $.map(this, function(e){ 
		return $(e).height() 
	})))
}
