/*
 +-------------------------------------------------------------------+
 |                      J S - M E M O   (v1.9)                       |
 |                                                                   |
 | Copyright Gerd Tentler                www.gerd-tentler.de/tools   |
 | Created: Jan. 26, 2002                Last modified: Apr. 9, 2007 |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+

======================================================================================================

 This script was tested with the following systems and browsers:

 - Windows XP: IE 6, NN 7, Opera 7 + 9, Firefox 2
 - Mac OS X:   IE 5, Safari 1

 If you use another browser or system, this script may not work for you - sorry.

------------------------------------------------------------------------------------------------------

 The memo function takes three arguments:

 1. The content of your memo-box, e.g. 'Just a test'
 2. The width of your memo-box in pixels, e.g. 150 (optional)
 3. The title of your memo-box, e.g. 'Info' (optional)

 EXAMPLE:

 <a href="javascript:memo('Just a test', 150, 'Info')">some text here</a>

======================================================================================================
*/
// -------------------------------------------------------------------------------------------------------
// Configuration
// -------------------------------------------------------------------------------------------------------

var titleFont = "Verdana,Arial,Helvetica";  // title font family
var titleSize = 12;                         // title font size (pixels)
var titleColor = "#676E73";                 // title color
var textFont = "Verdana,Arial,Helvetica";   // text font family
var textSize = 10;                          // text font size (pixels)
//var textColor = "#ffffff";                  // text color
var textColor = "#202020";                  // text color
//var bgColor = "#12244d";                    // background color
//var bgColor = "#ffffff";                    // background color
var borderColor = "#ffffff";                // border color
//var btnRaisedColor = "#12244d";             // raised button color
var btnRaisedColor = "#9e9e9e";             // raised button color
//var btnPressedColor = "#12244d";            // pressed button color
var btnPressedColor = "#9e9e9e";            // pressed button color
var fadeSpeed = 15;                         // fade speed (0 - 30; 0 = no fading)*

// * Fading is not supported by all browsers.

// -------------------------------------------------------------------------------------------------------
// Get browser information
// -------------------------------------------------------------------------------------------------------

var OP = (navigator.userAgent.indexOf('Opera') != -1);
var IE = (navigator.userAgent.indexOf('MSIE') != -1 && !OP);
var GK = (navigator.userAgent.indexOf('Gecko') != -1);
var NN4 = document.layers;
var DOM = document.getElementById;

// -------------------------------------------------------------------------------------------------------
// Set styles
// -------------------------------------------------------------------------------------------------------

document.write('<style> .cssMemoText { ' +
               'font-family: ' + textFont + '; ' +
               'font-size: ' + textSize + 'px; ' +
               'color: ' + textColor + '; ' +
               'padding: 20px; ' +
               //***********************************************
			   '} .cssMemoTitle { ' +
               'font-family: ' + titleFont + '; ' +
               'font-size: ' + titleSize + 'px; ' +
               'font-weight: bold; ' +
               'color: ' + titleColor + '; ' +
               'padding: 2px; ' +
               'padding-left: 4px; ' +
//*****************************************************************************
//*****************************************************************************
               '} .cssMemoBtnRaised { ' +
               'font-family: Verdana,Arial,Helvetica; ' +
               'font-size: ' + titleSize + 'px; ' +
               'font-weight: bold; ' +
               'color: #FFFFFF; ' +
               'background-color: ' + btnRaisedColor + '; ' +
               //'border: 1px outset #FFFFFF; ' +
               'border: none; ' +
               'cursor: default; ' +
               'width: 16px; ' +
               'height: 16px; ' +
               'padding: 2px; ' +
               'text-align: center; ' +
               'display:none; ' +
               '} .cssMemoBtnPressed { ' +
               'font-family: Verdana,Arial,Helvetica; ' +
               'font-size: ' + titleSize + 'px; ' +
               'font-weight: bold; ' +
               'color: #FFFFFF; ' +
               'background-color: ' + btnPressedColor + '; ' +
               //'border: 1px inset #FFFFFF; ' +
               'border: none; ' +
               'cursor: default; ' +
               'width: 16px; ' +
               'height: 16px; ' +
               'padding-left: 3px; ' +
               'padding-top: 3px; ' +
               'padding-bottom: 1px; ' +
               'padding-right: 1px; ' +
               'text-align: center; ' +
               'display:none; ' +
//*****************************************************************************
//*****************************************************************************
               '} #memo_table { ' +
               '-moz-opacity:.9; ' +
			   'filter:alpha(opacity=90); ' +
			   'background-color:#D7DFE1; ' +
			   'background-repeat:no-repeat; ' +
               '} </style>');

// -------------------------------------------------------------------------------------------------------
// Set memo-box layer
// -------------------------------------------------------------------------------------------------------

document.write('<div id="divMemo" style="position:absolute; z-index:69; visibility:hidden"></div>');

if(DOM) {
  var obj = document.getElementById('divMemo');
  var sobj = obj.style;
}
else if(IE) {
  var obj = document.all.divMemo;
  var sobj = obj.style;
}
else if(NN4) {
  var obj = document.divMemo;
  var sobj = obj;
}

// -------------------------------------------------------------------------------------------------------
// Get mouse position, window height and scroll top
// -------------------------------------------------------------------------------------------------------

var mouseX = mouseY = winY = scrTop = 0;

if(NN4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;

function getScrollLeft() {
  var scrLeft = 0;
  if(document.documentElement && document.documentElement.scrollLeft)
    scrLeft = document.documentElement.scrollLeft;
  else if(document.body && document.body.scrollLeft)
    scrLeft = document.body.scrollLeft;
  else if(window.pageXOffset) scrLeft = window.pageXOffset;
  return scrLeft;
}

function getScrollTop() {
  var scrTop = 0;
  if(document.documentElement && document.documentElement.scrollTop)
    scrTop = document.documentElement.scrollTop;
  else if(document.body && document.body.scrollTop)
    scrTop = document.body.scrollTop;
  else if(window.pageYOffset) scrTop = window.pageYOffset;
  return scrTop;
}

function getWindowHeight() {
  if(window.innerHeight)
    winY = window.innerHeight;
  else if(document.documentElement && document.documentElement.clientHeight)
    winY = document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    winY = document.body.clientHeight;
  else winY = screen.height;
  scrTop = getScrollTop();
}

function getMouseXY(e) {
  if(e && e.pageX != null) {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  else if(event && event.clientX != null) {
    mouseX = event.clientX + getScrollLeft();
    mouseY = event.clientY + getScrollTop();
  }
  if(mouseX < 0) mouseX = 0;
  if(mouseY < 0) mouseY = 0;
}

// -------------------------------------------------------------------------------------------------------
// Set opacity, fade-in/out
// -------------------------------------------------------------------------------------------------------

var timer = opacity = 0;

function setOpacity(opacity) {
  if(sobj && !NN4) {
    sobj.opacity = opacity / 100;
    sobj.MozOpacity = opacity / 100;
    sobj.KhtmlOpacity = opacity / 100;
    sobj.filter = 'alpha(opacity=' + opacity + ')';
  }
}

function fadeIn() {
  if(sobj) {
    sobj.visibility = 'visible';
    if(fadeSpeed && opacity < 100) {
      opacity += fadeSpeed;
      if(opacity > 100) opacity = 100;
      setOpacity(opacity);
      if(timer) clearTimeout(timer);
      timer = setTimeout('fadeIn()', 1);
    }
    else {
      opacity = 100;
      setOpacity(100);
    }
  }
}

function fadeOut() {
  if(sobj) {
    if(fadeSpeed && opacity > 0) {
      opacity -= fadeSpeed;
      if(opacity < 0) opacity = 0;
      setOpacity(opacity);
      if(timer) clearTimeout(timer);
      timer = setTimeout('fadeOut()', 1);
    }
    else {
      opacity = 0;
      setOpacity(0);
      sobj.visibility = 'hidden';
    }
  }
}

// -------------------------------------------------------------------------------------------------------
// Create the memo-box and view it
// -------------------------------------------------------------------------------------------------------

function memo_klubi(text, width, title) {
  if(width == null || width == 0) width = 200;
  if(title == null) title = '';

  //var left = mouseX - width;
  //var left = mouseX - (width/4);
  //var left = mouseX + 50;
  //var left = 402; //colmio orig
  var left = 168; //colmio v2
  if(left < 0) left = 0;

  // TITLEEN AVUSTAJA??? TEXTIIN LAATIKKO
  var t = '<table id="memo_table" border="0" cellspacing="0" cellpadding="1">' +
          '<td class="cssMemoTitle" style="width:' + (width - 16) + 'px">' + title + '</td>' +
          '<td class="cssMemoBtnRaised" align="right" onClick="fadeOut()" onMouseDown="this.className=\'cssMemoBtnPressed\'" ' +
          'onMouseUp="this.className=\'cssMemoBtnRaised\'" onMouseOut="this.className=\'cssMemoBtnRaised\'">&times;</td>' +
          '</tr><tr><td colspan="2">' +
          '<table border="0" cellspacing="0" cellpadding="4" width="' + width + '"><tr>' +
          '<td><table border="0" cellspacing="0" cellpadding="0" align="center"><tr>' +
          '<td class="cssMemoText">' + text + '</td></tr></table></td></tr></table></td></tr></table>';

  if(DOM || IE) {
    sobj.width = width + (NN4 ? '' : 'px');
    obj.innerHTML = t;
  }
  else if(NN4) {
    obj.document.write(t);
    obj.document.close();
  }

  var hght = 0;
  //var top = mouseY - 50;
  var top = 181; // laskettu 50px, koska logo ylhäällä

  if(DOM) hght = obj.offsetHeight;
  else if(IE) hght = sobj.pixelHeight;
  else if(NN4) hght = sobj.clip.bottom;

  getWindowHeight();
  if(top + hght - scrTop > winY) {
    if(hght > top) top = 0;
    else top -= hght;
  }

  sobj.left = left + (NN4 ? '' : 'px');
  sobj.top = top + (NN4 ? '' : 'px');
  fadeIn();
}

function memo_aitio(text, width, title) {
  if(width == null || width == 0) width = 200;
  if(title == null) title = '';

  //var left = mouseX - width;
  //var left = mouseX - (width/4);
  var left = 20;
  if(left < 0) left = 0;

  var t = '<table id="memo_table" border="0" cellspacing="0" cellpadding="1"><tr bgcolor="' + borderColor + '">' +
          '<td class="cssMemoTitle" style="width:' + (width - 16) + 'px">' + title + '</td>' +
          '<td class="cssMemoBtnRaised" align="right" onClick="fadeOut()" onMouseDown="this.className=\'cssMemoBtnPressed\'" ' +
          'onMouseUp="this.className=\'cssMemoBtnRaised\'" onMouseOut="this.className=\'cssMemoBtnRaised\'">&times;</td>' +
          '</tr><tr><td bgcolor="' + borderColor + '" colspan="2">' +
          '<table border="0" cellspacing="0" cellpadding="4" width="' + width + '" style="backgroud-image:url(images/kupla.png)" ><tr>' +
          '<td><table border="0" cellspacing="0" cellpadding="0" align="center"><tr>' +
          '<td class="cssMemoText">' + text + '</td></tr></table></td></tr></table></td></tr></table>';

  if(DOM || IE) {
    sobj.width = width + (NN4 ? '' : 'px');
    obj.innerHTML = t;
  }
  else if(NN4) {
    obj.document.write(t);
    obj.document.close();
  }

  var hght = 0;
  var top = 150; // laskettu 50px, koska logo ylhäällä

  if(DOM) hght = obj.offsetHeight;
  else if(IE) hght = sobj.pixelHeight;
  else if(NN4) hght = sobj.clip.bottom;

  getWindowHeight();
  if(top + hght - scrTop > winY) {
    if(hght > top) top = 0;
    else top -= hght;
  }

  sobj.left = left + (NN4 ? '' : 'px');
  sobj.top = top + (NN4 ? '' : 'px');
  fadeIn();
}

// -------------------------------------------------------------------------------------------------------
