
function loadDesktop() {
	var containerDiv = document.createElement("div");
	containerDiv.id = "desktopContainer";
	objBody = docbody();
	objBody.insertBefore(containerDiv, objBody.firstChild);
	
	
	var desktopElementsSack = new sack("pageserv.php?type=loadDesktop");
	desktopElementsSack.onCompletion = function() {
		deskArr = null;
		eval(desktopElementsSack.response);
		
		for(x in deskArr)
		{
			var deskNote = new deskNoteObj(containerDiv);
			deskNote.build(deskArr[x]['title'], deskArr[x]['content'], deskArr[x]['posx'], deskArr[x]['posy'], deskArr[x]['width'],deskArr[x]['height'], deskArr[x]['id']);
		}
		//need to parse the array and do something useful here
			
	}
	desktopElementsSack.runAJAX();
}
addLoadEvent(loadDesktop);

function deskNoteObj (containerDiv) {
	
	this.note = null;
	this.container = containerDiv;
	
	this.build = function(title, ctext, posx, posy, width, height, id) {
		this.note = document.createElement("div");
		this.note.className = "dwin";
		
		var header = document.createElement("div");
		header.className = "dwinh";
		this.note.appendChild(header);
		
		header.innerHTML = title;
		
		var content = document.createElement("div");
		content.className = "dwinc";
		this.note.appendChild(content);
		
		content.innerHTML = base64Decode(ctext);
		
		this.note.style.left = posx+"px";
		this.note.style.top = posy+"px";
		this.note.style.width = width+"px";
		this.note.style.height = height+"px";
		
		header.style.width = (width-4)+"px";
		
		content.style.width = (width-10)+"px";
		content.style.height = (height-45)+"px";
		content.style.overflow = "auto";
		
		containerDiv.appendChild(this.note);
		regMinorDraggable(this.note, header, this.container);
	}
	
}

function refreshDesk() {
	if(getObj("desktopContainer"))
		docbody().removeChild(getObj("desktopContainer"));
	loadDesktop();
}

function regMinorDraggable(dobj, dobjh, container)
{
	dobjh.onmousedown = function(e) {
		offsetVar[0] = mousePos[0]-dobj.offsetLeft;
		offsetVar[1] = mousePos[1]-dobj.offsetTop;
		followMouseObj = dobj;
		//if((document.all) && (navigator.userAgent.indexOf('Opera')== -1))
			container.appendChild(dobj);
		return false;
	}
}