$(function(){

    var self = this;
        self.lastSelected = $('#tabMenu li:first-child');
        self.lastWrapper  = $('#' + self.lastSelected.find('a').attr('class'));
        self.modFunctions = {};
	
    self.handleClick = function(){
    	
        $('#tabMenu li').removeClass('current')
        self.lastSelected = $('#tabMenu .'+this.className).parent().addClass('current');

        self.lastWrapper.addClass('hidden');
        self.lastWrapper = $( '#' + this.className ).removeClass('hidden');

        if ( typeof window[ this.className ] == 'function' ) {
            if ( !( this.className in self.modFunctions ) ) {
                self.modFunctions[ this.className ] = window[ this.className ].call( self.lastWrapper );
            }
        }
    };

    $('#tabMenu li a').click( self.handleClick );
	$('#quickExplore li a').click( self.handleClick );
    var hash = window.location.hash;
        hash = hash.substr(1, hash.length - 2);

    if ( hash.length > 0 ) {
        var control = $('#tabMenu li a.' + hash);
        if ( control.length == 1 ) {
            self.handleClick.call( control[0] );
        }
    }
});
