function loadTiles()
{
	new Ajax.Request('tiles.php',
	{
		method:'get',
		onSuccess: function(transport)
		{
			var tiles = transport.responseText.evalJSON();
			createTiles( tiles );
		},
		onFailure: function()
		{
			alert('Something went wrong...')
		}
	});

}

function createTiles( tiles )
{
	var ttable = document.createElement('table');
	ttable.setAttribute('style', 'margin-left:auto;margin-right:auto;padding:16px');
	ttable.setAttribute('id', 'tiles');
	var col = 0;
	
	var tr = document.createElement('tr');

	tiles.each( function(t)
	{
		if ( 0 == ( col % 4 ) && col )
		{
			ttable.appendChild(tr);
			tr = document.createElement('tr');
		}
			
		var td = document.createElement('td');
		var ot;
		
		if ( navigator.appName != 'Microsoft Internet Explorer' )		
		{
			ot = document.createElement('object');
			ot.setAttribute( 'data', 'hal?text=' + t[1] + '&sub=' + t[2] + '&back=' + t[3] + '&href=' + t[0] );
		}
		else
		{
			ot = document.createElement('a');
			var imgt = document.createElement('img');
			imgt.setAttribute( 'src', 'hal?type=png&text=' + t[1] + '&sub=' + t[2] + '&back=' + t[3] );
			imgt.setAttribute( 'alt', t[2] );
			ot.setAttribute( 'href', t[0] );
			ot.appendChild(imgt);
		}
		
		td.appendChild(ot);
		tr.appendChild(td);

		++col;
	} );

	ttable.appendChild(tr);
	document.body.appendChild(ttable);

}
