$(function(){
// replace spam emails
	var spt = $('span.mailme');
	var at = / at /;
	var dot = / dot /g;
	var addr = $(spt).text().replace(at,"@").replace(dot,".");
	$(spt).after('<a href="mailto:'+addr+'" title="Send an email">'+ addr +'</a>')
	.hover(function(){window.status="Send a letter!";}, function(){window.status="";});
	$(spt).remove();
	
// Dropdown
	function showNav(){
		jQuery(this).children('.dropdown').fadeIn();
	}
	function hideNav(){
		jQuery(this).children('.dropdown').fadeOut();
	}
	var navConfig = {
		over: showNav,
		timeout: 500,
		out: hideNav
	};
	jQuery('.nav li').hoverIntent(navConfig);

// homepage slide
	$('#cycle').cycle({delay: -2500,speed:  1000});

// post like button
	$('.likeButton').live('click', function () {
	    liked = $(this).hasClass('liked');
        command = liked ? 'unlike' : 'like';
        oauth = $(this).parent().parent().attr('title').slice(-8);
        id = $(this).parent().parent().attr('id');
        commandUrl = 'http://www.tumblr.com/' + command + '/' + oauth + '?id=' + id;
	
	    $('#like-it').attr('src', commandUrl);
	    $(this).toggleClass('liked');
	
	    return false;
	});
	
	$('.reblogButton').each(function () {
        oauth = $(this).parent().parent().attr('title').slice(-8);
        id = $(this).parent().parent().attr('id');
        $(this).attr('href', 'http://www.tumblr.com/reblog/' + id + '/' + oauth + '?redirect_to=%2Fdashboard');

	});
	
// fancybox
	$('.highRes').each(function(){
		oldHighRes = $(this).attr('href');
		oldHighResSlash = oldHighRes.replace(/^.+\/([^\/]*)$/,'$1');
		newHighRes = 'http://s3.amazonaws.com/data.tumblr.com/' + oldHighResSlash + 'o1_1280.jpg';
		$(this).attr('href', newHighRes);
	}).fancybox({
		fitToView	: true,
		closeClick	: true,
		openEffect	: 'fade',
		closeEffect	: 'fade'
	});
	
	$('.photoset a').fancybox({
		fitToView	: false,
		width		: '90%',
		height		: '90%',
		autoSize	: false,
		closeClick	: true,
		openEffect	: 'fade',
		closeEffect	: 'fade',
		loop		: true
	});
});
