"""
gfx.py - Toplevel displaying
"""

import common
import os
import random
import pygame.image
import levels

# List of background surfaces
backgrounds = []

def loadBackgrounds():
    global backgrounds
    #print "Loading backgrounds.. "
    for x in os.listdir("images"):
        if x[-4:] in ['.jpg','jpeg'] and x[:2] == 'bg':
                backgrounds.append(\
                    pygame.image.load("images%s%s"%(os.sep,x)).convert())
                #print x,
    #print "[done]"

def setRandomBackground():
    common.current_bg = backgrounds[random.randrange(len(backgrounds)-1)+1]
    common.screen.blit(common.current_bg, (0,0))
    pygame.display.update()

def setBackground():
    common.current_bg = backgrounds[levels.level-1]
    common.screen.blit(common.current_bg, (0,0))
    pygame.display.update()
