// PROTOTYPE objektit
// show
// hide
// shiftTo
//
// DEF:
// function defnote
// function page
// function getlayer
//
// SHOW:
// function shownote
// function getxmouse
// function getymouse
// function getHeight
// function positionTip
// function shiftToNote
// function nshow
//
// HIDE:
// function hidenote
// function nhide
//
// HTML:
// <script type="text/javascript"> <!-- var tip1 = "Teksti"; --> </script>	
// <a href="page.w" onMouseOver="shownote(event,tip1,header,footer)" onMouseOut="hidenote()">Linkki</a>
// <div id="NoteId" style="position:absolute; visibility:hidden;  z-index:1000"></div>
//
//
//
//	24.3.2004	fix1	If you scroll down the window.event.y value isn't in synch with the documenturselves.
//				added the amount that the document has been scrolled by using document.body.scrollTop.
//

var xmouse, ymouse, footnote;
// var header = '<table bgcolor="#000000" width="500" cellspacing="0" cellpadding="1" border="1"><tr><td><table bgcolor="#ffffcc" width="100%" cellspacing="0" cellpadding="4" border="0"><tr><td>';
// var footer = '</td></tr></table></td></tr></table>';
var header = '<table bgcolor="red" width="360" cellspacing="0" cellpadding="1" border="0"><tr><td><table bgcolor="green" width="100%" cellspacing="0" cellpadding="4" border="0"><tr><td>';
var footer = '</td></tr></table></td></tr></table>';

window.onload = defnote;

page.prototype.show = nshow; //  Toteutetaan näyttö ja piilotus kun prototype objekti esiintyy.
page.prototype.hide = nhide;
page.prototype.shiftTo = shiftToNote;

var timer_active = false;
var menu_timer;

function reset_timer()
{
    if(timer_active)
    {
      clearTimeout(menu_timer);
      timer_active=false;
    }
}

function hide_menu_slow()
{
    timer_active=true;
    menu_timer=setTimeout('hidenote()',5000);
}

function hide_menu_fast()
{
    menu_timer=setTimeout('hidenote()',5000);
    timer_active=true;
}

// Luodaan FootNote ja asetetaan IE:n tyylitiedoston asetukset
function defnote() {

	footnote = new page('NoteId');

	if (!footnote) return;

	if (!document.layers && typeof footnote.doc.innerHTML == "undefined"){
		footnote = null;
		return;
	}
	if (footnote.el.style) {
		footnote.css.borderStyle = "groove";
		footnote.css.width = "100px";
		footnote.css.fontFamily = "Verdana, arial, helvetica, sans-serif";
		footnote.css.fontSize = "10px";
		footnote.css.color = "#000000";
		// footnote.css.backgroundColor = "#ffffcc";
		footnote.css.borderColor = "#000000";
		footnote.css.borderWidth = "0px";
		footnote.css.padding = "0px";
	}
}

function page(id,x,y,w,h) {

	this.el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getlayer(id,document): null;
	if (!this.el) return null;

	this.doc = (document.layers)? this.el.document: this.el;
	this.css = (this.el.style)? this.el.style: this.el;
	var px = (document.layers||window.opera)? "": "px";
	this.x = x || 0;
	if (x) this.css.left = this.x+px;
	this.y = y || 0;
	if (y) this.css.top = this.y+px;
	this.width = w? w: (this.el.offsetWidth)? this.el.offsetWidth: (this.css.clip.width)? this.css.clip.width: 0;
	this.height = h? h: (this.el.offsetHeight)? this.el.offsetHeight: (this.css.clip.height)? this.css.clip.height: 0;
	if (w){ (document.layers)? this.css.clip.width=w+px: this.css.width=w+px;}
	if (h){ (document.layers)? this.css.clip.height=h+px: this.css.height=h+px;}
	this.obj = id + "page";
	eval(this.obj + "=this");
}

// haetaan layerit
function getlayer(layer,doc) {

	if (document.layers) {
		var thelayer;
		for (var i=0; i<doc.layers.length; i++) {
	  	thelayer = doc.layers[i];
			if (thelayer.name == layer) return thelayer;
			else if (thelayer.document.layers.length > 0)
	    	if ((thelayer = getlayer(layer,thelayer.document)) != null)
					return thelayer;
	  }
		return null;
  }
}

/************************************************************/
/*   SHOWNOTE                                                                                           */
/************************************************************/

// Näytä FootNote, kiintä positio akselilla X
function shownote(evt,note,header,footer) {

	if (!footnote) return; // Onko alustettu ok

	var dispnote = "";
	if (document.layers) { dispnote = header + note + footer; } // Netscape
	else dispnote = note; // IE:llä tyylitiedosto

	if (typeof footnote.doc.innerHTML!="undefined") {
     		footnote.doc.innerHTML = dispnote;
  	} else if (document.layers) {
		footnote.doc.write(dispnote);
		footnote.doc.close();
 	}

	evt = (window.event)? window.event: evt;

	if (evt) { xmouse = getxmouse(evt); ymouse = getymouse(evt); }

	footnote.height = getHeight(footnote.el);
	if (!document.layers) footnote.height=getHeight('','NoteId'); // eri selainten takia moneen kertaan

	positionTip();
	footnote.show();
}

// Näytä FootNote, vapaasti positioitu hiiren mukaan
function shownote2(evt,note,header,footer) {

	if (!footnote) return; // Onko alustettu ok

	var dispnote = "";
	if (document.layers) { dispnote = header + note + footer; } // Netscape
	else dispnote = note; // IE:llä tyylitiedosto

	if (typeof footnote.doc.innerHTML!="undefined") {
     		footnote.doc.innerHTML = dispnote;
  	} else if (document.layers) {
		footnote.doc.write(dispnote);
		footnote.doc.close();
 	}

	evt = (window.event)? window.event: evt;

	if (evt) { xmouse = getxmouse(evt); ymouse = getymouse(evt); }

	footnote.height = getHeight(footnote.el);
	if (!document.layers) footnote.height=getHeight('','NoteId'); // eri selainten takia moneen kertaan

	positionTip2();
	footnote.show();
}

function getxmouse(evt) {

	return (evt.pageX)? evt.pageX: evt.clientX;

}

function getymouse(evt) {
	return (evt.pageY)? evt.pageY: evt.clientY;
}

function getHeight(obj,id) {

	var ht=0;
	if (document.getElementById||document.all) {
   	 var elem;
		if (id)	elem = (document.getElementById)? document.getElementById(id): document.all[id];
		else elem = obj;
		if (elem.offsetHeight) ht = elem.offsetHeight;
  } else if (obj.document) ht = obj.document.height;
  
  return ht;
}

function positionTip() {
	var x, y;
	var xcord	= -120;
	var ycord	= -40;

	footnote.height = getHeight(footnote.el);

        if(is_ie)
        {
          y = ymouse + document.body.scrollTop;
        }
        else
        {
          y = ymouse; // missä on layerin ylälaita
        }

        // y = ymouse; // missä on layerin ylälaita
        x = 170;    // missä on layerin vasen laita
	footnote.shiftTo(x,y);
}

function positionTip2() {
	var x, y;
	var xcord	= -120;
	var ycord	= -40;

        if(is_ie)
        {
          y = ymouse + document.body.scrollTop;
        }
        else
        {
          y = ymouse; // missä on layerin ylälaita
        }
        x = xmouse;

	footnote.shiftTo(x,y);
}

function shiftToNote(x,y) {

	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}

function nshow() { this.css.visibility = "visible"; } //  Toteutetaan näyttö ja piilotus kun prototype objekti esiintyy.


/************************************************************/
/*   HIDENOTE                                                                                           */
/************************************************************/

// Piilota FootNote
function hidenote() { if (!footnote) return; footnote.hide(); }

function nhide() { this.css.visibility = "hidden"; }