﻿/// <reference path="jquery-1.4.2.js" />
/// <reference path="jquery.jtwitter.js" />

String.prototype.startsWith = function (str) {
	return (this.match("^" + str) == str);
};

String.prototype.endsWith = function (str) {
	return (this.match(str + "$") == str);
};

String.prototype.contains = function(str) {
	return (this.indexOf(str) > -1);
};

$(function () {

	// auto-blur links & buttons
	$('a, button').click(function () {
		$(this).blur();
	});

	// navigation
	(function () {
		var currentNav =
			document.location.pathname === '/'
				? 'home'
				: document.location.pathname.split('/')[1];

		$('nav a').removeClass('current');
		$('nav a:contains(' + currentNav + ')').addClass('current');
	} ());

	// ideas
	if ($('#ideas').length == 1) {
		$.jTwitter('jonathanconway', 200, function (data) {
			$.each(data, function (i, post) {
				if (post.text.contains('#idea'))
					$('#twitter-ideas')
						.append(
							$('<p>' +
									post.text
										.replace(
											'#idea',
											'<span class="idea-hash">' +
											'	#idea' +
											'</span>') +
								'</p>'))
						.addClass('loaded');
			});
		});
	}

});
