google.setOnLoadCallback(function(){
	_initSidebarPosts();
	_initSwapInput();
	_initNavbarSearch();
        _initExternalLinks();
});

function _initExternalLinks()
{
	$('a[rel*="external"]').click(function(){
		window.open(this.href);
		return false;
	});
}
function _initSidebarPosts()
{
	$(".sidebaritemtabbed .tabs a").click(function()
	{
		$(this).parent().children().removeClass('active');
		$(this).addClass('active');
		if($(this).text() == "Popular Posts")
		{
			$(".sidebaritemshadow .comments").addClass('hide');		
			$(".sidebaritemshadow .posts").removeClass('hide');
			$('.sidebaritemtabbed .tabs').css({"backgroundPosition": "-295px -105px"});
		}
		else
		{
			$(".sidebaritemshadow .comments").removeClass('hide');
			$(".sidebaritemshadow .posts").addClass('hide');		
			$('.sidebaritemtabbed .tabs').css({"backgroundPosition": "-295px -154px"});	
		}
		return false;
	});
}
function _initSwapInput()
{
    $('.swap').each(function() {
	var defaultval = this.value;
	$(this).focus(function() {
	    if(this.value == defaultval) {
		this.value = '';
	    }
	});
	$(this).blur(function() {
	    if(this.value == '') {
		this.value = defaultval;
	    }
	});
    });
}
function _initNavbarSearch()
{
    $(".search form").submit(function()
    {
        var q = $("#.search form input.searchField").val().replace(/ /g, '+');
        window.location = "/search/"+q+"?collections=quickbase_blog";
        return false;
    });
}

