﻿var comit = {};


function classPostit() {
	this.hideTimer = false;
	this.active = false;
	this.mousePositionOffset = { "y": -50, "x": 10 };
	this.bigPostitHtml = document.createElement('div');
	this.bigPostitImage = new Image();
	this.postits = [];
	this.draw = function(y, x, header, text, writer, created) {
		if (!this.active) { return; }
		if (!header) {
			header = text = writer = created = "text";
		}
		var temp = "BP" + this.active.replace("SP", "") + "header";
		var postitInnerHtml = "<h3>" + document.getElementById("BP" + this.active.replace("SP", "") + "header").innerHTML + "</h3>";
		postitInnerHtml += "<p>" + document.getElementById("BP" + this.active.replace("SP", "") + "text").innerHTML + "</p>";
		postitInnerHtml += "<p>" + document.getElementById("BP" + this.active.replace("SP", "") + "writer").innerHTML + "</p>";
		postitInnerHtml += "<p>" + document.getElementById("BP" + this.active.replace("SP", "") + "created").innerHTML + "</p>";
		var bigPostit = document.getElementById('bigPostit');
		if (!bigPostit) {
			this.bigPostitHtml.className = "bigPostit";
			this.bigPostitHtml.id = "bigPostit";
			//this.bigPostitHtml.style.background = "url(yellowPostit_large.png)";
			//this.bigPostitImage.src = "yellowPostit_large.png";
			document.body.appendChild(this.bigPostitHtml);
			bigPostit = this.bigPostitHtml;
		}
		var getScreen = extScreen();
		if ((getScreen.height + getScreen.scrollTop) - y < this.bigPostitHtml.offsetHeight) {
			y = getScreen.height + getScreen.scrollTop - this.bigPostitHtml.offsetHeight;
		}
		if ((getScreen.width + getScreen.scrollLeft) - x < this.bigPostitHtml.Width) {
			x = getScreen.width + getScreen.scrollLeft - this.bigPostitHtml.Width;
		}
		bigPostit.style.top = y + "px";
		bigPostit.style.left = x + "px";
		bigPostit.style.position = "absolute";
		bigPostit.innerHTML = postitInnerHtml;
	};
	this.hidePostit = function() {
		this.hideTimer = window.setTimeout(function() { comit.postit.hidePostitTrue(); }, 100);
	};
	this.hidePostitTrue = function() {
		this.active = false;
		this.bigPostitHtml.style.top = "-9999px";
		this.bigPostitHtml.style.left = "-9999px";
		this.draw(-9999,-9999);
	};
	this.followMouse = function(e) {
		var mousePos = getMousePos(e);
		var mousePosition = { "y": comit.postit.mousePositionOffset.y * 1 + mousePos.y * 1, "x": comit.postit.mousePositionOffset.x * 1 + mousePos.x * 1 };
		comit.postit.draw(mousePosition.y, mousePosition.x);

	};
	this.findPostits = function() {
		var tempPostits = getElmByClass("postit");
		for (var i = 0; i < tempPostits.length; i++) {
			var elm = tempPostits[i];
			var index = this.postits.length;
			this.postits[index] = elm;
			elm.onmouseover = function(e) {
				comit.postit.active = this.id;
				window.clearTimeout(comit.postit.hideTimer);
				document.onmousemove = comit.postit.followMouse;
			};
			elm.onmouseout = function(e) {
				comit.postit.hidePostit();
			};
		}
	};
}
addOnload(function() {
	comit.postit = new classPostit();
	comit.postit.findPostits();
});