
	//	Tweetable
	;(function($) {
		$.fn.tweetable = function(settings) {
			var option = $.extend({}, $.fn.tweetable.defaultSettings, settings)

			return this.each(function(options) {
				var tweets = $(this)

				$(tweets).prepend('<ul class="tweetable"></ul>')

				var tweetable = $('.tweetable', tweets)

				$.getJSON("http://twitter.com/statuses/user_timeline/" + option.username + ".json?count=" + option.limit + "&callback=?", tweets, function(data) {
					if (option.loading) $(option.loading).remove()

					$.each(data, function(idx, tweet) {
						$(tweetable).append('<li class="tweet_' + idx + '"></li>')

						$('.tweet_' + idx, '.tweetable')
							.append('<span>' + tweet.text
								.replace(/#(.*?)(\s|$)/g, '<span class="hash">#$1 </span>')
								.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$&">$&</a> ')
								.replace(/@(.*?)(\s|\(|\)|$)/g, '<a href="http://twitter.com/$1">@$1 </a>$2')
							+ '</span>')

						if (option.time == true) $('.tweet_' + idx, tweetable).append('<small> ' + tweet.created_at.substr(0, 20) + '</small>')
					})
				})
			})
		}

		$.fn.tweetable.defaultSettings = {
			limit: 5,
			loading: false,
			username: '',
			time: true
		}
	})(jQuery);



	/* Functions are DONE */
	$(function() {
		$('body').addClass('js')
		$('#comment_email').jGravatar()
		$('.tweets')
			.html('<p class="loading">Loading Recent Tweets&hellip;</p>')
			.tweetable({loading: 'p.loading', username: 'YorkPies'})
	});



	;(function($) {
		$.fn.jGravatar = function() {

			field  = $(this)
			avatar = $('div.form_avatar')

			field.blur(function() {
				email_val = field.val()

				if (email_val) {
					if (field.data('email_val') == email_val) return;

					field.data('email_val', email_val);

					avatar.empty()

					//	This url should point to a script which prints/echos the email address after md5 encryption
					//	e.g. <?php echo md5($_GET['email']); ?>
					$.get('/incs/actions/md5_email.php', { email: email_val }, function(response) {
						g_url    = 'http://www.gravatar.com/avatar/'+response+'?s=48&r=g&d=http://'+document.domain+'/img/design/avatar_default.png';
						gravatar = '<img alt="" height="48" src="'+g_url+'" width="48" />';

						$(gravatar).appendTo(avatar)
					})
				} else {
					avatar.empty()
				}
			})
			.blur()

			return this;

		}
	})(jQuery);

	;(function($) {
		$.fn.getTweets = function() {
			tweets_area = $(this)
			username = tweets_area.attr('id')
			tweets_area.tweetable({ username: username, limit: 3 })

			return this;
		}
	})(jQuery);

	/* Define functions in the Des object */

	var Des = Des || {};

	Des.css_on = function() {
		//	FOR THIS TO WORK make sure the following CSS is being referenced somewhere:
		//	.css_test { display: none; height: 1px; width: 1px; }

		$('<div class="css_test"></div>').appendTo('body');
		result = $('.css_test').width() > 0;
		$('.css_test').remove();
		return result;
	}

	Des.print_mode = function() {
		//	FOR THIS TO WORK make sure the following CSS is being referenced somewhere:
		//	.print_test { display: none; height: 1px; width: 1px; }

		$('<div class="print_test"></div>').appendTo('body');
		result = $('.print_test').width() > 0;
		$('.print_test').remove();
		return result;
	}
