# get current scene
scene = GameLogic.getCurrentScene()

# get the current controller
controller = GameLogic.getCurrentController()

# get object script is attached to
obj = controller.owner

# check to see mirror has been added
if obj.has_key("Mirror") == True:
				
	# update the mirror
	obj["Mirror"].refresh(True)

# if mirror hasn't been added 
else:

	# import VideoTexture module
	import VideoTexture

	# get active camera
	cam = scene.active_camera 
		
	# get the mirror material ID
	matID = VideoTexture.materialID(obj, "MA" + obj['material'])
	
	#texture channel
	if obj.has_key('channel') == True:
		texChannel = obj['channel']
	else:
		texChannel = 0

	# get the mirrortexture
	mirror = VideoTexture.Texture(obj, matID, texChannel)
	
	# get the mirror source
	mirror.source = VideoTexture.ImageMirror(scene,cam,obj,matID)

	# save mirror as an object variable
	obj["Mirror"] = mirror 
