// ex de folder layout
//mt.component.layout.DocumentLayout = function(domId){
mt.component.MosaicLayout = function(domId){
	var self = this;
	this.domId = domId;
	this.selectionEnabled = false;
	this.selectionItems = [];
	this.iMosaicColumnCount = 5; // Number of columns 
	this.tableWidth = "auto";

	this.setItemDisplay = function(item) {
		var div = document.createElement("div");
		div.style.backgroundColor = "lightyellow";
		div.style.border = "1px solid #CCC";
		div.style.margin = "10px";
		div.style.paddding = "10px";
		div.innerHTML = item.name;
		return div;
	}
	
	this.init = function(){
		this.selectionItems = [];
	}
	
	this.setDisplay = function(engineInstance) {
		var result = engineInstance.result;
		var table = document.createElement("table");
		table.className = "SE_TableLayout";
		table.style.borderCollapse = "collapse";
		table.style.width = this.tableWidth;
		
		var tbody = document.createElement("tbody");
		table.appendChild(tbody);
				
		var iIndex = 0;
		var bNewLine = true;
		self.tr = document.createElement("tr");
		result.dataset.each(function(item,index){
			bNewLine = ((iIndex==0) || (iIndex%self.iMosaicColumnCount==0));
			if (bNewLine){
				self.tr = document.createElement("tr");
			}
			var td = document.createElement("td");
			td.appendChild(self.setItemDisplay(item));
			
			/*
			if (self.selectionEnabled) {

				var chk = document.createElement("input");
				chk.type = "checkbox";
				self.selectionItems.push(chk);
				chk.setSelection = function() {
					divClear.style.backgroundColor = (this.checked)?"lightyellow":"none";
				}
				chk.onclick = chk.setSelection;
				chk.title = "Sélectionner";
				chk.item = item;
				
				userDiv.childNodes[1].childNodes[1].appendChild(chk);
				//userDiv.innerHTML = chk + userDiv.innerHTML ;
			}*/		
			
			self.tr.appendChild(td);
			if (bNewLine) tbody.appendChild(self.tr);
			iIndex++;
		});

		var domElm = $(this.domId);
		domElm.innerHTML = '';
		domElm.appendChild(table);
	}
	
	this.enableSelections = function(enable, selectionItem){
		this.selectionEnabled = enable;
		this.selectionItem = selectionItem;
	}
	
	this.getSelections = function(){
		var selections = [];
		this.selectionItems.each(function(item){
			if (item.checked) selections.push(item.item);
		});
		return selections;
	}
	this.setMosaicColumnCount = function(iMosaicColumnCount){
		this.iMosaicColumnCount = iMosaicColumnCount;
	}
}

