namespace eval ::AIEnv {
	variable CurrentGraphics
	variable Bindings
	variable HexaGraphicsExist
	variable MedGraphicsExist
	
	set HexaGraphicsExist 0
	set MedGraphicsExist 0
	
	namespace export ShowHexa
	namespace export ShowMed
}

proc ::AIEnv::ShowHexa {} {
	variable CurrentGraphics
	variable HexaGraphicsExist
	
	global hexa_graphics
	
	# Check and see if the graphics for Hexa exist
	if { $HexaGraphicsExist == 0 } {
		CreateHexaGraphics
	}
	
	if { $CurrentGraphics != "Hexa" } {
		# Construct a function call based on the current
		# gfx
		set func Hide${CurrentGraphics}
		eval $func
	}
	pack $hexa_graphics -in $GraphicsContainer -fill both -expand yes	
	set CurrentGraphics "Hexa"
}

proc ::AIEnv::ShowMed {} {
	global tdv_default
	global GraphicsContainer
	
	variable CurrentGraphics
	variable MedGraphicsExist
	
	if { $MedGraphicsExist == 0 } {
		CreateMedGraphics
	}
	
	# If the CurrentGraphics flag doesn't exist, set it to a value
	# that will insure the rest of this function executes
	if { ! [info exists CurrentGraphics] } {
		set CurrentGraphics "Hexa"
	}
	if { $CurrentGraphics != "Med" } {
		# Construct a function call based on the current
		# graphics
		set func Hide${CurrentGraphics}
		eval $func	
	}
	
	if {[info exists Bindings($tdv_default)]} {
		bindtags $tdv_default $Bindings($tdv_default)
	}
	
	pack $tdv_default -in $GraphicsContainer -fill both -expand yes
	set CurrentGraphics "Med"	
}

proc ::AIEnv::HideMed {} {
	global tdv_default
	variable Bindings
	variable MedGraphicsExist
	
	if { $MedGraphicsExist } {
		pack forget $tdv_default
		# Store the current bindings for this widget
		set Bindings($tdv_default) [bindtags $tdv_default]
		# Clear the bindings for this window
		bindtags $tdv_default ""
	}
}

proc ::AIEnv::HideHexa {} {
	global hexa_graphics
	variable Bindings
	variable HexaGraphicsExist
	
	if { $HexaGraphicsExist } {
		pack forget $hexa_graphics
		# Store the current bindings for this widget
		set Bindings($hexa_graphics) [bindtags $hexa_graphics]
		# Clear the bindings for this window
		bindtags $hexa_graphics ""
	}
}

proc ::AIEnv::CreateHexaGraphics {} {
	global hexa_graphics
	global hexa_interp
	variable HexaGraphicsExist
	
	if { [catch {$hexa_interp eval start_process hexa .v.view "Hexa >" hexa} result] } {
		mess "Hexa graphics failed. Reason: $result\n" red
	} else {
		# The window path created by start_process for the graphics is
		# the concatentation of the first argument and the second
		# argument
		set hexa_graphics .v.view.hexa
		set HexaGraphicsExist 1
	}
	
}

proc ::AIEnv::CreateMedGraphics___NOT_USED {} {
    global display_type
    global tdv_default
    variable MedGraphicsExists
    
    set display_vendor [winfo server .]
    
    switch -glob -- $display_vendor {
	{*Silicon Graphics*}                { set display_type sgi }
	{*Hewlett-Packard *}                { set display_type hp }
	{*Sun Microsystems*}                { set display_type sun }
	{*International Business Machines*} { set display_type ibm }
	{*Digital Equipment Corporation*}   { set display_type dec }
	default                             { set display_type other }
    }
    
    set width 1
    set height 1
    
    tdv_init $tdv_default $width $height native black 0
    tdv_dynamics_bindings $tdv_default
    tdv_selection_bindings $tdv_default
    tdv_init_shortcuts 0 {s x}
    bind $tdv_default <Enter> "tdv_unfocus_entries"
    
    tdv_set_key_command F11 "make_sane" "Emergency reset"
    tdv_set_key_command F4 "make_sane" "Emergency reset"
    
    set MedGraphicsExist 1
    
}
