/*
	http://cbsides.com/cb.blog.js
*/
if (!cb) { 
    var cb = {};
}
if (!cb.blog) {
    cb.blog = {
		toTopOffset: 0,
		commentText: null,
		testToTop: function() {
			$('#to-top').toggleClass('persist', ($(window).scrollTop() >= (cb.blog.toTopOffset - 16)));
		},
		init: function() {
			//	Dynamic right positioning of form / to-top link:
			cb.blog.toTopOffset = $('#to-top').offset().top;
			cb.blog.testToTop();
			$(window).scroll(cb.blog.testToTop);
			$('#comment-form :input').focus(function() {
				$('#comment-form').addClass('active');
			});
			$('#comment-form :input').blur(function() {
				$('#comment-form').removeClass('active');
			});
			//	Clear comment help text on focus
			cb.blog.commentText = $('#comment-text');
			if (cb.blog.commentText) {
				cb.blog.commentText.focus(function() {
					if (!this.getAttribute('pretext') && this.value.indexOf('Enter your comment...') === 0) {
						this.setAttribute('pretext', this.value);
						this.value = '';
					}
				});
				cb.blog.commentText.blur(function() {
					if (this.getAttribute('pretext') && this.value === '') {
						this.value = this.getAttribute('pretext');
						this.setAttribute('pretext', '');
					}
				});
			}
			//	Focus form on error
			if ($('#comment-form > p.error').length > 0) {
				window.location.hash = '#new-comment';
				document.getElementById('comment-name').focus();
			}
			//	Focus form on "new comment" link
			$('#newComment').unbind('click').click(function() {
				document.getElementById('comment-name').focus();
				return false;
			});
			//	Wire up dynamic labels
			if (cb.label) {
				cb.label('.meta dd');
				cb.label('#paging-post-prev a,#paging-post-next a');
			}
		}
	};
};
$(document).ready(cb.blog.init);