
/* script from http://www.devarticles.com/c/a/JavaScript/Creating-PopUp-Notes-with-CSS-and-JavaScript-Part-I/ */

/*
createNotes=function(){

	showNote=function( evt ){
		evt = (evt) ? evt : ((window.event) ? window.event : "")
	    if (evt) {
		
			var popup = document.getElementById('popup_1');
			popup.style.left = evt.clientX + "px";
			popup.style.top = evt.clientY  + "px";;
			popup.style.visibility='visible';
	    }
	}

	hideNote=function(){
			var popup = document.getElementById('popup_1');
			popup.style.visibility='hidden';
	}

	var a1 = document.getElementById('popupLink_1');
	a1.onmouseover = showNote;
	a1.onmouseout = hideNote;
	
}


window.onload = createNotes;
*/

createNotes = function(){

            showNote = function( evt ){
			evt = (evt) ? evt : ((window.event) ? window.event : "")
			if (evt) {
				// the link and popup should have the same id
				var id = this.id.replace( /popupLink_/,'popup_' );
				popup = document.getElementById( id );
				popup.style.left = (evt.clientX+10) + "px";
				popup.style.top = (evt.clientY+10) + "px";
				popup.style.visibility = 'visible';
			}
            }

            hideNote = function(){
                        var id = this.id.replace(/popupLink_/,'popup_');
                        popup = document.getElementById(id);
                        popup.style.visibility = 'hidden';
            }
                       

            as = document.getElementsByTagName('a');
            for( i=0; i < as.length; i++ ){
			linkID = as[i].id;
			if( linkID != null ){
				if( linkID.length >= 10 && 'popupLink_' == linkID.substring( 0, 10 ) ){
					as[i].onmousemove = showNote;
					as[i].onmouseout = hideNote;
				}
			}
		}


		// have to move the popup divs because they doesn't seem to work when I ouput divs in weird spots :0 (and I can't easily change that)

		alDivs = document.getElementsByTagName("div");
		popupDivs = [];
		popupCount = 0;

		for (i = 0; i < alDivs.length; i++){
			divID = alDivs[i].id;
			if( divID != null ){
				if( divID.length >= 6 && 'popup_' == divID.substring( 0, 6 ) ){
					popupDivs[popupCount] = divID;
					popupCount++;
				}
			}
		}

		/* We have to do the move divs AFTER we've found them all. Otherwise the document model we're iterating through gets corrupted */
		for( i=0; i<popupDivs.length; i++){
			document.getElementById('wrapper').appendChild(document.getElementById( popupDivs[i] )); // would be nice not have a hardcoded id here
			//document.body.childNodes[0].appendChild(document.getElementById( popupDivs[i] )); 
		}

}

window.onload = createNotes;


