// * ********* ********* ********* ********* *********
// * Sticky Note Popup
// * iMarketingTool.com software
// * http://www.imarketingtool.com
// * (c)2000 Dan Shipe 
// *  danshipe@imarketingtool.com
// * ********* ********* ********* ********* *********
// * useage...
// * 
// * <script type="text/javascript" src='postit.js'></script>
// * <script type="text/javascript">
// * var objStickyNote1 = new fpuObject();
// * objStickyNote1.left = -100;
// * objStickyNote1.html = "<span style=\"font: 12pt verdana;\">My sticky note html message</span>";
// * objStickyNote1.create();
// * </script>
// * ********* ********* ********* ********* *********
// * PROPERTY          TYPE     DEFAULT               DESCRIPTION
// * allowDrag         bool     true                  allow dragging of popup	
// * backgroundImage   string   images/postit75.gif   background-image style of popup div
// * closeButton       bool     true                  show or hide the close "x"
// * cssClass	       bool     true                  apply a css class to entire popup (good for font)
// * divID             string   null                  id of existing DIV to use as the popup
// *                                                     use divID or html; if both will use divID
// * finalTop          int      window center         initial top of the popup div
// *                                                     when != top, popup will move to finalTop
// * finalLeft         int      window center         initial left of the popup div
// *                                                     when != top, popup will move to finalLeft
// * html              string   ...                   HTML text to be displayed in popup div
// *                                                     use divID or html; if both will user divID
// * left              int      window center         initial left of the popup div
// * name              string   StickyNotePopup       unique name of the popup object						
// *                                                     useful for drag debug if m_blnFPUDebug=true 
// * padding           int      30                    padding of popup div
// * top               int      window center         initial top of the popup div
// * ********* ********* ********* ********* *********

var m_arrFPUObjects = new Array();

$(document).ready(
	function() {
		// preload image
		var image1 = $('<img />').attr('src', 'PostItYellow.gif');
		image1.appendTo($("body"));	
			
		for (var i=0; i<m_arrFPUObjects.length; i++)
		{	
			m_arrFPUObjects[i].create();
		}	

		image1.css("display", "none");
	}
);



// ********* ********* ********* ********* *********
// MAIN OBJECT
// ********* ********* ********* ********* *********

// ********* ********* ********* ********* *********
function fpuObject()
{
	this.name = "PostIt";
	this.allowDrag = true;
	this.divID = null;
	this.closeButton = true;
	this.cssClass = null;

	this.backgroundImage = "PostItYellow.gif";
	this.backgroundRepeat = "no-repeat";
	this.padding = 30;
	this.html = "PostIt Popup Note<br/>http://www.imarketingtool.com";

	// positioning properties
	this.height = 285;
	this.width = 245;

	this.top = parseInt((document.body.clientHeight - this.height)/2, 10);
	this.left = parseInt((document.body.clientWidth - this.width)/2, 10);
	this.finalTop = parseInt((document.body.clientHeight - this.height)/2, 10);
	this.finalLeft = parseInt((document.body.clientWidth - this.width)/2, 10);

	// add object to global array
	m_arrFPUObjects[m_arrFPUObjects.length] = this;
};

// ********* ********* ********* ********* *********
fpuObject.prototype.create = function()
{
	// establish an ID if none given	
	if (!this.divID)
	{
		this.divID = "pu" + Math.floor(Math.random()*101);
	}

	// create the actual DIV element
	// or grab a existing DIV 
	var objElement = document.getElementById(this.divID);
	if (!objElement)
	{
		//$("<div id='" + this.divID + "' style='background-color:#00ff00;'></div>").appendTo($("body"));
		$("<div id='" + this.divID + "'></div>").appendTo($("body"));
		objElement = document.getElementById(this.divID);
	}	
	this.debug(objElement.id);

	this.element = objElement;
	objElement.parentObject = this;
	var wset = $("#" + this.divID);

    var img = $("<img border='0' src='" + this.backgroundImage + "'/>").appendTo(wset[0]);
	
	if (this.cssClass)
		wset[0].addClass(this.cssClass);		

    wset.css("position", "absolute");
	wset.css("top", this.top);
	wset.css("left", this.left);
    //wset.css("border", "3px solid #000000");
    	
	if (this.allowDrag)
	{
		wset.draggable();
	}

	// append content
    var divContent = $("<div/>").appendTo(wset[0]);
    divContent.css("position", "absolute");
    divContent.css("top", "0");
    divContent.css("left", "0");
    divContent.css("padding", this.padding);
    //divContent.css("border", "3px solid #ff0000");
    if($.browser.msie)
        divContent.css("width", img.width());
        

	// create close button
	if (this.closeButton) 
	{
		var html = "<div style='float:right; font: 12pt verdana;'>&nbsp;&#x00d7;&nbsp;</div>";
		$(html).appendTo(divContent).click(
			function() {
				this.parentNode.parentNode.style.display="none";
			}
		);			
	}
	
	// append html
    var divHtml = $("<div>"+this.html+"</div>").appendTo(divContent);

    // animate
	wset.animate
	(
		{
			top: this.finalTop,
			left: this.finalLeft
		}, 
		5000,
		function()
		{
			// Animation complete.
		}
	);

	return objElement;	
};

fpuObject.prototype.debug = function()
{
	if (false)
	{
		var objConsole = document.getElementById("DebugConsole");
		if (!objConsole)
		{
			objConsole = $("<textarea id='DebugConsole' style='background-color:#ffcc00;' rows='10' cols='100'>")
			objConsole.appendTo($("body"));
			objConsole.append($(document.createTextNode("				DEBUG CONSOLE\r\n" + strData + "\r\n")));
		}
		else
		{
			objConsole.value += strData + "\r\n";
		}
	}	
}

fpuObject.prototype.showProperties = function(obj)
{
	var i;
	var strOutput;
	var strTerm;
	var strData;
	var strSpace;
	var lngCols;
	var lngMaxLen = 100;
	
	// initialize number of columns
	lngCols=3;
	if (document.layers) lngCols=3;

	// initialize an empty string
	strSpace = "                                        ";
	
	strOutput = obj.name + "\n\n";
	i=1;
	for (var prop in obj) {
		strTerm = "\n";
		if (i==lngCols) strTerm = "\n";

		i=i+1;
		if (i>lngCols) i=1;	

		strData = "." + prop + " = " + obj[prop];
		if (strData.length<lngMaxLen) strData += strSpace.substring(0, lngMaxLen-strData.length);
		if (strData.length>lngMaxLen) strData = strData.substring(0, lngMaxLen);

		strOutput += strData + strTerm;
	};	
	this.debug(strOutput);
	return true;
};

