/* Blog
######################################################################################## */

var processtab = function(tab){
    if($(tab).length > 0)
    {
		var id = $(tab).attr('href').split('-');
		t = id[1];
		if($('#tab_scroll_content_'+(t)).length == 0)
		{
		    $('#tab_scroll_'+(t)+' > *').wrapAll('<div id="tab_scroll_content_'+(t)+'" class="clearfix"></div>');
		}
		if(($('#tab_scroll_content_'+(t)).outerHeight() - 20) > $('#tab_scroll_'+(t)).outerHeight())
		{
			$('#tab_scroll_'+(t)).addClass('tab_overflow');
			$('#tab_scroll_'+(t)).jScrollPane(
				{
						topCapHeight: 5,
						scrollbarWidth: 11,
						wheelSpeed: 60
				}
			);
		}    
   	}    
}

$(function() {

    $("#blog_inner > ul").tabs( { cookie: { expires: 30, path: '/' }, show: function(e,ui){processtab(ui.tab);}});
    $('.ui-tabs-nav').bind('tabsshow', function(event, ui) {
	    processtab(ui.tab);			
    } );

    $("#blog_sidenav h2 a").click(function() {

		var blogSideOpenVal = ($.browser.msie && $.browser.version=='6.0') ? 245 : 232;
		var blogSideCloseVal = ($.browser.msie && $.browser.version=='6.0') ? 24 : 12;

        if ( $("#blog_sidenav").css('left') == "-"+blogSideOpenVal+"px")
        {
            $("#blog_sidenav").animate({"left": "-"+blogSideCloseVal+"px"}, "slow");
            $('#blog_sidenav h2 a').removeClass();
        }
        else
        {
            $("#blog_sidenav").animate({"left": "-"+blogSideOpenVal+"px"}, "slow");
            $('#blog_sidenav h2 a').addClass('active');
        }
    });

    $(".blog_archive ul").hide();
    $(".blog_archive .year",this).click(function() {
        $(".blog_archive .year + ul").hide();
        $('+ ul',this).show();
        $.cookie('archive', $(this).html(), { path: '/', expires: 10 });
        return false;
    });

    $(".blog_archive .year").each(function (i) {
        if ( $.cookie('archive') == $(this).html() )
        {
            $('+ ul',this).show();
        }
    });

    $('.clickable').fitted({
        'status' : true,
        'title'  : true
    });

    $('div#blog_sidenav').show();

});
