jQuery(document).ready(function($) {
	$('#mainNav ul').superfish();
	categoryCountBug($);
	mastheadAnim($);
});	
function mastheadAnim($,n) {
	if(n==null) n =0;
	$('#animatedArea .item:eq('+n+') .icon').hide();
	if($('#animatedArea .item:eq('+n+') li').length>0) {
		$('#animatedArea .item:eq('+n+') li').hide();
		var len =$('#animatedArea .item:eq('+n+') li').length;
		var r =(len>1) ? Math.round(Math.random() * (len-1)) : 0;
		var li ='#animatedArea .item:eq('+n+') li:eq('+r+')';
		if($(li + ' a').attr('title')) {$(li +' a').text($(li+' a').attr('title')); $(li+' a').removeAttr('title');}
		$(li).show();
	}
	$('#animatedArea .item:eq('+n+')').show();
	if($('#animatedArea .item').length==1 || ($('#animatedArea .item').length==2 && n!=0)) {
		$('#animatedArea .item:eq(' + n + ') .icon').hide();
		$('#animatedArea .item:eq('+n+') .strap').show('drop', {direction: 'left'}, 600, function() {
			$('#animatedArea .item:eq('+n+') .icon').show('scale', {}, 200);
		});
	}else{
		var nextAnim =0;
		while(nextAnim==n || nextAnim<1) nextAnim =Math.round(Math.random()*($('#animatedArea .item').length -1));
		$('#animatedArea .item:eq(' + n + ') .icon').hide();
		$('#animatedArea .item:eq('+n+') .strap').show('drop', {direction: 'left'}, 600, function() {
			$('#animatedArea .item:eq('+n+') .icon').show('scale', {}, 200);
		});
		setTimeout(function() {$('#animatedArea .item:eq('+n+') .icon').fadeOut(200, function() {$('#animatedArea .item:eq('+n+') .strap').hide('drop', {direction: 'up'}, 600, function() {$('#animatedArea .item:eq('+n+')').hide(); mastheadAnim($,nextAnim)});});}, 5000);
	}
}


function categoryCountBug($) {
	//shameful hack to display the category counts inline properly
	
	e('#sidebar ul li.widget_categories ul');
	e('#sidebar ul li.categories ul');
	function e(cats){
	var a;
	for(var i=0; i<$(cats).children('li').length; i++) {
		a =$(cats +' li:eq('+i+')').html();
		$(cats +' li:eq('+i+')').html(a.replace(/<\/a>/gi, '') + '</a>');
	}
	}
	
}