#include <allegro.h>
#include <iostream>

void language() {
	
	allegro_init();
	install_mouse();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 300, 150, 0, 0);
	
	FILE *cfg;
	
	BITMAP *sk, *cz, *en, *ge, *es, *hu;
	sk = load_bitmap("gfx/language/sk.tga", NULL);
	cz = load_bitmap("gfx/language/cz.tga", NULL);
	en = load_bitmap("gfx/language/en.tga", NULL);
	ge = load_bitmap("gfx/language/ge.tga", NULL);
	es = load_bitmap("gfx/language/es.tga", NULL);
	hu = load_bitmap("gfx/language/hu.tga", NULL);
	
	int flags_width = 75;
	int flags_height = 50;
	int flags_start_x = 22;
	int flags_start_y = 10;
	int flags_hspace = 30;
	int flags_wspace = 15;
	
	clear_to_color(screen, makecol(180, 180, 180));
	
	int x = flags_start_x;
	int y = flags_start_y;
	
	blit(sk, screen, 0, 0, x, y, flags_width, flags_height);
	y += flags_height + flags_hspace;
	
	blit(cz, screen, 0, 0, x, y, flags_width, flags_height);

	x += flags_width + flags_wspace;	
	y = flags_start_y;
	
	blit(en, screen, 0, 0, x, y, flags_width, flags_height);
	y += flags_height + flags_hspace;
	
	blit(ge, screen, 0, 0, x, y, flags_width, flags_height);
	
	x += flags_width + flags_wspace;	
	y = flags_start_y;
	
	blit(es, screen, 0, 0, x, y, flags_width, flags_height);
	y += flags_height + flags_hspace;
	
	blit(hu, screen, 0, 0, x, y, flags_width, flags_height);
	
	show_mouse(screen);
	
	int lang = 0;
	
	while (TRUE) {
		
		if (mouse_b & 1) {
			
			if (mouse_x >= 22 && mouse_x <= 277 && mouse_y >= 10 && mouse_y <= 140) {
				
				if (mouse_y <= 60) {
					
					if (mouse_x >= 22 && mouse_x <= 97) lang = 1;
					else if (mouse_x >= 113 && mouse_x <= 188) lang = 3;
					else if (mouse_x >= 203 && mouse_x <= 278) lang = 5;
					
				} else if (mouse_y >= 90) {
					
					if (mouse_x >= 22 && mouse_x <= 97) lang = 2;
					else if (mouse_x >= 113 && mouse_x <= 188) lang = 4;
					else if (mouse_x >= 203 && mouse_x <= 278) lang = 6;
					
				}
				
				if (lang != 0) break;
				
			}
			
		}
		
	}
	
	cfg = fopen("cfg/language.cfg", "w");
	fprintf(cfg,"%d\n",lang);
	fclose(cfg);
	
	allegro_exit();
	
}

int main() {
	
	language();
	
}
END_OF_MAIN();
