
$(document).ready(function(){
	prettyPrint();
	bgAnimate();
	balloonAnimate();
	$("a.submit").click(function(){
		$(this).parents("form").submit();
	});
	$("div#balloon").click(function(){
		$(this).stop();
		$(this).animate({top:'-=500px'}, 4000, 'swing')
	});
	$("div.search input.textbox")
		.focus(function(){
			$(this).css('color', '#434343');
			if($(this).val() == 'Search this site'){
				$(this).val('');
			}
		})
		.blur(function(){
			$(this).css('color', '#b0b0b0');
			if($(this).val() == ''){
				$(this).val('Search this site');
			}
		});
	$("div.content pre")
		.addClass('prettyprint')
		.wrap('<code>');
	$("pre.prettyprint:not([class='nolines'])").each(function(){
		var elemheight = $(this).css('height');
		var lines = $(this).height()/parseInt($(this).css('line-height'));
		$(this).parent().css({height: elemheight, position: 'relative'});
		var i = parseInt($(this).attr('title'));
		var build = '';
		if(isNaN(i)){ i = 1; } else if(i <= 1){ i = 1; } else { lines+=i;lines--; }
		while(i <= lines){
			build += '<li>'+i+'</li>';
			i++;
		}
		$(this).before('<ul>'+build+'</ul>');
		$(this).css({position: 'absolute', top: '0', left: '0', paddingLeft: '47px'});
		
	});
	$("div.content code ul").disableTextSelect().css('cursor', 'default');
});

function bgAnimate(){
	$("div.cloud")
		.css({backgroundPosition:'0 0'})
		.animate({backgroundPosition:'-1310px 0'}, 90000, 'linear', function(){bgAnimate();});
}
function balloonAnimate(direct){
	if(direct == true)
	{
		$("div#balloon")
			.animate({top:'-='+(rand(10)+15)+'px', left:'-='+rand(15)+'px'}, 3000+rand(2000), 'swing', function(){balloonAnimate(false);});
	}
	else
	{
		$("div#balloon")
			.animate({top:'+='+(rand(10)+15)+'px', left:'+='+rand(8)+'px'}, 3000+rand(2000), 'swing', function(){balloonAnimate(true);});
	}
}
function rand(n){
	return Math.ceil(Math.random()*n);
}

(function($) {
    if ($.browser.mozilla) {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).css({
                    'MozUserSelect' : 'none'
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).css({
                    'MozUserSelect' : ''
                });
            });
        };
    } else if ($.browser.msie) {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).bind('selectstart.disableTextSelect', function() {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).unbind('selectstart.disableTextSelect');
            });
        };
    } else {
        $.fn.disableTextSelect = function() {
            return this.each(function() {
                $(this).bind('mousedown.disableTextSelect', function() {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function() {
            return this.each(function() {
                $(this).unbind('mousedown.disableTextSelect');
            });
        };
    }
})(jQuery);