function show_loader() {
	$('#loader').css( { 'height' : $('.the_posts').css('height') } );
	$('#loader').show();
}
function hide_loader() {
	$('#loader').fadeOut('slow');
}
function fix_heights() {
	var j = 1;
	var post1, post2, height1, height2, height3;
	$('.post .captions').each(function() {
		switch(j) {
			case 1: 
				height1 = $(this).css('height');
				height1 = height1.substring(0, height1.length-2); 
				post1 = $(this);
				j++; 
			break;
			case 2: 
				height2 = $(this).css('height'); 
				height2 = height2.substring(0, height2.length-2); 
				post2 = $(this); 
				j++; 
			break;
			case 3: 
				height3 = $(this).css('height');
				height3 = height3.substring(0, height3.length-2); 
				j = 1;
				// Find tallest entry
				var heightarray = new Array();
				heightarray[0] = parseInt(height1);
				heightarray[1] = parseInt(height2);
				heightarray[2] = parseInt(height3);
				var highNum = 0;
				for (var i=0; i < heightarray.length; i++) {
					if (heightarray[i] > highNum) { highNum = heightarray[i]; }
					else { highNum = highNum; }
				};
				
				// Set all entries same height
				$(post1).css({ 'height' : highNum + 'px' });
				$(post2).css({ 'height' : highNum + 'px' });
				$(this).css({ 'height' : highNum + 'px' });
			break;
		}
	});
}
function check_url() {
	$.ajax({
		url: 'http://www.flickrdesign.com/wp-content/themes/default/ajax-check-url.php',
		method: 'post',
		data: 'url=' + $('#sub_url').val(),
		success: function(message) {
			if (message == '') {
				return true;
			} else {
				if (message != '') {
					$('#submit-url .url-error').html(message).show();
				}
				return false;
			}
		}
	})
}
function validate_submit() {
	// check_url();
	var message = '';
	var valid = 'true';
	if ($('#sub_email').val() == '') {
		valid = 'false';
		message = 'Please enter a valid email address.<br/>';
	} if ($('#sub_url').val() == '') {
		valid = 'false';
		message += 'Please enter a valid image URL.';
	}
	if (valid == 'true') {
		return true;
	} else {
		$('#submit-url .error').html(message).show();
		return false;
	}
}
function validate_contact() {
	if ($('#comments').val() == '') {
		$('#submit-url .error').html('Please enter your comments.').show();
		return false;
	} else {
		return true;
	}
}
function like(id) {
	$.ajax({
		url: 'http://www.flickrdesign.com/wp-content/themes/default/ajax-like.php?id=' + id,
		success: function(responseText) {
			$('#num-likes-'+id).html(responseText);
		}
	});
}
function outbound_links(id) {
	$.ajax({ 
		url: 'http://www.flickrdesign.com/wp-content/themes/default/ajax-outbound.php?id='+id,
		success: function() { return true; } 
	});
}

$(document).ready(function() {
	if ($('.post')) {
		var i = 1;
		$('.post').each(function() {
			if (i == 3) { $(this).addClass('no-right-margin'); i = 1; }
			else { i++; }
		});
	}
	$('#subscribe').hover(
		function() { $(this).animate( { left : '-5px' }, "fast" ); },
		function() { $(this).animate( { left : '-13px' }, "fast" ); }
	);
	$('#headernav li a').hover(
		function() { $(this).animate( { opacity: 1.0, paddingTop: '35px' }, "fast" ); },
		function() { $(this).animate( { opacity: 1.0, paddingTop: '30px' }, "fast" ); }
	);
	$('#headerimg img').hover(
		function() { $(this).animate( { opacity: 0.8, marginTop: '5px' }, "fast" ); },
		function() { $(this).animate( { opacity: 1.0, marginTop: '0px' }, "fast" ); }
	);
	if ($('.navigation .alignleft a')) {
		$('.navigation .alignleft a').hover(
			function() { $('.navigation .alignleft a img').animate( { right: '21px' }, "fast" ); },
			function() { $('.navigation .alignleft a img').animate( { right: '15px' }, "fast" ); }
		);
	}
	if ($('.navigation .alignright a')) {
		$('.navigation .alignright a').hover(
			function() { $('.navigation .alignright a img').animate( { left: '21px' }, "fast" ); },
			function() { $('.navigation .alignright a img').animate( { left: '15px' }, "fast" ); }
		);
	}
	if ($('#close')) {
		$('#close').hover(
			function() { $(this).css( { 'background-position' : '100% 100%' } ); },
			function() { $(this).css( { 'background-position' : '100% 0%' } ); }
		);
		$('#close').click(function() {
			$('#welcome_message').fadeOut("fast", function() { $(this).remove(); } );
		});
	}
	// Add arrow icon after links
		$('a.arrow').each(function() {
			$(this).after('&nbsp;&nbsp;<img src="http://www.flickrdesign.com/wp-content/themes/default/images/right-arrow.gif" alt="more ->" style="margin-top: -2px" />');
		});
	if ($('#loader')) { show_loader(); }
	if ($('.submit-button')) {
		$('.submit-button').hover(
			function() { $(this).animate( { opacity: 0.8 }, "normal" ); },
			function() { $(this).animate( { opacity: 1.0 }, "normal" ); }
		);
	};
});