var WheelNav = {
    zoom_states: {},
    default_depths: {},
    zoom_in_timer: null,
    current_segment_id: null,
    init: function() {
        $('#wheel-nav-container a.wheel-segment').each(function() {
            WheelNav.set_state(this.id,'zoomed_out');
            WheelNav.default_depths[this.id] = $(this).css('z-index');
        });
        $('#wheel-nav-container a.wheel-segment').mouseover(function() {
            clearTimeout(WheelNav.zoom_in_timer);
            WheelNav.current_segment_id = this.id;
            WheelNav.zoom_in_timer = setTimeout('WheelNav.zoom_in();',800);
        });
        $('#wheel-nav-container a.wheel-segment').mouseout(function() {
            clearTimeout(WheelNav.zoom_in_timer);
        });
    },
    zoom_in: function() {
        clearTimeout(WheelNav.zoom_in_timer);
        var curr_state = WheelNav.get_state(this.current_segment_id);
        if (curr_state == 'zoomed_out') {
            $('#'+this.current_segment_id).css({'z-index': '20'});
            WheelNav.set_state(this.current_segment_id,'zooming');
            $('#wheel-nav-container a').each(function() {
               if (this.id != WheelNav.current_segment_id) {
                   $(this).hide();
               } 
            });
            $('#vision-background').fadeOut('fast');
            $('#'+this.current_segment_id).animate({
                width: '392px',
                height: '392px'
            },'normal');
            $('#'+this.current_segment_id).children('img').fadeIn('normal', function() {
                WheelNav.set_state(WheelNav.current_segment_id,'zoomed_in');
                $('#'+WheelNav.current_segment_id).mouseout(function() {
                    WheelNav.zoom_out();
                });
            });
        }
    },
    zoom_out: function() {
        var curr_state = this.get_state(this.current_segment_id);
        if (curr_state == 'zoomed_in') {
            this.set_state(this.current_segment_id,'zooming');
            $('#vision-background').fadeIn('slow');
            $('#'+this.current_segment_id).animate({
                width: '196px',
                height: '196px'
            },'normal');
            $('#'+this.current_segment_id).children('img').fadeOut('normal', function() {
                WheelNav.set_state(WheelNav.current_segment_id,'zoomed_out');
                $('#'+WheelNav.current_segment_id).css({'z-index': WheelNav.default_depths[WheelNav.current_segment_id]});
                $('#'+WheelNav.current_segment_id).mouseout(function() {
                    clearTimeout(WheelNav.zoom_in_timer);
                });
                $('#wheel-nav-container a').each(function() {
                   if (this.id != WheelNav.current_segment_id) {
                       $(this).show();
                   } 
                });
                WheelNav.current_segment_id = null;
            });
        }
    },
    set_state: function(element_id,state) {
        this.zoom_states[element_id] = state;
    },
    get_state: function(element_id) {
        return this.zoom_states[element_id];
    }
}

$(document).ready(function() {
    WheelNav.init();
});
