/*
	Post-It - Crispin Parker 17/10/2005
*/

//var mouseDownObj = null;
var notes = new Array();
var basePath = "http://www.kulcsrakeszhaz.hu/outers/js/PostIt/";

function noteObj(obj, x, y){
	this.element = obj;
	this.x = x;
	this.y = y;
}
/*
* Megjegyzésben az egérrel való mozgatás műveletei
function mouseMove(e){
	if(!e)e=window.event;
	var curPos = new getPos(e);
	with(mouseDownObj){
		element.style.left = curPos.x - x + "px";
		element.style.top = curPos.y - y + "px";
	}
	return false;
}

document.onmousedown = function(e){
	if(!e)e=window.event;
	var caller = e.target ? e.target : e.srcElement;
	for(i=0;i<notes.length;i++){
		if(caller == notes[i]){
			bringToTop(caller);
			var x = e.pageX ? e.pageX - caller.offsetLeft : e.offsetX;
			var y = e.pageY ? e.pageY - caller.offsetTop : e.offsetY;
			mouseDownObj = new noteObj(caller, x, y);
			document.onmousemove = mouseMove;
		}else{
			notes[i].style.zIndex = 0;
		}
	}
	return false;
}

document.onmouseup = function(e){
	if(!e)e=window.event;
	document.onmousemove = null;
}
*/

function bringToTop(caller){
	var i = 0;
	try{
		for(i=0;i<notes.length;i++){if(!notes[i]==caller)notes[i].style.zIndex = 1;}
		caller.style.zIndex=10;
	}catch(e){
		// empty catch
	}
}
function getPos(e){
	this.x = e.pageX ? e.clientX : e.clientX + document.body.scrollLeft;
	this.y = e.pageY ? e.clientY : e.clientY + document.body.scrollTop;
}

function addNew(left,top,myText){
	if(!myText)return;
	var index = notes.length
	notes[index] = buildPostIt(myText);
    notes[index].style.left=left;
    notes[index].style.top=top;
    notes[index].onmouseup = function(e) {
      location.href='./?menu=postits'; 
};
	document.body.appendChild(notes[index]);
}

function buildPostIt(text){
	var div1 = document.createElement("DIV");
	var div2 = document.createElement("DIV");
	var a = document.createElement("A");
	var img1 = document.createElement("IMG");

	img1.src = basePath + "close.gif";
	img1.setAttribute("align", "right");

	a.appendChild(img1);
	a.onmouseover = function(){
  this.childNodes[0].src=basePath+"closeRed.gif";
  index=0;
  notes[index].onmouseup = null;
};
	a.onmouseout = function(){
  this.childNodes[0].src=basePath+"close.gif";
  index=0;
  notes[index].onmouseup = function(e) {
      location.href='./?menu=postits'; 
  };
};
	a.onclick = function(){document.body.removeChild(this.parentNode);};

    div2.innerHTML=text;

	div1.appendChild(a);
	div1.appendChild(div2);
    width=242;
    height=241;
//	div1.style.cssText = "color: #0000ff; font-family: arial; font-size: 12px; position:absolute; left: " + (20 + (notes.length * 3)) + "px; top: " + (20 + (notes.length * 3)) + "px; width: "+width+"px; height: "+height+"px; border-top: 1px solid #000000; border-left: 1px solid #000000; border-right: none; border-bottm: none; background-color: none; background-image: url(" + basePath + "background.gif); background-position: bottom right; background-repeat: no-repeat; cursor: pointer; cursor: hand;";
	div1.style.cssText = "color: #0000ff; font-family: arial; font-size: 16px; position:absolute; left: " + (20 + (notes.length * 3)) + "px; top: " + (20 + (notes.length * 3)) + "px; width: "+width+"px; height: "+height+"px; border: none; background-color: none; background-image: url(" + basePath + "background.gif); background-position: bottom right; background-repeat: no-repeat; cursor: pointer; cursor: hand;";
	div2.style.cssText = "padding:30px;";

	return div1;
}
