// Array-ul ce va contine id-urile imaginilor puse in patratele
var droppedOnes = new Array();

// Array-ul cu id-urile imaginilor care vor fi draggable
// exclus din fisier, inclus in pagina

// Array-ul cu id-urile div-urilor care vor fi droppable(unde vor fi "depozitate" imaginile)
var droppables = [
	"#np-wash-cont-1", 
	"#np-wash-cont-2", 
	"#np-wash-cont-3", 
	"#np-wash-cont-4", 
	"#np-wash-cont-5"
];

$(document).ready(function() {
	
	// facem fiecare element din array-ul de draggables sa fie draggable, legat de droppable-ul corespunzator
	var count = 0;
	for (i in draggables) {		
		for (j in draggables[i]) {
			$(draggables[i][j]).draggable({
				snap: droppables[count],
				snapMode: 'inner',
				revert: false,
				start: function(evt, ui) {
					$("#" + this.id).draggable('option', 'revert', 'invalid');
				}
			});
		}
		count++;	
	}	
	
	// facem fiecare element din array-ul de droppables sa fie droppable, cu proprietatea ca numai un element poate fi asezat intr-un div
	for (i in droppables) {
		$(droppables[i]).droppable({
			accept: function(ui) {
				if (ui.draggable('option', 'snap') == "#" + this.id) {
					return true;
				}
				else {
					return false;
				}
			},
			drop: function(evt, ui) {
				if (droppedOnes[this.id]) {
					$(droppedOnes[this.id]).animate({
						"left": "0px",
						"top" : "0px"
					});
					droppedOnes[this.id] = '';
				}
				droppedOnes[this.id] = '#' + ui.draggable[0].id; 
			},
			out: function(evt, ui) {
				if (droppedOnes[this.id] == "#" + ui.draggable[0].id) {
					$("#" + ui.draggable[0].id).draggable('option', 'revert', false);
					$("#" + ui.draggable[0].id).animate({
						"left": "0px",
						"top": "0px"
					});

					droppedOnes[this.id] = '';
				}
			}
		});							
	}

	// pt testare, face un log la array-ul de rezultate
	/*$("#np-wash-button").click( function() {
		for (i in droppedOnes) {
			console.log(droppedOnes[i]);
		}
	});*/
	
	$("#np-wash-button").click( function() {
		var content_html='';
		for(j=1;j<6;j++) {
			i='np-wash-cont-'+j;
			if (desc[droppedOnes[i]]) {
				if (i=='np-wash-cont-1') content_html+='<strong>1:</strong> ';
				if (i=='np-wash-cont-2') content_html+='<strong>2:</strong> ';
				if (i=='np-wash-cont-3') content_html+='<strong>3:</strong> ';
				if (i=='np-wash-cont-4') content_html+='<strong>4:</strong> ';
				if (i=='np-wash-cont-5') content_html+='<strong>5:</strong> ';
				content_html+=desc[droppedOnes[i]]+'<br />';
			}
		}
		$("#np-wash-text").html(content_html);
	});
});

