var activeTab = 'philosophy';
var activePerf = 'month';

$( document ).ready( function() {
	$( "div.fund_tabs div" ).hover( function() {
		$(this).addClass( "tabhover" );
	}, function() {
		$(this).removeClass( "tabhover" );
	});

	$( "div.fund_tabs div" ).click( function( ) {
		var id = $(this).children( "a" ).attr( "id" );
		switchTab( id );
	});

	$( "div.chart-tab" ).click( function() {
		var id = $( this ).attr( "id" );
		var parentclass = $( this ).parent().parent().attr( 'class' ); // Grab the fund class to limit the scope
		$( this ).parent().children().each( function( index ) {
			$( this ).removeClass( 'active' );
		});
		$( this ).addClass( 'active' );
		if( id == 'quarter' ) {
			$( "." + parentclass + " div.month-tab" ).hide();
			$( "." + parentclass + " div.quarter-tab" ).show();
		} else {
			$( "." + parentclass + " div.month-tab" ).show();
            $( "." + parentclass + " div.quarter-tab" ).hide();
		}
	});

	$( "div.perf-tab" ).click( function() {
        var id = $( this ).attr( "id" );
		$( this ).addClass( 'active' );
        if( id == 'invest' ) {
            $( "div.inst-tab" ).hide();
			$( "div.perf-tab#inst" ).removeClass( 'active' );
            $( "div.invest-tab" ).show();
        } else {
            $( "div.inst-tab" ).show();
			$( "div.perf-tab#invest" ).removeClass( 'active' );
            $( "div.invest-tab" ).hide();
        }
    });

    $( '#investor' ).click( function() {
       $( '#inst' ).removeClass( 'activetab' );
       $( this ).addClass( 'activetab' );
       $( 'div#investortab' ).show();
       $( 'div#insttab' ).hide();
    });
    $( '#inst' ).click( function() {
       $( '#investor' ).removeClass( 'activetab' );
       $( this ).addClass( 'activetab' );
       $( 'div#investortab' ).hide();
       $( 'div#insttab' ).show();
    });

});

function switchTab( tab ) {
	if( tab != activeTab ) {
		// This is another tab
		var oldtab = activeTab + "-tab";
		var oldparent = $( "#" + activeTab ).parent();
		oldparent.removeClass( "tabselected" );
		$( "#" + oldtab ).hide();
		var newtab = tab + "-tab";
		var newparent = $( "#" + tab ).parent();
		newparent.addClass( "tabselected" );
		$( "#" + newtab ).show();
		activeTab = tab;
	}
}

