var currentCell = null;

function processMatrix(){
 	if (!(req.readyState == 4 && req.status == 200 && req.responseXML != null)) return;
    var nl = req.responseXML.getElementsByTagName( 'el' );
	var smallMatrix = document.createElement( 'div' );
	currentCell.appendChild(smallMatrix);
	smallMatrix.className = 'tinyMatrix';

	var cells = new Array();
	var emptyCells = new Array();

    for(var i = 0; i < nl.length; i++ ) {
      var nli = nl.item( i );
      var img = nli.getAttribute( 'img' );
	  var url = nli.getAttribute( 'url' );
	  var cell = document.createElement( 'div' );
   	  cell.className = 'tinyCell';
	  if (img){
	  	var cellImage = document.createElement('img');
		cellImage.src = img;
		cellImage.style.width= "10px";
		cellImage.style.height= "10px";
		if (url){
		  	var a = document.createElement('a');
			a.setAttribute('href', url);
			a.appendChild(cellImage);
			a.style.position = "absolute";
			a.style.left="0px";
			a.style.top="0px";
			cell.appendChild(a);
	  	} else {
			cellImage.style.position = "relative";
			cell.appendChild(cellImage);	  
		}
		cells[i] = cell;
	  } else {
	  	emptyCells[i] = cell;
	  }
    }

    for (var c in cells) {
		smallMatrix.appendChild(cells[c]);
	}
    for (var c in emptyCells) {
		smallMatrix.appendChild(emptyCells[c]);
	}
}
function loadMatrix(cell, url){
	if (cell.loaded || url == null) return;
	currentCell = cell;
	
	currentUrl = url;
	
	loadXMLDoc('/php/getMatrix.php?url='+url, processMatrix);
	cell.loaded = true;
}
