// =========================
// = Movable Type features =
// =========================

mtAttachEvent('load', mtUpdateScores);
mtAttachEvent('usersignin', mtUpdateScores);

// =====================
// = Custom Javascript =
// =====================

// A little container boxing, centering
if ($(window).width() < 1012) $('body').addClass('notwide');
// Extra Decoration
$('#sidebar .box').addClass('outer').wrapInner('<div class="inner"/>');

// Remove margin for last elem in the padded box
$('#sidebar .box p:last-child').addClass('bottom');

// "Hot this (timeframe)": tabbed menu switcher
var minheight,
	switchboxes = $('.switcher').hide(),
	menuitems   = $('.tabmenu a');

menuitems.click(function(){
	var _this = $(this);
	menuitems.parent().removeClass('active');
	_this.parent().addClass('active');
	switchboxes.hide();
	$(_this.attr('href')).show();
	return false;
});

menuitems.filter(":first").click();

Cufon.replace('.cufon');
Cufon.replace('.museo', { } );


// Ajax Comments
var $commentform = $('#comments-form'),
		$ajaxmessage = $('#ajax-comment').html('<img src="/_images/ajax-loader.gif" border="0" class="loading"/>');

		$ajaxmessage.find('img.loading').hide();
		$commentform.parent().wrap('<div style="min-height:200px"/>');

successful = false;
if ($commentform.length > 0) {
	  $commentform.ajaxForm({
		target: $ajaxmessage,
		beforeSubmit: function(data, $form, opt){
			$ajaxmessage.html('<img src="/_images/ajax-loader.gif" border="0" class="loading"/>');
			$ajaxmessage.find('img.loading').show();
			$commentform.parent().fadeOut(500);
		},
		success: function(){
			if (successful != true ){
				$commentform.parent().fadeIn(400);
			}
		}
	});

}; //end of if

$previewfield = $commentform.find('input[name=preview]');
if (! $previewfield.length > 0) {
	var fieldhtml = '<input name="preview" value="" type="hidden"/>';
	$previewfield = $commentform.prepend(fieldhtml).find('input[name=preview]');
}

$('#comment-preview').hover(function(){
	$previewfield.attr('value', '1');
}, function(){
	$previewfield.attr('value', '0');
});

// Add box-click style for .over elements
var hoverboxes = $('.bloggerprofile, .hpentry, .mojoeentry');

hoverboxes.hover( function(){
	var $this = $(this);	
	$this.addClass('over');
	
}, function(){
	$(this).removeClass('over');
}).click(function(){
	var $this = $(this);	
	var link = $this.find("a:first");
	
	location.href = link.attr('href');
	
});


// Homepage Twitter aggregator

// This method relies on SimplePie to create a blank include file called twitter.php
var $twitterHolder = $("#hptwitter"),
	loadingHtml    = '<div class="twitterBody"><p>Loading Latest Tweets...</p></div>',
	$twitterBody   = $twitterHolder.append(loadingHtml).find('div:last');

$twitterBody.neotweet('/_library2/twitter.php');


$('.twitterentry').live('mouseover', function(){
	$(this).addClass('over');
}).live('mouseout', function(){
	$(this).removeClass('over');
}).live('click', function(){
	var $this = $(this);	
	var link = $this.find("a:last");
	location.href = link.attr('href');
});
