<script type='text/javascript'>
$(function(){
var a = 1;
var coordinates = function(element) {
element = $(element);
var top = element.position().top;
var left = element.position().left;
$('#".$row->id."X').val('' + left );
$('#".$row->id."Y').val('' + top );
$('#".$row->id."Z').val('' + a );
$(".$row->id.").css('z-index', a++);
}
$('#$row->id').draggable({
containment: \"#window\",
start: function() {
var a = 1;
coordinates('#$row->id');
$(".$row->id.").css(\"z-index\", a++);
},
stop: function() {
coordinates('#$row->id');
}
});
});
</script>