if (typeof(Perch) == 'undefined') {
	Perch		= {};
	Perch.UI	= {};
}

Perch.UI.Global = function() {
	
	var timer;
	var bubble = false;
	
	var init	= function() {
		$('body').addClass('js');
		animate_in();
		
		if ($('.post').length){
			prettyPrint();
		}
	};

	var animate_in = function() {
		$('#tree1 .inner').css('bottom', '-487px');
		$('#tree1').append('<img src="/img/ft-bird1.gif" width="45" height="51" alt="Bird" id="treeburd1" />').find('#treeburd1').hide();
		$('#tree2 .inner').css('bottom', '-373px');
		$('#tree2').append('<img src="/img/ft-bird2.gif" width="48" height="64" alt="Bird" id="treeburd2" />').find('#treeburd2').hide();
		do_tree1();
	};
	
	var do_tree1 = function() {
		$('#tree1 .inner').css('bottom', '-487px').show().animate({
			bottom: 20
		}, {
			easing: 'swing',
			complete: do_tree2
		});
	};
	
	var do_tree2 = function() {
		$('#tree2 .inner').css('bottom', '-342px').show().animate({
			bottom: 20
		}, {
			easing: 'swing',
			complete: do_burd
		});
	};
	
	var do_burd = function() {		
		$('#treeburd1').show().animate({
			top: '30px'
		}, 'fast',function(){
			$(this).css('z-index', 11);
			
			$('#treeburd2').show().animate({
				top: '98px'
			},function(){
				$(this).css('z-index', 11);
				$(this).hover(function(){
					burd_hover(true);
				},function(){
					burd_hover(false);
				});
			});
		});	
	};
	
	var burd_hover = function(show) {
		if (show) {
			if (!bubble) {
				$('#treeburd2').before('<p id="twitterfollow"><a href="http://twitter.com/grabaperch">Follow me on Twitter!</a></p>');
				bubble = $('#twitterfollow');
				bubble.hover(function(){
					clearTimeout(timer);
				});
			}
			bubble.show();
			
		}else{
			timer = setTimeout(function(){
				bubble.fadeOut();
			}, 5000);
		}
	};

	return {
		init: init
	};

}();

jQuery(function($) {Perch.UI.Global.init();});

document.write('<style type="text/css">#tree1 .inner, #tree2 .inner {display: none;}</style>');