//Copyright (C) Ben Parbury - All Rights Reserved. Unauthorized copying of this file, via any medium is strictly prohibited. Written by Ben Parbury <ben@gridlockinteractive.com> 2014
WebFontConfig = {
	custom: {
		families: [ 'Comfortaa' ],
		urls: [ 'data/fonts/fonts.css' ]
	},
	fontactive: function(fontFamily, fontDescription)
	{
    	gConsole.Log(3, "[FONT] Loaded " + fontFamily);
  	},
	active: function()
	{
		gConsole.Log(3, "[FONT] Font loading complete");
		gFonts.Loaded(WebFontConfig.custom.families);
	},
	inactive: function()
	{
		gConsole.Log(3, "[FONT] Failed to load fonts");
		gFonts.Loaded(null);
	}
};

var gFonts = new Font();

function Font()
{
	this.fonts = new Array('sans-serif');

	this.fontIndex = 0;
	
	this.loaded = false;

	this.Loaded = function(fonts)
	{
		if(fonts)
		{
			this.fonts = this.fonts.concat(fonts);
			this.fontIndex = this.fonts.length - 1;
		}

		if(this.LoadedCallback)
		{
			this.LoadedCallback();
		}
		this.loaded = true;
	}
	
	this.SetLoadedCallback = function(callback)
	{
		this.LoadedCallback = callback;
		if(this.loaded)
		{
			this.LoadedCallback();
		}
	}

	this.SetNextFont = function()
	{
		this.SetFontDirection(1);
	}

	this.SetFontDirection = function(index)
	{
		this.fontIndex = (this.fontIndex + index) % this.fonts.length;
		gScoreOverlay.redraw = true;
		gObjectivesOverlay.redraw = true;
		gHintsOverlay.redraw = true;
		gCompleteOverlay.redraw = true;
		gControlsOverlay.redraw= true;
		gBlockSystem.Redraw();
	}
}

function GetFontScale(size)
{
	return size * kTileSize/50;
}

function GetFont(size, bold, italic)
{
	var prefix = ""
	if (bold)
	{
		prefix += "bold ";
	}
	if (italic)
	{
		prefix += "italic ";
	}
	return prefix + size + "px " + gFonts.fonts[gFonts.fontIndex];
}
