/*

FontJazz 1.2

http://www.fontjazz.com

(C) Copyright Rasmus Schultz, all rights reserved.

Free for use on all private/commercial websites. You may not
sell this script or FontJazz-generated fonts. Removing this
copyright statement is a violation of the licensing terms.

*/

var FontJazz = {
	
	_fonts: {},
	
	_initialized: false,
	
	_css: null,
	
	_basePath: fjBasePath,
	
	_initialize: function() {
		
		for (var fontname in FontJazz._fonts) {
			
			if (!FontJazz._fonts[fontname].initialized) {
				
				var image = FontJazz._fonts[fontname].image;
				var height = FontJazz._fonts[fontname].height;
				
        FontJazz._addRule(
          ".FontJazz-" + fontname + " div",
          "float:left; display:inline; overflow:visible;"
        );
        
				FontJazz._addRule(
					".FontJazz-" + fontname + " span",
					"display:block; float:left; background-image:url(" + image + "); height:" + height + "px;"
				);
				
				FontJazz._addRule(
					".FontJazz-" + fontname + " br",
					"clear:both;"
				);
				
				FontJazz._fonts[fontname].initialized = true;
				
			}
			
		}
		
	},
	
	_addRule: function(selector, rule) {
		
		if (!FontJazz._css) {
			if (document.createStyleSheet) {
				FontJazz._css = document.createStyleSheet();
			} else {
				FontJazz._css = document.createElement('style');
				FontJazz._css.setAttribute('type', 'text/css');
				document.getElementsByTagName("head")[0].appendChild(FontJazz._css);
			}
		}
		
		if (FontJazz._css.addRule) {
			FontJazz._css.addRule(selector, rule);
		} else {
			FontJazz._css.appendChild( document.createTextNode(selector + ' { ' + rule + " }\n") );
		}
		
	},
	
	register: function(fontname, data) {
		data.image = FontJazz._basePath + data.image;
		FontJazz._fonts[fontname] = data;
		FontJazz.initialized = false;
	},
	
	transform: function(element, fontname) {
		
		if (!document.styleSheets) return;
		
		if (!FontJazz.initialized) FontJazz._initialize();
		
		var font = FontJazz._fonts[fontname];
		var text = element.firstChild.nodeValue + ' ';
		
		var div = document.createElement('div');
		div.className = "FontJazz-" + fontname;
		
		var html = '<span style="overflow:hidden; width:0px;">' + text + '</span>';
		var adjust = font[text.charAt(0)][2];
		
    var word = '', w = 0, wm = 0;
		for (var i=0; i<text.length; i++) {
			var c = text.charAt(i), metrics = font[c];
			if (metrics) {
        w += metrics[1]+(adjust-metrics[2]);
        if (word == '') wm = adjust-metrics[2];
        word += '<span style="' + (word == '' ? '' : 'margin-left: 0px;') + 'background-position: -' + metrics[0] + 'px 0px; width: ' + metrics[1] + 'px;"></span>';
        if (c == ' ') {
          html += '<div style="margin-left:' + wm + 'px; width:auto;">' + word + '</div>';
          word = ''; w = 0; wm = 0;
        }
        adjust = metrics[3]-metrics[1];
			}
		}
		
		div.innerHTML = html + "<br />";
		
		element.parentNode.insertBefore(div, element);
		element.parentNode.removeChild(element);
		
	},
	
	apply: function(tagname, fontname, rootnode) {
		
		var collection = (rootnode || document.body).getElementsByTagName(tagname);
		
		var elements = new Array();
		
		for (var i=0; i<collection.length; i++)
			elements[i] = collection[i];
		
		for (var i=0; i<elements.length; i++)
			FontJazz.transform(elements[i], fontname);
		
	}
	
}

FontJazz.register('font18', {
	image: '/font18.gif',
	width: 927,
	height: 23,
	'A': [0, 16, 1, 15],
	'B': [17, 14, 1, 15],
	'C': [32, 17, 1, 17],
	'D': [50, 15, 1, 15],
	'E': [66, 14, 1, 13],
	'F': [81, 13, 1, 12],
	'G': [95, 17, 1, 18],
	'H': [113, 15, 1, 16],
	'I': [129, 3, 1, 4],
	'J': [133, 11, 1, 12],
	'K': [145, 16, 1, 15],
	'L': [162, 13, 1, 12],
	'M': [176, 18, 1, 19],
	'N': [195, 15, 1, 16],
	'O': [211, 18, 1, 18],
	'P': [230, 14, 1, 14],
	'Q': [245, 18, 1, 18],
	'R': [264, 15, 1, 15],
	'S': [280, 14, 1, 15],
	'T': [295, 15, 1, 14],
	'U': [311, 15, 1, 15],
	'V': [327, 16, 1, 15],
	'W': [344, 23, 1, 23],
	'X': [368, 15, 1, 14],
	'Y': [384, 16, 1, 16],
	'Z': [401, 14, 1, 14],
	'a': [416, 12, 1, 11],
	'b': [429, 13, 1, 13],
	'c': [443, 13, 1, 12],
	'd': [457, 13, 1, 14],
	'e': [471, 13, 1, 12],
	'f': [485, 8, 1, 7],
	'g': [494, 13, 1, 13],
	'h': [508, 11, 1, 12],
	'i': [520, 3, 1, 3],
	'j': [524, 5, 1, 5],
	'k': [530, 12, 1, 11],
	'l': [543, 3, 1, 3],
	'm': [547, 18, 1, 19],
	'n': [566, 11, 1, 12],
	'o': [578, 13, 1, 13],
	'p': [592, 13, 1, 13],
	'q': [606, 13, 1, 14],
	'r': [620, 7, 1, 7],
	's': [628, 12, 1, 12],
	't': [641, 8, 1, 8],
	'u': [650, 11, 1, 12],
	'v': [662, 12, 1, 11],
	'w': [675, 19, 1, 19],
	'x': [695, 12, 1, 12],
	'y': [708, 12, 1, 11],
	'z': [721, 11, 1, 11],
	'0': [733, 13, 1, 13],
	'1': [747, 7, 1, 11],
	'2': [755, 12, 1, 12],
	'3': [768, 13, 1, 13],
	'4': [782, 13, 1, 13],
	'5': [796, 13, 1, 13],
	'6': [810, 12, 1, 12],
	'7': [823, 12, 1, 12],
	'8': [836, 13, 1, 13],
	'9': [850, 13, 1, 13],
	'&': [864, 14, 1, 14],
	'!': [879, 3, 1, 5],
	'?': [883, 11, 1, 12],
	'-': [895, 7, 1, 8],
	' ': [903, 8, 1, 7],
	'.': [912, 3, 1, 5],
	'\"': [916, 6, 1, 7],
	'\'': [923, 3, 1, 5]
});


FontJazz.register('font24', {
	image: '/font24.gif',
	width: 1210,
	height: 32,
	'A': [0, 22, 1, 20],
	'B': [23, 19, 1, 19],
	'C': [43, 22, 1, 22],
	'D': [66, 20, 1, 20],
	'E': [87, 17, 1, 17],
	'F': [105, 16, 1, 15],
	'G': [122, 22, 1, 23],
	'H': [145, 20, 1, 21],
	'I': [166, 4, 1, 5],
	'J': [171, 15, 1, 16],
	'K': [187, 20, 1, 19],
	'L': [208, 16, 1, 15],
	'M': [225, 24, 1, 25],
	'N': [250, 20, 1, 21],
	'O': [271, 23, 1, 23],
	'P': [295, 19, 1, 18],
	'Q': [315, 23, 1, 23],
	'R': [339, 20, 1, 19],
	'S': [360, 19, 1, 19],
	'T': [380, 19, 1, 18],
	'U': [400, 19, 1, 20],
	'V': [420, 21, 1, 20],
	'W': [442, 30, 1, 29],
	'X': [473, 20, 1, 18],
	'Y': [494, 22, 1, 20],
	'Z': [517, 19, 1, 18],
	'a': [537, 16, 1, 16],
	'b': [554, 18, 1, 17],
	'c': [573, 16, 1, 16],
	'd': [590, 17, 1, 17],
	'e': [608, 16, 1, 16],
	'f': [625, 10, 1, 8],
	'g': [636, 16, 1, 17],
	'h': [653, 16, 1, 16],
	'i': [670, 4, 1, 5],
	'j': [675, 6, 1, 7],
	'k': [682, 17, 1, 15],
	'l': [700, 4, 1, 5],
	'm': [705, 25, 1, 26],
	'n': [731, 16, 1, 16],
	'o': [748, 17, 1, 17],
	'p': [766, 18, 1, 17],
	'q': [785, 17, 1, 17],
	'r': [803, 11, 1, 9],
	's': [815, 16, 1, 15],
	't': [832, 10, 1, 9],
	'u': [843, 16, 1, 16],
	'v': [860, 16, 1, 15],
	'w': [877, 25, 1, 25],
	'x': [903, 16, 1, 15],
	'y': [920, 16, 1, 15],
	'z': [937, 15, 1, 15],
	'0': [953, 17, 1, 17],
	'1': [971, 10, 1, 15],
	'2': [982, 16, 1, 17],
	'3': [999, 17, 1, 17],
	'4': [1017, 18, 1, 18],
	'5': [1036, 17, 1, 17],
	'6': [1054, 17, 1, 17],
	'7': [1072, 17, 1, 17],
	'8': [1090, 17, 1, 17],
	'9': [1108, 17, 1, 17],
	'&': [1126, 20, 1, 19],
	'!': [1147, 4, 1, 6],
	'?': [1152, 16, 1, 16],
	'-': [1169, 9, 1, 10],
	' ': [1179, 10, 1, 9],
	'.': [1190, 4, 1, 6],
	'\"': [1195, 9, 1, 10],
	'\'': [1205, 4, 1, 6]
});

